SasLogMessage.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:1k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: SasLogMessage.java,v 1.3 2002/09/09 05:48:54 parasuraman Exp $ */
  2. /*
  3.  * @(#)SasLogMessage.java
  4.  * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. import java.io.*;
  8. import java.util.*;
  9. import java.awt.*;
  10. import java.lang.*;
  11. import com.adventnet.snmp.sas.*;
  12. /** SasLogMessage implements SasLogInterface
  13.  * Users can implement their own Log Message
  14.  * Everytime the log messages are appended into a file.
  15.  * This will create files Debug,Out,Error.
  16.  * This class can be used with SAServer with -log_class option. See the
  17.  * documentation for more details on the options.
  18.  * Usage : java com.adventnet.snmp.sas.SAServer -log_class SasLogMessage 
  19.  */
  20. public class SasLogMessage implements SasLogInterface {
  21. public void dbg(String dbg) {
  22. appendFile(dbg, "Debug");
  23. }
  24. public void out(String out) {
  25. appendFile(out, "Out");
  26. }
  27. public void err(String err) {
  28. appendFile(err, "Error");
  29. }
  30. private synchronized void appendFile(String s, String fname) {
  31. String filename = fname;
  32. FileWriter fs;
  33. try {
  34. fs = new FileWriter(filename, true);
  35. String s1 = s+"n";
  36. fs.write(s1, 0, s1.length());
  37. fs.close();
  38. } catch (Exception ie) {
  39. System.err.println("Error writing to: "+filename+":"+ie);
  40. ie.printStackTrace();
  41. }
  42. } // end appendFile()
  43. }