weblogic log can not be divided, weblogic log splitting, weblogic cluster split logs

weblogic log can not be divided, weblogic log splitting, weblogic cluster split logs

 

================================

© Copyright sweet potatoes Yao 2020-01-06

https://www.cnblogs.com/fanshuyao/

 

A, Log4j Profile

Log4j has three main components:

Loggers (Recorder): log category

Appenders (output source): location of the log to be output

Layouts (layout): log output format

 

1、Loggers

Loggers components in this system is divided into five levels:

DEBUG、INFO、WARN、ERROR、FATAL。

The five levels are sequential, DEBUG <INFO <WARN <ERROR <FATAL, are used to specify the importance of this log information.

Log4j not only the output level lower than the set level log information, assuming Loggers level is set to INFO, the INFO, WARN, ERROR and FATAL level log information will be output, the output level is not lower than INFO DEBUG.

 

2、Appenders

Allow to output log to a different location, such as the console (Console), files (Files) and the like, can generate a new file according to the file size or the number of days, can be sent to other places like in a stream.

Commonly used classes are as follows:

org.apache.log4j.ConsoleAppender (console)

org.apache.log4j.FileAppender (file)

org.apache.log4j.DailyRollingFileAppender (produce a daily log file)

org.apache.log4j.RollingFileAppender (file size reaches the specified size when create a new file)

Org.apache.log4j.WriterAppender (log stream format information is sent to any designated place)

Configuration mode:

log4j.appender.appenderName = className

 

3、Layouts

Their log output format, Log4j Layouts can be attached to the back Appenders accomplish this function.

Layouts provides four log output style, such as the HTML style based on freely specify the style, contains the log level and pattern styles and contains log time, thread, category information and other information.

 

Commonly used classes are as follows:

org.apache.log4j.HTMLLayout (layout in HTML table format)

org.apache.log4j.PatternLayout (the flexibility to specify the layout mode)

Org.apache.log4j.SimpleLayout (containing level information and log information string)

org.apache.log4j.TTCCLayout (including the time the log generated, thread, type and other information)

Configuration mode:

log4j.appender.appenderName.layout =className

 

Second, the detailed configuration instructions

Log4j supports two configuration file format An XML format file, one is the properties file properties.

Below an example to describe the properties file properties log4j.properties configuration.

 

1, the configuration root Logger:

log4j.rootLogger = [level], appenderName1, appenderName2, ... (the default output destination class name of the current incoming end)

log4j.additivity.org.apache = false: Logger does not represent output appender parent Logger's default is true.

level: the lowest level of logging is set, values ​​are OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL or custom level, typically set to INFO.

By setting this level, you can switch control application of the appropriate level of log information, such as where to set the INFO level, the application log information for all DEBUG level will not be printed.

appenderName: is specify where log information to be output. A plurality of output destinations can be specified simultaneously, separated by commas.

For example: log4j.rootLogger = INFO, A, B, C

 

2, configuration information log output destination (appender):

log4j.appender.appenderName = className

appenderName: Custom appderName, in log4j.rootLogger settings;

className: Value can be set as follows:

(1) org.apache.log4j.ConsoleAppender (console)

(2) org.apache.log4j.FileAppender (file)

(3) org.apache.log4j.DailyRollingFileAppender (produce a daily log file)

(4) org.apache.log4j.RollingFileAppender (file size reaches the specified size when generating a new file)

(5) org.apache.log4j.WriterAppender (log stream format information is sent to any designated place)

 

(1) ConsoleAppender options:

Threshold = WARN: log information specified minimum level of output, the default is DEBUG.

ImmediateFlush = true: indicates that all messages will be immediately output, the output is not set to false, the default value is true.

Target = System.err: The default is System.out.

 

(2) FileAppender options:

Threshold = WARN: log information specified minimum level of output, the default is DEBUG.

ImmediateFlush = true: indicates that all messages will be immediately output, the output is not set to false, the default value is true.

Append = false: true indicates that the message designated to document, the contents of the message is covered with false documents specified, the default is true.

File = D: /logs/logging.log4j: logging.log4j news output to a file.

 

(3) DailyRollingFileAppender options:

Threshold = WARN: log information specified minimum level of output, the default is DEBUG.

ImmediateFlush = true: indicates that all messages will be immediately output, the output is not set to false, the default value is true.

Append = false: true indicates that the message designated to document, the contents of the message is covered with false documents specified, the default is true.

File = D: /logs/logging.log4j: Specifies the current output to logging.log4j message file.

DatePattern = yyyy-MM '.': Once a month rolling log files, which produce a new log file each month. The current monthly log file named logging.log4j, the previous month's log file named logging.log4j.yyyy-MM.

In addition, can also be specified by week, day, hour, minute, to scroll the log file, corresponding to the following format:

1) yyyy-MM '.': Monthly

2) yyyy-ww '.': Week

'.' 3) yyyy-MM-dd: day

4) yyyy-MM-dd-a '.': Twice a day

'.' 5) yyyy-MM-dd-HH: hour

6) yyyy-MM-dd-HH-mm '.': Per minute

 

(4) RollingFileAppender options:

Threshold = WARN: log information specified minimum level of output, the default is DEBUG.

ImmediateFlush = true: indicates that all messages will be immediately output, the output is not set to false, the default value is true.

Append = false: true indicates that the message designated to document, the contents of the message is covered with false documents specified, the default is true.

File = D: /logs/logging.log4j: logging.log4j news output to a file.

MaxFileSize = 100KB: suffix can be KB, MB or GB. When the log file reaches this size, it will automatically scroll the contents of the upcoming move logging.log4j.1 original file.

