Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Log4j configuration file Explanation     - Mac OS X 10.10 Yosemite compiling OpenJDK 9 (Linux)

- Linux Thread Synchronization (Programming)

- RPM package management tools under Linux (Linux)

- To install GCC development environment under SUSE11 (Linux)

- Mahout source code analysis: FP-Growth algorithm parallelization (Programming)

- Apple Mac computer to install Windows 10 Concise Guide (Linux)

- Hunk / Hadoop: Performance Best Practices (Server)

- Father of Python: Why Python zero-based index (Programming)

- Port Telnet command to detect the remote host is turned on (Linux)

- 7 extremely dangerous Linux commands (Linux)

- How do you know your public IP terminal in Linux (Linux)

- CentOS 5.5 install ntop (Linux)

- Installation Experience open source car Automotive Grade Linux system (Linux)

- GitLab installation configuration notes (Linux)

- ASM learning overview (Database)

- Enable Intel Rapid Start in GNU / Linux (Linux)

- MySQL and MariaDB new master from the cluster configuration GTID (Database)

- Linux install Samba file sharing server (Server)

- Linux run queue process scheduling (Programming)

- About AWR More Description (Database)

 
         
  Log4j configuration file Explanation
     
  Add Date : 2018-11-21      
         
       
         
  Log4j configuration file is used to set the record level, the output destination and layout can be log4j.properties or log4j.xml. The following explanation to log4j.properties configuration manner.

The basic format of the configuration file

The basic format is as follows:

# Configure the root Logger
log4j.rootLogger = [level], appenderName1, appenderName2, ......
# Set the log information output destination (Appender)
log4j.appender.appenderName = fully.qualified.name.of.appender.class
log4j.appender.appenderName.option1 = value1
......
log4j.appender.appenderName.optionN = valueN
# Log information format (Layout)
log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class
log4j.appender.appenderName.layout.option1 = value1
......
log4j.appender.appenderName.layout.optionN = valueN

Level

Level is the log output levels, a total of five:

Name Level
FATAL 0
ERROR 3
WARN 4
INFO 6
DEBUG 7
Appender

Appender the log output destination, appender Log4j provides the following:

org.apache.log4j.ConsoleAppender (console)
org.apache.log4j.FileAppender (file)
org.apache.log4j.DailyRollingFileAppender (generates a log file per day)
org.apache.log4j.RollingFileAppender (file size reaches the specified size when create a new file)
org.apache.log4j.WriterAppender (log information is sent to the stream format to any designated place)
ConsoleAppender configurable items

Item Explanation
Threshold = DEBUG output log information specified minimum level
ImmediateFlush = true The default value is true, it means that all messages will be immediately output
Target = System.err By default is System.out, specify the output console
FileAppender configurable items

Item Explanation
Threshold = DEBUF output log information specified minimum level
ImmediateFlush = true The default value is true, it means that all messages will be immediately output
File = mylog.txt news output to a file mylog.txt
Append = false The default value is true, will be designated to file, false means the contents of the file will overwrite the message specified
RollingFileAppender configurable items

Item Explanation
Threshold = DEBUG minimum level of output log information specified.
ImmediateFlush = true The default value is true, it means that all messages will be output immediately.
File = mylog.txt mylog.txt specified message is output to a file.
Append = false The default value is true, will be designated to file, false means the message will overwrite the contents of the specified file.
MaxFileSize = 100KB suffix can be KB, MB or GB. When a log file reaches this size, it will automatically scroll, will move the contents of the original file mylog.log.1.
MaxBackupIndex = 2 specifies the maximum number of files that can be generated scrolling.
Layout

Layout of log output format, layout Log4j provides the following:

org.apache.log4j.HTMLLayout (in HTML table format layout),
org.apache.log4j.PatternLayout (the flexibility to specify the layout mode),
org.apache.log4j.SimpleLayout (contains the information string level and log information),
org.apache.log4j.TTCCLayout (including the time the log generated thread type information, etc.)
Layout Example

log4j.appender.A1.layout.ConversionPattern =% - 4r% -5p% d {yyyy-MM-dd HH: mm: ssS}% c% m% n

Symbol Meaning
- Left alignment information output
% P output log information priorities, namely DEBUG, INFO, WARN, ERROR, FATAL
Date or time% d output log point in time, the default format is ISO8601, can also be specified in the following format, for example:% d {yyy MMM dd HH: mm: ss, SSS}, the output similar to: October 18, 2002 22:10: 28,921
% R output from the application starts to output the log information on the number of milliseconds spent
Class% c output log information belongs, usually where the full name
% T output generated the log event thread name
Output occurring position% l log events, equivalent% C.% M (% F:% L) portfolio, including categories were the threads, as well as the number of lines in the code. Example: Testlog4.main (TestLog4.java:10)
NDC (nested diagnostic context)% x and output current thread associated with particular applications such as java servlets used in multi-threaded multi-client.
%% Outputs a "%" character
File name% F output log messages generated where
% L output code line number
% M output code specified in the message log to produce specific information
Output% n Enter a newline, Windows platform, "\ r \ n", Unix platform, "\ n"
Modifiers

You can add modifiers between the% character mode to control the minimum width, maximum width and alignment of the text. Such as:

Examples showing
Name% 20c specify the output category, the minimum width is 20, if the category name is less than 20, then right-aligned by default.
Name% -20c specify the output category, the minimum width is 20, if the category name is less than 20, then "-" sign designated left-aligned.
Name% .30c specify the output category, the maximum width is 30, if the category name, then more than 30, they will be left out of the multi-character truncated, but the words would not be less than 30 spaces.
% 20.30c if the category name is less than 20 to fill the space, and right-aligned, if the name is longer than 30 characters, it is truncated from the far left side of the character output.
     
         
       
         
  More:      
 
- Ubuntu install the camera driver (Linux)
- Linux host system monitoring implement the cgi (Server)
- CentOS 6.5 installation and deployment SVN 1.8.10 (Linux)
- Configuring a Linux operating system security management services Explain (Linux)
- Linux process or thread is bound to a CPU (Programming)
- Json data with double backslashes to a single backslash Json data processing (Programming)
- Linux using TCP-Wrapper Service Management (Linux)
- Spring REST Exception Handling (Programming)
- Linux / CentOS 7.0 installation and configuration under Tomcat 8.0 (Server)
- Several back door and log tool under Linux (Linux)
- Thinking in Java study notes - initialization and cleanup (Programming)
- Linux installed PCRE (Linux)
- Construction of Android and iOS apps use Jenkins Automation (Programming)
- Root of AVL Tree- achieve balanced search trees AVL tree (Programming)
- Using Java arrays implement sequential stack (Programming)
- CentOS How to mount the hard drive (Linux)
- Depth understanding of the TCP protocol (Database)
- How to fix Not Enough Free Disk Space On / boot on Ubuntu (Linux)
- How to upgrade to Ubuntu 14.04 Ubuntu 14.10 (Linux)
- Get the Linux device PCI ID method (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.