openTSDB日志配置

openTSDB启动之后,发现在日志目录下只生成了日志空文件,并没有写入日志内容。查看日志配置文件logback.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!--<jmxConfigurator/>-->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>
        %d{ISO8601} %-5level [%thread] %logger{0}: %msg%n
      </pattern>
    </encoder>
  </appender>
  
  <!-- This appender is responsible for the /logs endpoint. It maintains MaxSize 
       lines of the log file in memory. If you don't need the endpoint, disable
       this appender (by removing the line "<appender-ref ref="CYCLIC"/>" in
       the "root" section below) to save some cycles and memory. -->
  <appender name="CYCLIC" class="ch.qos.logback.core.read.CyclicBufferAppender">
    <MaxSize>1024</MaxSize>
  </appender>
  
  <!-- Appender to write OpenTSDB data to a set of rotating log files -->
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
      <file>/var/log/opentsdb/opentsdb.log</file>
      <append>true</append>
      <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
         <fileNamePattern>/home/y/logs/opentsdb2/opentsdb.log.%i</fileNamePattern>
         <minIndex>1</minIndex>
         <maxIndex>4</maxIndex>
      </rollingPolicy>
      <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
         <maxFileSize>512MB</maxFileSize>
      </triggeringPolicy>
      <!-- encoders are assigned the type
       ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
      <encoder>
         <pattern>%date{ISO8601} [%thread] %-5level [%logger{0}.%M] - %msg%n</pattern>
      </encoder>
   </appender>
  
  <!-- Appender for writing full and completed queries to a log file. To use it, make
       sure to set the "level" to "INFO" in QueryLog below. -->
  <appender name="QUERY_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/var/log/opentsdb/queries.log</file>
    <append>true</append>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>/var/log/opentsdb/queries.log.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>4</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>128MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%date{ISO8601} [%logger.%M] %msg%n</pattern>
    </encoder>
  </appender>
  
  <!-- Per class logger levels -->
  <logger name="QueryLog" level="INFO" additivity="false">
    <appender-ref ref="QUERY_LOG"/>
  </logger>
  <logger name="org.apache.zookeeper" level="INFO"/>
  <logger name="org.hbase.async" level="INFO"/>
  <logger name="com.stumbleupon.async" level="INFO"/>
  
  <!-- Fallthrough root logger and router -->
  <root level="INFO">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="CYCLIC"/>
    <!-- Uncomment to log to file -->
    <!--<appender-ref ref="FILE"/>-->
  </root>
</configuration>
<appender-ref ref="FILE"/> 默认被注释掉,导致日志内容不会像文件中输出。取消此处注释,opentsdb.log文件中会有日志输出。但此处配置的日志并不是按日期每天生成的,不方便查找日志。修改为如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
    <property name="LOG_HOME" value="/data/logs/opentsdb"/>

  <!--<jmxConfigurator/>-->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>
        <!--%d{ISO8601} %-5level [%thread] %logger{0}: %msg%n-->
        [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n
      </pattern>
    </encoder>
  </appender>
  
  <!-- This appender is responsible for the /logs endpoint. It maintains MaxSize 
       lines of the log file in memory. If you don't need the endpoint, disable
       this appender (by removing the line "<appender-ref ref="CYCLIC"/>" in
       the "root" section below) to save some cycles and memory. -->
  <appender name="CYCLIC" class="ch.qos.logback.core.read.CyclicBufferAppender">
    <MaxSize>1024</MaxSize>
  </appender>
  
  <!-- Appender to write OpenTSDB data to a set of rotating log files -->
  <!--<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
      <file>${LOG_HOME}/opentsdb.log</file>
      <append>true</append>
      <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
         <fileNamePattern>${LOG_HOME}/opentsdb.log.%i</fileNamePattern>
         <minIndex>1</minIndex>
         <maxIndex>4</maxIndex>
      </rollingPolicy>
      <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
         <maxFileSize>100MB</maxFileSize>
      </triggeringPolicy>
      &lt;!&ndash; encoders are assigned the type
       ch.qos.logback.classic.encoder.PatternLayoutEncoder by default &ndash;&gt;
      <encoder>
         <pattern>%date{ISO8601} [%thread] %-5level [%logger{0}.%M] - %msg%n</pattern>
      </encoder>
   </appender>-->
    <!-- 修改为TimeBasedRollingPolicy,按日期产生日志文件-->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--<Encoding>UTF-8</Encoding>-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>${LOG_HOME}/opentsdb.%d{yyyy-MM-dd}_%i.info.log</FileNamePattern>
            <!--日志文件保留天数-->
            <MaxHistory>180</MaxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n</pattern>
        </encoder>
    </appender>


  <!-- Appender for writing full and completed queries to a log file. To use it, make
       sure to set the "level" to "INFO" in QueryLog below. -->
    <appender name="QUERY_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/queries.log</file>
        <append>true</append>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${LOG_HOME}/queries.log.%i</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>4</maxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>128MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>%date{ISO8601} [%logger.%M] %msg%n</pattern>
        </encoder>
    </appender>
  
  <!-- Per class logger levels -->
  <logger name="QueryLog" level="INFO" additivity="false">
    <appender-ref ref="QUERY_LOG"/>
  </logger>
  <logger name="org.apache.zookeeper" level="INFO"/>
  <logger name="org.hbase.async" level="INFO"/>
  <logger name="com.stumbleupon.async" level="INFO"/>
  
  <!-- Fallthrough root logger and router -->
  <root level="INFO">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="CYCLIC"/>
    <!-- Uncomment to log to file -->
    <appender-ref ref="FILE"/>
    <!--<appender-ref ref="QUERY_LOG"/>-->
  </root>
</configuration>
按日期产生日志文件,每个文件大小100M,保留180天的日志文件。 

queries.log中输出内容和opentsdb.log重复,<!--<appender-ref ref="QUERY_LOG"/>-->  QUERY_LOG内容不再向文件中输出(格式也未修改)。


 

 

 



posted @ 2018-03-07 09:54 huonan 阅读(...) 评论(...) 编辑 收藏