src/java/isac/bridge/BridgeLogger.java
author mlang
Tue, 28 Jun 2005 13:14:03 +0200
changeset 2544 631fe7f467b7
parent 2448 f6065237ac78
child 2706 4916b66a7022
permissions -rw-r--r--
cosmetics part2
     1 /*
     2  * Created on Aug 21, 2003
     3  */
     4 package isac.bridge;
     5 
     6 /**
     7  * Simple Logging utility class used by the bridge components
     8  * 
     9  * @version 1.0
    10  * @author rgradisc
    11  */
    12 import java.io.FileWriter;
    13 import java.io.IOException;
    14 import java.util.Date;
    15 
    16 public class BridgeLogger {
    17 
    18     //The logging text will be stored in this file
    19     FileWriter general_log_;
    20 
    21     //minimum severity level of a message to be logged
    22     //0 == log everything
    23     int min_log_level_ = 0;
    24 
    25     /**
    26      * Create a new BridgeLogger which writes data to a file
    27      * 
    28      * @param path
    29      *            The path to the file which should be logged into
    30      */
    31     public BridgeLogger(String path) {
    32         try {
    33             general_log_ = new FileWriter(path + "../sml/BridgeLog/general.txt");
    34             log(1, "--------------------------");
    35             log(1, "Server started on " + new Date());
    36             log(1, "--------------------------");
    37         } catch (IOException e) {
    38             e.printStackTrace();
    39         }
    40     }
    41 
    42     /**
    43      * Log general messages of bridge components in one file
    44      * 
    45      * @param level
    46      *            Severity level
    47      * @param msg
    48      *            The message to be logged
    49      */
    50     public void log(int level, String msg) {
    51         if (level > min_log_level_) {
    52             try {
    53                 general_log_.write(msg + "\n");
    54                 general_log_.flush();
    55             } catch (IOException e) {
    56                 e.printStackTrace();
    57             }
    58         }
    59     }
    60 
    61     /**
    62      * Close the logging file
    63      */
    64     public void close() {
    65         try {
    66             general_log_.close();
    67         } catch (IOException e) {
    68             e.printStackTrace();
    69         }
    70     }
    71 
    72     public int getMinLogLevel() {
    73         return min_log_level_;
    74     }
    75 
    76     public void setMinLogLevel(int i) {
    77         min_log_level_ = i;
    78     }
    79 }