Search in sources :

Example 1 with LogFormatter

use of org.syncany.config.LogFormatter in project syncany by syncany.

the class CommandLineClient method initLogHandlers.

private void initLogHandlers(OptionSet options, OptionSpec<String> optionLog, OptionSpec<Void> optionLogPrint, OptionSpec<Void> optionDebug) throws SecurityException, IOException {
    // --log=<file>
    String logFilePattern = null;
    if (options.has(optionLog)) {
        if (!"-".equals(options.valueOf(optionLog))) {
            logFilePattern = options.valueOf(optionLog);
        }
    } else if (config != null && config.getLogDir().exists()) {
        logFilePattern = config.getLogDir() + File.separator + LOG_FILE_PATTERN;
    } else {
        logFilePattern = UserConfig.getUserLogDir() + File.separator + LOG_FILE_PATTERN;
    }
    if (logFilePattern != null) {
        Handler fileLogHandler = new FileHandler(logFilePattern, LOG_FILE_LIMIT, LOG_FILE_COUNT, true);
        fileLogHandler.setFormatter(new LogFormatter());
        Logging.addGlobalHandler(fileLogHandler);
    }
    // --debug, add console handler
    if (options.has(optionDebug) || options.has(optionLogPrint) || (options.has(optionLog) && "-".equals(options.valueOf(optionLog)))) {
        Handler consoleLogHandler = new ConsoleHandler();
        consoleLogHandler.setFormatter(new LogFormatter());
        Logging.addGlobalHandler(consoleLogHandler);
    }
}
Also used : FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) ConsoleHandler(java.util.logging.ConsoleHandler) LogFormatter(org.syncany.config.LogFormatter) ConsoleHandler(java.util.logging.ConsoleHandler) FileHandler(java.util.logging.FileHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)1 FileHandler (java.util.logging.FileHandler)1 Handler (java.util.logging.Handler)1 LogFormatter (org.syncany.config.LogFormatter)1