MaxBackupIndex = 2: Specifies the maximum number of files that can be produced rolling, for example, set two can produce logging.log4j.1, logging.log4j.2 two rolling papers and a logging.log4j file.

 

3, the output format of log information (Layout):

log4j.appender.appenderName.layout=className

className: Value can be set as follows:

(1) org.apache.log4j.HTMLLayout (HTML table format layout)

(2) org.apache.log4j.PatternLayout (the flexibility to specify the layout mode)

(3) org.apache.log4j.SimpleLayout (comprising level information and log information string)

(4) org.apache.log4j.TTCCLayout (log time comprising the time, thread, type information, etc.)

(1) HTMLLayout options:

LocationInfo = true: java output file name and line number, the default value is false.

Title = My Logging: The default value is Log4J Log Messages.

(2) PatternLayout options:

ConversionPattern =% m% n: setting display a message in what format.

 

Format symbol Description:

% P: output log information indicating the priority, i.e. DEBUG, INFO, WARN, ERROR, FATAL.

% D: output log date or time point in time, the default format is ISO8601, you can specify the format followed in as:% d {yyyy / MM / dd HH: mm: ss, SSS}.

% R: output from the application to the number of milliseconds spent output the log information.

% T: output generated thread name of the log event.

% L: log event occurrence location output corresponds% c% M.: Composition (% F% L), including the full name of the class, method, file name and line number in the code. For example: test.TestLog4j.main (TestLog4j.java:10).

Full name category output log information belongs, usually the class where:% c.

% M: generating log information output method name.

% F: output file name where the log messages generated.

% L :: outputs row number code.

% M :: specified output code specific log information.

% N: a carriage return line feed output, Windows platform "rn", Unix platform "n".

% X: output associated with the current thread and NDC (nested diagnostic context), especially in applications like java servlets used in this multi-client multi-threaded.

%%: output a "%" character.

Further, the modifiers may also be coupled between the character% and to control the format of the minimum and maximum length, and the alignment of the text. Such as:

1) c: the name of the output category, the minimum length is 20, if the category name length is less than 20, then, by default right alignment.

2)% - 20c: "-" sign indicates left-aligned.

. 3)% 30c: the name of the category specified output, the maximum length is 30, if the category name of a length greater than 30, then, will be left out of the plurality of characters truncated, but if less than 30 will not fill the space.

 

Three, Log4j Configuration Example

 

Log4j configuration file to achieve the output to the console, files, rollback files, send e-mail log, log output to a database table, custom labels, such as full function.

log4j.rootLogger=DEBUG,console,dailyFile,im

log4j.additivity.org.apache=true

 

# Console (console)

log4j.appender.console=org.apache.log4j.ConsoleAppender

log4j.appender.console.Threshold=DEBUG

log4j.appender.console.ImmediateFlush=true

log4j.appender.console.Target=System.err

log4j.appender.console.layout=org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n

 

# Log file (logFile)

log4j.appender.logFile=org.apache.log4j.FileAppender

log4j.appender.logFile.Threshold=DEBUG

log4j.appender.logFile.ImmediateFlush=true

log4j.appender.logFile.Append=true

log4j.appender.logFile.File=D:/logs/log.log4j

log4j.appender.logFile.layout=org.apache.log4j.PatternLayout

log4j.appender.logFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n

 

# Send logs to a specified e-mail

log4j.appender.mail=org.apache.log4j.net.SMTPAppender

log4j.appender.mail.Threshold=FATAL

log4j.appender.mail.BufferSize=10

log4j.appender.mail.From = [email protected]

log4j.appender.mail.SMTPHost=mail.com

log4j.appender.mail.Subject=Log4J Message

log4j.appender.mail.To= [email protected]

log4j.appender.mail.layout=org.apache.log4j.PatternLayout

log4j.appender.mail.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n

 

 

# Applied to the database

log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender

log4j.appender.database.URL=jdbc:mysql://localhost:3306/test

log4j.appender.database.driver=com.mysql.jdbc.Driver

log4j.appender.database.user=root

log4j.appender.database.password=

log4j.appender.database.sql=INSERT INTO LOG4J (Message) VALUES('=[%-5p] %d(%r) --> [%t] %l: %m %x %n')

log4j.appender.database.layout=org.apache.log4j.PatternLayout

log4j.appender.database.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n

 

Four, Log4j Weblogic cluster log split configuration (weblogic log splitting)

log4j.rootLogger = INFO, console, daily 

# Output to the control station
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = [${weblogic.Name}] %-d{yyyy-MM-dd HH:mm:ss} [%p][%l] %n%m%n%n

# Generate a file every day
log4j.appender.daily = org.apache.log4j.DailyRollingFileAppender
log4j.appender.daily.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.daily.File = D:/logs/pro_name/${weblogic.Name}/pro_name-${weblogic.Name}.log
log4j.appender.daily.layout = org.apache.log4j.PatternLayout
log4j.appender.daily.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%p][%l] %n%m%n%n

And the general configuration of a cluster configuration is somewhat different.

Mainly in the path of the output file with the server name of the variable: $ {weblogic.Name} . why?

Because in a cluster, when the log file is jointly occupy multiple application servers, not by date, size separated out: When an application server to be divided, a common log file is locked by other application servers, resulting in segmentation fails.

So you need to log file name with the variable name of the server, so that each application server has its own independent log files. So as not to cause too much log (such as 500M, 1G or more size) and open. At the same time the log file is too large, it can also cause problems logging output affect system performance.

 

================================

© Copyright sweet potatoes Yao 2020-01-06

https://www.cnblogs.com/fanshuyao/

Guess you like

Origin www.cnblogs.com/fanshuyao/p/12156813.html