Use log4j without configuration files
Log4j is an open-source Java program of Apache. It has powerful functions and can be applied to different fields. It supports various types of logs, such as console, file, email, and DB. However, the configuration of log4j must also be complex, and a log4j is required. the propert
When the project is in the development run phase, it is necessary to debug or troubleshoot the logs, and log management is needed to help us solve these problems:In Java we can use SYSTEM.OUT.PRINTLN (), but this way function is too weak, and not easy to control, if temporarily do not want to output what to do? What if I want to output to a file? What if I want partial output? ......Why use both commons-logging and log4j? Why not just use one of them?
Jar package
Log4j-1.2.11.jar
Log4j configuration file
Log4j. Properties
# For JBoss: Avoid to setup log4j outside $ jboss_home/Server/default/deploy/log4j. xml!# For all other servers: comment out the log4j listener in Web. XML t
What do you write? Well, it's decadent recently. I haven't written a blog for a long time. I don't know what to write, but the level has dropped ......
Write something simple. log4j logging:
Jar package:
Commons-logging.jar
Log4j-1.2.15.jar
You can call it directly:
Import org. Apache. commons. Logging. log;Import org. Apache. commons. Logging. logfactory;
Private log logger = logfactory. getlog (this. get
The first time I entered the workplace, I had a comprehensive understanding of "log. Unlike print statements that are everywhere in the student age, schools cannot teach anything useful.
The recent work happens to be to convert the original log4j log component of the project to logback. The reason for conversion is that logback has better performance than log4j. However, the arrival of the latest version
Log4j finally ushered in the first apache version. Log4j 2 is an upgraded version of log4j. This version is significantly improved compared with its predecessor, including many improvements in logback and problems in the logback architecture.
This is the first release version of log4j 2. The following improvements are
log4j Basic Use MethodLOG4J consists of three important components: the priority of the log information, the output destination of the log information, and the output format of the log information. The priority of log information is high to low with error, WARN, INFO, DEBUG, respectively, to specify the importance of this log information; the output destination of the log information specifies whether the log will be printed to the console or the file
LOG4J can be configured by using a configuration file.The configuration steps are as follows: 1. Define the Log component loggerEach logger can have one or more appender, each appender representing the output destination of a log, such as the console or a file.The syntax for configuring root logger is:Log4j.rootlogger=[priority],appendername,appendername,...-The syntax for configuring a custom logger component is:Log4j.logger.loggername=[priority],app
Many diaosi think that log4j is not easy to use because it is not output to the IDE console. Haha, it is actually a disaster caused by configuration. The following describes how to configure log4j to the console step by step,
I believe that log4j's output level and output mode are all known. I will not talk about it here. Let's just look at the code comment:
# All, TRACE, DEBUG, INFO, WARN, ERROR, FITAL, OF
Writing programs on the Java platform is also a bit of a time, from the former Java-ee to the current background program, more or less used to the log4j to output the log, but each time the use of the others are good, and then tell me how to use, and then directly call the good, has been log4j in the state of the half solution. Today, with the understanding of its own, know the reason why the attitude, care
LOG4J Component Composition
The log4j is composed of three important components:
1. Priority of log information (Logger)
2. Output Destination of log information (Appender)
3. The output format of the log information (Layout).
Profile:
The priority of log information from high to low has error, WARN, INFO, DEBUG, respectively, to specify the importance of this log information;
The output destination
The log is an integral part of the application software, and the Apache Open source project log4j is a powerful log component that provides easy logging. On the Apache website: jakarta.apache.org/log4j can download the latest version of the log4j package for free. An example of getting Started
1. Create a new Java project, import package
Write a class that dynamically generates Properties (the form in which log4j. properties is loaded into the memory). Specify the class to dynamically modify anything!======================================The directory cannot be created, but the log file is automatically created.Log4j. appender. R = org. apache. log4j. RollingFileAppenderLog4j. appender. R. File = C: \ bea \ user_projects \ domain \ log=====
The initial desire to invoke an external interface to record audit information while executing a business logic has not been able to find a more elegant way, and it has been discussed that log4j's custom appender may be possible to implement this function. Then I learned about this part of log4j. Apache log4j Architecture Apache log4j is currently the most used l
Original link: http://www.cnblogs.com/mailingfeng/archive/2011/07/28/2119937.htmlLog4j is a very powerful log recording software.First of all, of course, get the log4j jar file, we recommend the 1.2.X version:Http://logging.apache.org/log4j/1.2/download.htmlLet's take a look at Log4j's class diagram.Logger-log writer for programmers to output log informationAppender-Log destination, output formatted log inf
Org. apache. log4j. jdbc. JDBCAppender uses the traditional JDBC connection method to connect to the database, which is inefficient. To solve this problem, we now customize a Log4j Appender and change the database connection to the connection pool, this Appender inherits from org. apache. log4j. jdbc. JDBCAppender, and uses the open source project Poolman (can be
When you are developing a program, debugging (debugging) and logging are very important tasks. However, there are too many logging APIs available because they are both good, it is difficult to make a choice. the foreign Java Forum also has some discussions on these logging methods.
While common logging is a small bridge between these different logging APIs. currently, the most famous LOG method in Java is log4j and JDK 1.4 logging API. in addition, t
I have not written examples in the log4j usage notes. In this article, I will write a complete application instance of log4j.
In the log4j usage notes, we already know that the same log information can be output to multiple output destinations at the same time. In the following example, I will demonstrate how to output log information to the console, files, and d
1. Basic knowledge:Log4j's Chinese documentation (this is based on the latest log4j (jakarta-log4j-1.2.8) Development package comes with the manual translation of the document)Http://dev.csdn.net/develop/article/29/29441.shtmThe corresponding English text:Short Introduction to Log4jHttp://logging.apache.org/log4j/docs/manual.html2. Steps1) Log4j.jar placed under
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.