summaryrefslogtreecommitdiff
path: root/doc/book/src/java-broker/Configure-Log4j-CompositeRolling-Appender.xml
blob: f52bc55399f0f4f055ba8bcceb4f66676752d8c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?xml version="1.0" encoding="utf-8"?>

<!--
 
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 
-->

<section id="Qpid-Java-Log4j"><title>
      Configure Log4j CompositeRolling Appender
    </title>
    <section role="h2" id="ConfigureLog4jCompositeRollingAppender-HowtoconfiguretheCompositeRollinglog4jAppender"><title>
            How to configure the CompositeRolling log4j Appender
          </title>
	  <para>
            There are several sections of our default log4j file that will
            need your attention if you wish to fully use this Appender.
          </para>

	  <orderedlist>
	    <listitem>
	  <para>Enable the Appender</para>
	  <para>
            The default log4j.xml file uses the FileAppender, swap this for
            the ArchivingFileAppender as follows:
          </para>
            <programlisting>
    &lt;!-- Log all info events to file --&gt;
    &lt;root&gt;
        &lt;priority value="info"/&gt;

        &lt;appender-ref ref="ArchivingFileAppender"/&gt;
    &lt;/root&gt;
</programlisting>
	    </listitem>
	    <listitem>
          <para>
            Configure the Appender
          </para>

	  <para>
            The Appender has a number of parameters that can be adjusted
            depending on what you are trying to achieve. For clarity lets
            take a quick look at the complete default appender:
          </para>
            <programlisting>
  &lt;appender name="ArchivingFileAppender" class="org.apache.log4j.QpidCompositeRollingAppender"&gt;
        &lt;!-- Ensure that logs allways have the dateFormat set--&gt;
        &lt;param name="StaticLogFileName" value="false"/&gt;
        &lt;param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/&gt;
        &lt;param name="Append" value="false"/&gt;
        &lt;!-- Change the direction so newer files have bigger numbers --&gt;
        &lt;!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover --&gt;
        &lt;param name="CountDirection" value="1"/&gt;
        &lt;!-- Use default 10MB --&gt;
        &lt;!--param name="MaxFileSize" value="100000"/--&gt;
        &lt;param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/&gt;
        &lt;!-- Unlimited number of backups --&gt;
        &lt;param name="MaxSizeRollBackups" value="-1"/&gt;
        &lt;!-- Compress(gzip) the backup files--&gt;
        &lt;param name="CompressBackupFiles" value="true"/&gt;
        &lt;!-- Compress the backup files using a second thread --&gt;
        &lt;param name="CompressAsync" value="true"/&gt;
        &lt;!-- Start at zero numbered files--&gt;
        &lt;param name="ZeroBased" value="true"/&gt;
        &lt;!-- Backup Location --&gt;
        &lt;param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/&gt;

        &lt;layout class="org.apache.log4j.PatternLayout"&gt;
            &lt;param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/&gt;
        &lt;/layout&gt;
    &lt;/appender&gt;
</programlisting>
          <para>
            The appender configuration has three groups of parameter
            configuration.
          </para><para>
            The first group is for configuration of the file name. The
            default is to write a log file to QPID_WORK/log/qpid.log
            (Remembering you can use the logprefix and logsuffix values to
            modify the file name, see Property Config).
          </para>
            <programlisting>
        &lt;!-- Ensure that logs always have the dateFormat set--&gt;
        &lt;param name="StaticLogFileName" value="false"/&gt;
        &lt;param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/&gt;
        &lt;param name="Append" value="false"/&gt;
</programlisting>
          <para>
            The second section allows the specification of a Maximum File
            Size and a DatePattern that will be used to move on to the next
            file.
          </para><para>
            When MaxFileSize is reached a new log file will be created
            The DataPattern is used to decide when to create a new log file,
            so here a new file will be created for every minute and every
            10Meg of data. So if 15MB of data is made every minute then there
            will be two log files created each minute. One at the start of
            the minute and a second when the file hit 10MB. When the next
            minute arrives a new file will be made even though it only has
            5MB of content. For a production system it would be expected to
            be changed to something like 'yyyy-MM-dd' which would make a new
            log file each day and keep the files to a max of 10MB.
          </para><para>
            The final MaxSizeRollBackups allows you to limit the amount of
            disk you are using by only keeping the last n backups.
          </para>
            <programlisting>
        &lt;!-- Change the direction so newer files have bigger numbers --&gt;
        &lt;!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover --&gt;
        &lt;param name="CountDirection" value="1"/&gt;
        &lt;!-- Use default 10MB --&gt;
        &lt;!--param name="MaxFileSize" value="100000"/--&gt;
        &lt;param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/&gt;
        &lt;!-- Unlimited number of backups --&gt;
        &lt;param name="MaxSizeRollBackups" value="-1"/&gt;
</programlisting>
          <para>
            The final section allows the old log files to be compressed and
            copied to a new location.
          </para>
            <programlisting>
        &lt;!-- Compress(gzip) the backup files--&gt;
        &lt;param name="CompressBackupFiles" value="true"/&gt;
        &lt;!-- Compress the backup files using a second thread --&gt;
        &lt;param name="CompressAsync" value="true"/&gt;
        &lt;!-- Start at zero numbered files--&gt;
        &lt;param name="ZeroBased" value="true"/&gt;
        &lt;!-- Backup Location --&gt;
        &lt;param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/&gt;
</programlisting>
</listitem>
</orderedlist>
<!--h2--></section>
</section>