Java Log APIFunctionally, the functionality required by the log API itself is simple enough to be able to record a piece of text. The user of the API constructs the corresponding text information according to the current context information when it needs to record, and invokes the API to complete the record. In general, the log API consists of the following sections:
Recorder (Logger): The user of
useful), which is the most important cause of memory leaks. Then cite another example to illustrate the memory leaks in Java. Suppose there is a log class logger, which provides a static log (String msg), and any other class can call LOGGER.LOG (message) to record the contents of the message into the system's log file.The logger class has a static variable of ty
? Is it added again, the problem is resolved after finding it again to delete?The above problems and contradictions can be solved well by using log4j. The log4j has a log level that controls whether logging is logged. Its low-to-high levels are as follows:All The purpose of grading logs is to be flexible to configure. For example, if the log level is limited to debug, the info, WARN, ERROR, FATAL, and OFF are logged, including debug, and if the level is defined as info, then the log of the follo
;
Import Java.net.ServerSocket;
Import Java.net.Socket;
Import Java.util.concurrent.TimeUnit;
Import Java.util.logging.Logger;
Import Demo.callable.ThreadPoolTaskExecutor; public class Tcpechoserverexecutor {public static void main (string[] args) throws IOException {//Create a ser
Ver socket to accept client connection requests ServerSocket Servsock = new ServerSocket (5500);
Logger L
eventlistener ){ This . El = Eventlistener;} @ override Public Boolean Supportsevents (){ Return True ;} // Implementation that saves the properties in a very secure way Public Void Changepropertiesforabap_as (string destname, properties Properties ){ Synchronized (Securedbstorage ){ If (Properties = Null ){ If (Securedbstorage. Remove (destname )! = Null ) El. Deleted (destname );} Else {Securedbstorage. Put (destname, properties); El. Updated (destname ); // Create
Java. util. Date and Java. SQL. Date, java. SQL. Time, java. SQL. Timestamp interchange, java. SQL. timestamp
1. SQL time type to util time type
Principle: java. SQL. date, java. SQL. t
Java beginners how to take the first step of AOP -- use Java Dynamic proxy to implement AOP
Xbird original (Participation score: 36, expert score: 90) published: Version: 1.0 read:1602Times
Current development Community The AOP (Aspect oriented programing) has been promoted, and a large number of excellent frameworks th
information; the output destination of the log information specifies whether the log will be printed to the console or file, and the output format controls the display of the log information.
2.1. Define configuration file
You can actually configure the LOG4J environment in your code without using a configuration file at all. However, using a configuration file will make your application more flexible. LOG4J supports two configuration file formats, one in XML format and one for
Use of Java Standard log tool log4j (source code attached)
Source code Download
Log4j is the de facto Java standard logging tool. Is it possible to use log4j to a certain extent, it is a standard to measure whether a developer is a qualified Java programmer. If you're a Java programmer, if you're not using log4j, then
= Org.apache.log4j.patternlayoutlog4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd HH:MM:SS} [%p]%m%nFinally, in your code, use thePackage Com.xmyself.log4j;import Org.apache.log4j.logger;public class Main {public static void main (string[] args) {new T EST (). Test ();}} Class Test {final Logger log = Logger.getlogger (test.class);p ublic void Test () {log.info ("Hello this is log4j info log");} }Run the main method and the log information
Logger Logger=logger.getlogger (GetClass ());
2 logger.info ("info");
3 logger.error ("error");
log4j Basic Use Method
Log4j is composed of three important components: priority of log information, output destination of log information, and output format of log information. Log information priority from high to low have error, WARN, INFO, DEBUG, respectively, to specify the importance of this
20145311 "Java Programming" Seventh Week study summary textbook study content summary 14th NiO and NIO2Advanced input and output processing, can use NIO (New IO), NIO2 is the file system API15th Chapter General API15.1 Log
15.1.1 Log API
The starting point for using the log is the Logger class, to obtain the Logger class, you must use Logger's static m
Five common rules in Java Logging
Logging is a key factor that needs to be considered during software development. When a product encounters an error, log files are usually the primary choice for error analysis. Moreover, in many cases, they are the only information we have in hand that can be used to identify the situation and root cause of the problem. Therefore, it is extremely important to correctly record the required information.
The followin
Java Logging
Java has a log system (logging framework) that records the runtime information of a program on the JVM ).
The program can use logger (Java. util. Logging. Logger) to record logs.
Java uses a hierarchical naming method
is derived from RuntimeException, caused by program errors, such as array out-of-bounds, type conversion error, and the other contains other exceptions, such as I/O errors. such as opening a non-existing file. the Java specification calls the exceptions derived from the preceding two classes as unchecked exceptions, and all other exceptions are called checked exceptions. if you want to pass an exception, you must add a throws specifier in the method
set the status query, query how long it will take to expire ....
Import java. io. serializable; public class ConsumerInfoState implements Serializable {/*** serialization ID */private static final long serialVersionUID = 1L;/*** expiration time 20 s */protected long expiration; private String topic; private String userId; private boolean isSubscribed = false; private long CONSUMER_INSTANCE_TIMEOUT_MS_DEFAULT = 5000; public ConsumerInfoState (String u
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.