Configure embedded tomcat & make access logs effect under spring boot frame

First of all, I’ll say something about my comprehension of embedded container and what is access log.

Generally, we always build one tomcat container in somewhere, almost every server holds the same container, tomcat or jetty. Then we put our application into it, to managet it by container which integrated with management scripts, startup/shutdown/jdk_home/jvm_allocate so on. Embedded container is similar with the independent one and integrated by application which means the application  can manage itself as convenient as possible. Usually, some simple commands can get the key points.

What is access logs ?

I think we certainly know nginx and the details about logs which go through it well, when one request comes to it , the container will record some necessary quotas, such as request uri, headers, request time, status etc. We usually call the records as access logs.

  • Dependency solutions.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>

  • Log4j configures

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %d [%t] %c{1} - %m%n" />
    </layout>
  </appender>

  <appender name="roll" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="/tmp/http_app.log" />
    <param name="DatePattern" value=".yyyy-MM-dd" />
    <param name="Append" value="true" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %d [%t] %c{1} - %m%n" />
    </layout>
  </appender>

  <logger name="com.ivan">
    <level value="debug" />
  </logger>

  <logger name="org.springframework">
    <level value="info" />
  </logger>

  <root>
    <priority value="debug" />
    <appender-ref ref="console" />
    <appender-ref ref="roll" />
  </root>

</log4j:configuration>

 

  • Start service in command line to make embedded tomcat/access_log effect and locate the logs generation.

ivan@ivan nohup java -Xmn2G -Xms2G -Dserver.tomcat.access-log-enabled=true -Dserver.tomcat.access-log-pattern="%h %l %u %t '%r' %s %b %D" -Dserver.tomcat.basedir=/tmp/home_service -Dserver.port=9010 -jar homeservice-1.0-SNAPSHOT.jar >> sys.log

 

 

 

 

 

 

 

 

 

 

 

 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>