Problem & logback generating catalina.base_IS_UNDEFINED VM how to add parameters in the log information is stored in springboot catalina.base in eclipse / idea of

1> set in Eclipse in windows-> Preferences-> Java-> the Installed JRES-> the Edit-> the Default  the VM  the Arguments in the text box -Dcatalina.base = d: / logs

2> in the run- IDEA> >> vm options provided in Configurations in the input text box -Dcatalina.base = d: / logs

_________________________________________________________________________________________

Arranged on the relative path see Log4j log:
log log4j produced and provided at a position catalina.home, catalina.base.

Since we introduced the system properties Log4j configuration $ {catalina.base}, Here to talk about how to set up catalina.base, in essence, when you start Tomcat, the command or script to start adding a parameter:
can refer to: Operating System Java environment variables and system properties
1. Third Party Tomcat

In Tomcat installation path / bin below catalina.bat or several related bat file inside, 
there CATALINA_BASE setting properties, of course, set the JAVA_HOME and several other properties. 
These environment variables, when the JVM starts, will be converted into System Properties (in the form of key-value pairs stored). 
You can corresponding increase in the local script file parameters you need.

2.Springboot built-in Tomcat

1> in Eclipse provided in windows-> Preferences-> Java-> the Installed JRES-> the Edit-> the Default  the VM  the Arguments in the text box

D = -Dcatalina.base: / logs
2> in the run- IDEA> configurations provided in, Figure

When the project started with Maven, in need after the command line command with -Dcatalina.base = "your path."

 ______________________________________________________________________________________________________

Springboot the log information is stored in the catalina.base

 
Copy the code
<? xml Version = "1.0" encoding = "UTF-8"?> 
<the Configuration Debug = "to true"> 
    <-! project name -> 
    <Property name = "PROJECT_NAME" value = "springBootTemplate" /> 

    <! using a relative path memory address defined in the log files do not LogBack configuration - -> 
    <Property name = "LOG_HOME" value = "$ {catalina.base} / logs" /> 

    <-! console output - > 
    <the appender name = "the CONSOLE" class = "ch.qos.logback.core.ConsoleAppender"> 
        <withJansi> to true </ withJansi> 
        <Encoder class = "ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
            <! - output format:% d represents the date,% thread indicates that the thread name,% - 5level: level 5 show left character width% msg: log messages,% n newline -> 
        </ Encoder> 
    </ the appender> 
    <-! system error log file ->
            <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n)</pattern>
            <charset>UTF-8</charset>

    <appender name="SYSTEM_FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 过滤器,只打印ERROR级别的日志 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>${LOG_HOME}/${PROJECT_NAME}.system_error.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <MaxHistory> 15 </ MaxHistory>
            <! - the number of days to keep log files ->
            <! - the maximum log file size -> - the maximum size of the log file -> 
            <the MaxFileSize> 10MB </ the MaxFileSize>
        </ rollingPolicy> 

        <Encoder class = "ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
            <- Output Format:!% D represents the date,% thread represents thread name,% - 5level: level 5 show left character width% msg: log messages,% n newline -> 
            <pattern> [% {D the mM-dd-YYYY HH: mm: ss.SSS}] [Thread%] [% -5level] {50} Logger% -%% n-MSG </ pattern> 
            <charset> UTF-. 8 </ charset> 
        </ Encoder> 
    </ the appender> 
    <Logger name = "system_error" the additivity = "to true"> 
        <appender-ref ref = "SYSTEM_FILE" /> 
    </ Logger> 

    <-! print their own log files for log recording important information -> 
    <appender name = "MY_INFO_FILE" class = "ch.qos.logback.core.rolling.RollingFileAppender "> 
        <-! filter, print only ERROR level log ->
        <filter class="ch.qos.logback.classic.filter.LevelFilter"> 
            <Level> the INFO </ Level> 
            <onMatch> ACCEPT </ onMatch> 
            <onMismatch> DENY </ onMismatch> 
        </ filter> 
        <class = rollingPolicy "ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> 
            <-! file name of the log file output -> 
            . <FileNamePattern> $ {LOG_HOME} / {the PROJECT_NAME $ D {%} .my_info the MM-dd-YYYY . i.log%} </ FileNamePattern> 
            <-! number of days to keep log files -> 
            <MaxHistory> 15 </ MaxHistory> 
            <-! maximum size of the log file -> 
            <the MaxFileSize> 10MB </ the MaxFileSize> 
        </rollingPolicy>

        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <- Formatting Output:!% D represents the date,% thread indicates that the thread name,% - 5level: Level 5 show left character width% msg: log messages,% n newline -> 
            <pattern> [% {the mM-YYYY-D dd HH: mm: ss.SSS}] [Thread%] [% -5level] {50} Logger% -%% n-MSG </ pattern> 
            <charset> UTF-. 8 </ charset> 
        < / Encoder> 
    </ the appender> 
    <Logger name = "my_info" = the additivity "to true"> 
        <REF-REF = the appender "MY_INFO_FILE" /> 
    </ Logger> 

    <-! development environment configuration log -> 
    <springProfile = name "dev"> 
        <= the root Level "the INFO"> 
            <REF-REF = the appender "the CONSOLE" /> 
            <REF-REF = the appender "SYSTEM_FILE" />
        </ the root> 
    </ springProfile> 

    <-! logging configuration in the production environment -> 
    <springProfile name = "Prod">
        <root level="INFO">
            <appender-ref ref="SYSTEM_FILE" />
        </root>
    </springProfile>
</configuration>
Copy the code

SpringBoot project described in official documents, the default has been dependent on a number of logging framework, which recommended that Logback, SpringBoot has relied Logback there is no need to add dependencies manually.

