Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Log4j configuration file Explanation     - Ceph performance optimization summary (v0.94) (Server)

- Simple and fast sorting (Programming)

- Java precision four operations (Programming)

- Linux process group, session daemon (Linux)

- With screenfetch linux logo and basic hardware information display with cool Linux logo (Linux)

- Shell Programming points to note about the function (Programming)

- Can not empty the Recycle Bin to repair problems in Ubuntu 14.04 (Linux)

- Shell scripts quickly deploy Tomcat project (Server)

- Tmux create the perfect terminal management tool under CentOS (Linux)

- Linux Powerful IDE - Geany configuration instructions (Linux)

- History of the most complex validation e-mail address regular expression (Linux)

- Ubuntu 14.04 configure JDK1.8.0_25, switchable version (Linux)

- shell-like program (Programming)

- Changes in C # asynchronous programming model (Programming)

- How to use jgit to manage Git submodule (Linux)

- MySQL5.6 based GTID master-slave replication (Database)

- Android Unzip the ZIP / GZIP data (based on the InflaterInputStream implementation) (Programming)

- Grep how to find files based on file contents in UNIX (Linux)

- Linux asynchronous read documents by AIO (Programming)

- Arrow keys, backspace key garbled in Python-2.7.5 Interactive Mode under CentOS 5.8 (Linux)

 
         
  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:      
 
- Terminal fun: 6 interesting Linux command-line tools (Linux)
- Linux regex sed detailing (Linux)
- Linux rights management (Linux)
- Git Installation and Configuration (Network Agent settings) (Linux)
- CentOS and RHEL installation under GAMIT10.6 (Linux)
- JSON data normalization (normalize) (Programming)
- Let your PHP 7 faster the Hugepage (Linux)
- Linux, Oracle listen address modification (Database)
- Slice MyCAT common fragmentation rules of enumeration (Database)
- SHELL script to use anti SSH brute force and vsftpd (Linux)
- Create a project using Android Studio LinearLayout (Programming)
- Quickly locate the mistakes by gdb location (Programming)
- To install Internet security firewall Raiders (Linux)
- Atheros AR8161 / AR8162 network card driver problem solving in CentOS 6.4 (Linux)
- Linux System Getting Started Learning: Statistical process a number of threads in Linux (Linux)
- jQuery plugin dynamic label generation (Linux)
- CentOS6 install Redis (Database)
- Safe learning through self-extracting package to achieve invasion (Linux)
- SQLite3 simple operation (Database)
- C ++ why we chose to use the smart pointer (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.