Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Log4j in JBuilder

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use Log4j in JBuilder, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

/ / call configuration file 1 (log does not wrap output)

Public static void ConfigLog () {

String resource = "/ util/ConfigLog.properties"

URL configFileResource =

Util.Log4j.class.getResource (resource)

PropertyConfigurator.configure (configFileResource)

}

/ / call configuration file 2 (log line wrap output)

Public static void ConfigLog_ln () {

String resource = "/ util/ConfigLog_ln.properties"

URL configFileResource =

Util.Log4j.class.getResource (resource)

PropertyConfigurator.configure (configFileResource)

}

}

Then build ConfigLog.properties and ConfigLog_ln.properties configuration files in the util package

# ConfigLog.properties

# set logger and level

Log4j.rootCategory=DEBUG, R

# Export to a file

Log4j.appender.R=org.apache.log4j.FileAppender

# output log file name (stored in the root directory of the project)

Log4j.appender.R.File=Log.txt

# the file format is in custom mode (4 options)

Log4j.appender.R.layout=org.apache.log4j.PatternLayout

Log4j.appender.R.layout.ConversionPattern=%m

# ConfigLog_ln.properties

# set logger and level

Log4j.rootCategory=DEBUG, R

# Export to a file

Log4j.appender.R=org.apache.log4j.FileAppender

# output log file name (stored in the root directory of the project)

Log4j.appender.R.File=Log.txt

# the file format is in custom mode (4 options)

Log4j.appender.R.layout=org.apache.log4j.PatternLayout

Log4j.appender.R.layout.ConversionPattern=%m%n

When using it, you can call it in the following way

Import util.Log4j

Log4j.ConfigLog ()

Log4j.logger.debug ("Hello,")

Log4j.logger.info ("my name is Vincent Casularm.")

Log4j.ConfigLog_ln ()

Log4j.logger.debug ("Hello,")

Log4j.logger.info ("my name is Vincent Casularm.")

The output in the Log.txt file is as follows

Hello, my name is Vincent Casularm.

Hello

My name is Vincent Casularm.

Note: if you use * .html file to store the log, it will be displayed continuously even if% n is used, and you need to add a newline character manually

Thank you for reading this article carefully. I hope the article "how to use Log4j in JBuilder" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report