Logback configuration generates multiple log files

Source: Internet
Author: User

Recently want to use the project to generate multiple log files, on the Internet to check the relevant documents. Sorted out, took out has been shared by everyone:

Before I write, I think you already know how Logback is configured.

1, the configuration file add the following code:

<!--connection Statistics-->
<appender name= "Linkstat" class= "Ch.qos.logback.core.rolling.RollingFileAppender" >
<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
class= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" >

<!--a custom contactlogutil class in a Java project specifies that the Contactlogutil class log uses Linkstat generation-->
<logger name= "Com.targtime.dataTransfer.util.ContactLogUtil" >
<appender-ref ref= "Linkstat"/>

2.Create class Contactloguti in Java

Package com.targtime.dataTransfer.util;

Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;

public class Contactlogutil {
Private static final Logger log = Loggerfactory.getlogger (Contactlogutil.class);

public static void Contactlog (String msg) {
Log.info ("{}", msg);

3. Generate log

The log content is entered into the log file, and only the following code needs to be invoked:

Contactlogutil.contactlog ("More log file test");

If you want to generate another log file, you can then customize a Java class.

I hope to help you, if you have questions about the log configuration you can view: Logback configuration

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.