Log4j Appender File File For Mac



  1. Log4j Appender File File For Mac Os
  2. Log4j Appender File File For Mac Download

File=tm1event.log log4j.appender.S2.Format=TM1Event: Format. Specifies the format of the logs. For example: log4j.appender.S2.Format=TM1Event. Where the format is TM1Event or TM1Top. For example, to dynamically monitor the threads that are running and outputs thread status to the tm1top.log. In the example, the FileAppender appends log events to the log file named crawl.log (which is created in the current working directory). The ConsoleAppender writes to the console using a simple pattern in which only the messages are printed, but not the more verbose information (logging level, timestamp, and so on).

Log4j provides org.apache.log4j.PattrernLayout class to generate your logging information in a particular format based on a pattern.

The PatternLayout extends the abstract org.apache.log4j.Layout class and overrides the format() method to structure the logging information according to a supplied pattern.

PatternLayout is also a simple layout object that provides the Bean Property i.e. conversionPattern, which can be set using the configuration file:

conversionPattern: This property is used to set the conversion pattern. Default is %r [%t] %p %c %x - %m%n

For

Pattern Conversion Characters

Let's see the following table describes the characters used in the conversion pattern and all other characters that we can use in our custom pattern:

Conversion CharacterMeaning
cIt is used to output the category of the logging event. For Example: for the category name x.y.z the pattern %c{2} will output y.z.
CIt is used to output the fully qualified class name of the caller issuing the logging request. For example, for the class name 'org.apache.abc.MyClass', the pattern %C{1} will output 'MyClass'.
dIt is used to output the date of the logging event. For example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}.
FIt is used to output the file name where the logging request was issued.
lIt is used to output location information of the caller which generated the logging event.
LIt is used to output the line number from where the logging request was issued.
mIt is used to output the application supplied message associated with the logging event.
MIt is used to output the method name where the logging request was issued.
nIt is used to give the output of platform-dependent line separator character or characters.
pOutputs the priority of the logging event.
rIt is used to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event.
tIt is used to output the name of the thread that generated the logging event.
xIt is used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.
XThe X conversion character is followed by the key for the MDC (Mapped Diagnostic Context). For example, X{clientIP} prints the information stored in the MDC against the key clientIP.
%The literal percent sign. %% will print a % sign.

Format Modifiers

By default, the relevant information is displayed as a normal output. However, log4j provides the format modifiers; with the help of this, it is possible to change the maximum field width, the minimum field width, and justification.

Let's see some modifiers:

Format modifierleft justifyminimum widthmaximum widthcomment
%20cfalse20noneLeft pad with spaces if the name of the category is less than 20 characters long.
%-20ctrue20noneRight pad with spaces if the name of the category is less than 20 characters long.
%.30cNAnone30Truncate from the beginning if the name of the category is longer than 30 characters.
%20.30cfalse2030Left pad with spaces if the name of the category is shorter than 20 characters. However, if the name of the category is longer than 30 characters, then truncate from the beginning.
%-20.30ctrue2030Right pad with spaces if the name of the category is shorter than 20 characters. However, if the category name is longer than 30 characters, then truncate from the beginning.

PatternLayout Example

Let's see one simple example for Patternlayout.

Following is a simple configuration file for PatternLayout:

File

log4j.properties:

Log4j Appender File File For Mac Os

Log4jExample.java:

When you compile and run the above program, you will get a log.out file in c:/usr/home/log4j directory which would have the following log information:

Output:

Next TopicLog4j - Appenders

Log4j Appender File File For Mac Download