static void configure()

in src/main/java/com/spotify/logging/LoggingConfigurator.java [456:512]


  static void configure(final JewelCliLoggingOptions opts) {
    // Use logback config file to setup logging if specified, discarding any other logging options.
    if (!opts.logFileName().isEmpty()) {
      configure(new File(opts.logFileName()), opts.ident());
      return;
    }

    final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    // Log uncaught exceptions
    UncaughtExceptionLogger.setDefaultUncaughtExceptionHandler();

    // Setup context
    final LoggerContext context = setupLoggerContext(rootLogger, opts.ident());

    // See if syslog host was specified via command line or environment variable.
    // The command line value takes precedence, which defaults to an empty string.
    String syslogHost = opts.syslogHost();
    if (syslogHost.isEmpty()) {
      syslogHost = getSyslogHost();
    }

    // See if syslog port was specified via command line or environment variable.
    // The command line value takes precedence, which defaults to -1.
    int syslogPort = opts.syslogPort();
    if (syslogPort < 0) {
      syslogPort = getSyslogPort();
    }

    // Setup syslog logging
    if (opts.syslog() || syslogHost != null || syslogPort > 0) {
      rootLogger.addAppender(
          getSyslogAppender(context, syslogHost, syslogPort, ReplaceNewLines.OFF));
    } else {
      rootLogger.addAppender(getStdErrAppender(context, ReplaceNewLines.OFF));
    }

    // Setup default logging level
    rootLogger.setLevel(Level.INFO.logbackLevel);

    // Setup logging levels
    if (opts.error()) {
      rootLogger.setLevel(Level.ERROR.logbackLevel);
    }
    if (opts.warn()) {
      rootLogger.setLevel(Level.WARN.logbackLevel);
    }
    if (opts.info()) {
      rootLogger.setLevel(Level.INFO.logbackLevel);
    }
    if (opts.debug()) {
      rootLogger.setLevel(Level.DEBUG.logbackLevel);
    }
    if (opts.trace()) {
      rootLogger.setLevel(Level.TRACE.logbackLevel);
    }
  }