コード例 #1
0
ファイル: SimpleLogger.java プロジェクト: kmd-himanshu/Helios
  // Initialize class attributes.
  // Load properties file, if found.
  // Override with system properties.
  static void init() {
    INITIALIZED = true;
    loadProperties();

    String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
    if (defaultLogLevelString != null) DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);

    SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
    SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
    SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
    SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
    DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
    LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);

    LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
    TARGET_STREAM = computeTargetStream(LOG_FILE);

    if (DATE_TIME_FORMAT_STR != null) {
      try {
        DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
      } catch (IllegalArgumentException e) {
        Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
      }
    }
  }
コード例 #2
0
 private StaticLoggerBinder() {
   loggerFactory = new Log4jLoggerFactory();
   try {
     @SuppressWarnings("unused")
     Level level = Level.TRACE;
   } catch (NoSuchFieldError nsfe) {
     Util.report(
         "This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
   }
 }
コード例 #3
0
ファイル: SimpleLogger.java プロジェクト: kmd-himanshu/Helios
 private static PrintStream computeTargetStream(String logFile) {
   if ("System.err".equalsIgnoreCase(logFile)) return System.err;
   else if ("System.out".equalsIgnoreCase(logFile)) {
     return System.out;
   } else {
     try {
       FileOutputStream fos = new FileOutputStream(logFile);
       PrintStream printStream = new PrintStream(fos);
       return printStream;
     } catch (FileNotFoundException e) {
       Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
       return System.err;
     }
   }
 }