src/java/isac/bridge/BridgeLogger.java
changeset 2544 631fe7f467b7
parent 2448 f6065237ac78
child 2706 4916b66a7022
equal deleted inserted replaced
2543:62acf19daa74 2544:631fe7f467b7
    14 import java.util.Date;
    14 import java.util.Date;
    15 
    15 
    16 public class BridgeLogger {
    16 public class BridgeLogger {
    17 
    17 
    18     //The logging text will be stored in this file
    18     //The logging text will be stored in this file
    19     FileWriter generalLog;
    19     FileWriter general_log_;
    20 
    20 
    21     //minimum severity level of a message to be logged
    21     //minimum severity level of a message to be logged
    22     //0 == log everything
    22     //0 == log everything
    23     int min_log_level_ = 0;
    23     int min_log_level_ = 0;
    24 
    24 
    28      * @param path
    28      * @param path
    29      *            The path to the file which should be logged into
    29      *            The path to the file which should be logged into
    30      */
    30      */
    31     public BridgeLogger(String path) {
    31     public BridgeLogger(String path) {
    32         try {
    32         try {
    33             generalLog = new FileWriter(path + "../sml/BridgeLog/general.txt");
    33             general_log_ = new FileWriter(path + "../sml/BridgeLog/general.txt");
    34             log(1, "--------------------------");
    34             log(1, "--------------------------");
    35             log(1, "Server started on " + new Date());
    35             log(1, "Server started on " + new Date());
    36             log(1, "--------------------------");
    36             log(1, "--------------------------");
    37         } catch (IOException e) {
    37         } catch (IOException e) {
    38             e.printStackTrace();
    38             e.printStackTrace();
    48      *            The message to be logged
    48      *            The message to be logged
    49      */
    49      */
    50     public void log(int level, String msg) {
    50     public void log(int level, String msg) {
    51         if (level > min_log_level_) {
    51         if (level > min_log_level_) {
    52             try {
    52             try {
    53                 generalLog.write(msg + "\n");
    53                 general_log_.write(msg + "\n");
    54                 generalLog.flush();
    54                 general_log_.flush();
    55             } catch (IOException e) {
    55             } catch (IOException e) {
    56                 e.printStackTrace();
    56                 e.printStackTrace();
    57             }
    57             }
    58         }
    58         }
    59     }
    59     }
    61     /**
    61     /**
    62      * Close the logging file
    62      * Close the logging file
    63      */
    63      */
    64     public void close() {
    64     public void close() {
    65         try {
    65         try {
    66             generalLog.close();
    66             general_log_.close();
    67         } catch (IOException e) {
    67         } catch (IOException e) {
    68             e.printStackTrace();
    68             e.printStackTrace();
    69         }
    69         }
    70     }
    70     }
    71 
    71