1

In java,For example, There are objects have different and regular named chat1,chat2,chat3... they map to chatlogger1,chatlogger2,chatlogger3... how can they output log data to different log file named chatlog1,chatlog2,chatlog3... and with the logback features such as RollingFileAppender

i hope to deal with logback xml configuration than coding;

i have try some ways like

<configuration>

  <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/${logger}.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>logs/${logger}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
      <maxFileSize>10MB</maxFileSize>
      <maxHistory>10</maxHistory>
      <totalSizeCap>100GB</totalSizeCap>
    </rollingPolicy>

    <encoder>
      <pattern>%d [%thread] %-5level %logger - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="INFO">
    <appender-ref ref="file"/>
  </root>
<logger name="chatlogger-*" level="info" additivity="false">
        <appender-ref ref="file"/>
    </logger>
</configuration>

and code with

Logger = LoggerFactory.getLogger("chatlogger-" + variableName );

but it doesnt work,${logger} can not be recognize.

The key point is that logger name is dynamic,not fixed, so i can not predefine each one in configuration. Is there some way to write wildcards that would solve the problem?

belowfox
  • 51
  • 5

0 Answers0