How can I configure system properties or logback configuration variables from typesafe config?

后端 未结 3 1610
死守一世寂寞
死守一世寂寞 2021-02-02 14:15

I have variables with defaults in my logback.xml configuration file, and I would like to be able to optionally set these variables from my typesafe config app

3条回答
  •  梦毁少年i
    2021-02-02 14:35

    I chose to programmatically configure logback having typesafe config. It turned out to be easy.

    def enableRemoteLogging(config: Config) = {
        val ctx = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
    
        val gelf = new GelfAppender
        gelf.setGraylog2ServerHost(config.getString("logging.remote.server"))
        gelf.setUseLoggerName(true)
        gelf.setUseThreadName(true)
        gelf.setUseMarker(true)
        gelf.setIncludeFullMDC(true)
        gelf.setContext(ctx)
        gelf.start()
    
        LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)
          .asInstanceOf[ch.qos.logback.classic.Logger]
          .addAppender(gelf)
      }
    

提交回复
热议问题