How to configure

1, in the new logback-spring.xml resources directory

As long as your name is logback-spring.xml then SpringBoot will automatically recognize and read it, so you do not need to perform additional configuration in the application.yml.

Configuration file as follows:

Same here logback configuration file will read the appropriate configuration, for example, you use the dev it will read the configuration under dev, if you use the prod will use the configuration under prod.

That project needs until the time on the line, you need only modify the configuration file can be springBoot, do not need to be modified logback, can be achieved in a production environment and development environment to print different log levels

Print in color treated console will display different distinction, it is easy to find the problem.

 

There is a classification of the log file

By tools will separate print log

Important information will need to log in my_info print to file, and important information is stored in system_error error file.

 
Category  Micro Services
Copy the code
<? xml Version = "1.0" encoding = "UTF-8"?> 
<the Configuration Debug = "to true"> 
    <-! project name -> 
    <Property name = "PROJECT_NAME" value = "springBootTemplate" /> 

    <! using a relative path memory address defined in the log files do not LogBack configuration - -> 
    <Property name = "LOG_HOME" value = "$ {catalina.base} / logs" /> 

    <-! console output - > 
    <the appender name = "the CONSOLE" class = "ch.qos.logback.core.ConsoleAppender"> 
        <withJansi> to true </ withJansi> 
        <Encoder class = "ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
            <! - output format:% d represents the date,% thread indicates that the thread name,% - 5level: level 5 show left character width% msg: log messages,% n newline ->
            <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n)</pattern>
            <charset>UTF-8</charset> 
        </ Encoder> 
    </ the appender> 

    <-! system error log file ->
    <appender name="SYSTEM_FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 过滤器,只打印ERROR级别的日志 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>${LOG_HOME}/${PROJECT_NAME}.system_error.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <MaxHistory> 15 </ MaxHistory>
            <! - the number of days to keep log files -> 
            <!- the maximum size of the log file -> 
            <the MaxFileSize> 10MB </ the MaxFileSize>
        </ rollingPolicy> 

        <Encoder class = "ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
            <- Output Format:!% d represents the date,% thread indicates that the thread name,% - 5level: from left to Level 5 characters wide% msg: log messages,% n newline -> 
            <pattern> [% {D the mM-dd-YYYY HH: mm: ss.SSS}] [Thread%] [% -5level]% {Logger 50} -% MSG% n-</ pattern> 
            <charset> UTF-. 8 </ charset> 
        </ Encoder> 
    </ the appender> 
    <Logger name = "system_error" the additivity = "to true"> 
        <the appender-REF REF = "SYSTEM_FILE "/> 
    </ Logger> 

    <-! print their own log files for log recording important information -> 
    <appender name =" MY_INFO_FILE "class =" ch.qos.logback.core.rolling.RollingFileAppender">
        <-! filter, print only ERROR level log ->
        <filter class="ch.qos.logback.classic.filter.LevelFilter"> 
            <Level> the INFO </ Level> 
            <onMatch> ACCEPT </ onMatch> 
            <onMismatch> DENY </ onMismatch> 
        </ filter> 
        <class = rollingPolicy "ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> 
            <-! file name of the log file output -> 
            . <FileNamePattern> $ {LOG_HOME} / {the PROJECT_NAME $ D {%} .my_info the MM-dd-YYYY . i.log%} </ FileNamePattern> 
            <-! number of days to keep log files -> 
            <MaxHistory> 15 </ MaxHistory> 
            <-! maximum size of the log file -> 
            <the MaxFileSize> 10MB </ the MaxFileSize> 
        </rollingPolicy>

        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <- Formatting Output:!% D represents the date,% thread indicates that the thread name,% - 5level: Level 5 show left character width% msg: log messages,% n newline -> 
            <pattern> [% {the mM-YYYY-D dd HH: mm: ss.SSS}] [Thread%] [% -5level] {50} Logger% -%% n-MSG </ pattern> 
            <charset> UTF-. 8 </ charset> 
        < / Encoder> 
    </ the appender> 
    <Logger name = "my_info" = the additivity "to true"> 
        <REF-REF = the appender "MY_INFO_FILE" /> 
    </ Logger> 

    <-! development environment configuration log -> 
    <springProfile = name "dev"> 
        <= the root Level "the INFO"> 
            <REF-REF = the appender "the CONSOLE" /> 
            <REF-REF = the appender "SYSTEM_FILE" />
        </ the root> 
    </ springProfile> 

    <-! logging configuration in the production environment -> 
    <springProfile name = "Prod">
        <root level="INFO">
            <appender-ref ref="SYSTEM_FILE" />
        </root>
    </springProfile>
</configuration>
Copy the code

SpringBoot project described in official documents, the default has been dependent on a number of logging framework, which recommended that Logback, SpringBoot has relied Logback there is no need to add dependencies manually.

How to configure

1, in the new logback-spring.xml resources directory

As long as your name is logback-spring.xml then SpringBoot will automatically recognize and read it, so you do not need to perform additional configuration in the application.yml.

Configuration file as follows:

Same here logback configuration file will read the appropriate configuration, for example, you use the dev it will read the configuration under dev, if you use the prod will use the configuration under prod.

That project needs until the time on the line, you need only modify the configuration file can be springBoot, do not need to be modified logback, can be achieved in a production environment and development environment to print different log levels

Print in color treated console will display different distinction, it is easy to find the problem.

 

There is a classification of the log file

By tools will separate print log

Important information will need to log in my_info print to file, and important information is stored in system_error error file.

Guess you like

Origin www.cnblogs.com/kelelipeng/p/11322261.html