Logback Configuration Log file location

Source: Internet
Author: User
Logback the output log file, which is placed under the directory of the startup process by default

For example, if the program runs directly in Eclipse, it will output to the directory where Eclipse.exe resides, and if run in TOMCAT, it will be exported to the%tomcat_home%/bin directory
<appender name= "FILE"
		class= "Ch.qos.logback.core.rolling.RollingFileAppender" >

		<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
			<filenamepattern>mylog/logfile.%d{ yyyy-mm-dd}.log</filenamepattern>
			<maxHistory>30</maxHistory>
		</rollingPolicy>

		<encoder>
			<pattern>%-4relative%d{hh:mm:ss. SSS}-[%thread]%-5level%class-%msg%n</pattern>
		</encoder>

	</appender>

If the application is deployed under JBOSS and the above configuration file is used, a MyLog folder is created in the%jboss_home%/bin directory

Of course, this is not usually the case, because the log files in the application server's Bin directory is very strange, so you can use absolute path or relative path, the location of the configuration log file

Absolute path:
<appender name= "FILE"
		class= "Ch.qos.logback.core.rolling.RollingFileAppender" >

		<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
			<filenamepattern>/opt/xxx/log/logfile .%d{yyyy-mm-dd}.log</filenamepattern>
			<maxHistory>30</maxHistory>
		</rollingpolicy >

		<encoder>
			<pattern>%-4relative%d{hh:mm:ss. SSS}-[%thread]%-5level%class-%msg%n</pattern>
		</encoder>

	</appender>

Relative path:
<property name= "LogDir" value= ". /.. /youcanfindme "/>

	<appender name=" FILE "
		class=" Ch.qos.logback.core.rolling.RollingFileAppender " >

		<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
			< Filenamepattern>${logdir}/logfile.%d{yyyy-mm-dd}.log</filenamepattern>
			<maxHistory>30</ maxhistory>
		</rollingPolicy>

		<encoder>
			<pattern>%-4relative%d{hh:mm:ss. SSS}-[%thread]%-5level%class-%msg%n</pattern>
		</encoder>

	</appender>

The Logback version here is the latest logback-1.0.4, and the old version seems to have a problem configuring the relative path.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.