JBoss log file configuration
1 . Size based rolling configuration
By changing the log handler to size-rotating-file-handler and defining the log file size(rotate-size) and the number of files(max-backup-index), the size of the log file is fixed and always rotates within the given number of files.
For e.g.: If we set rotation size to 5 MB and max-backup-index to 10 then it will create 10 files of size 5MB each and after writing 10 files it will start overwriting the earlier created files.
Size rotating Configuration
Step 1:
Search <size-rotating-file-handler> tag in jboss-logging.xml file and uncomment this tag.
Below is the actual screenshot of the tag in jboss-logging.xml
Edited tag
<size-rotating-file-handler
file-name="${jboss.server.log.dir}/server.log"
name="FILE"
autoflush="false"
append="true"
rotate-size="500k"
max-backup-index="10">
<error-manager>
<only-once/>
</error-manager>
<formatter>
<pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>
</formatter>
</size-rotating-file-handler>
Change the attributes of the tag like below
1. rotate-size : Rotates the log file in the given size.
E.g. - rotate-size="500k" will rotate the file in 500 kb
- rotate-size="200m" will rotate the file in 200 MB
2. max-backup-index : maximum number of log files created.
In the above example, only 10 files will be created and logs will get rotated in those 10 files.
3. file-name: Path of the file
Can mention absolute path in this attribute of the local system or the remote system but the remote systems folder must be shared.
Step 2:
Search <periodic-rotating-file-handler> tag and comment it.
Step 3:
Save the file.
The above configuration will create the log files as shown in the below screenshot.
2. Time/Date based rolling configuration (Default)
This is the default logging handler when the running system reaches a pre-defined time (that is, hour change, day change, and so on), the log file rolls, backing up itself and creating a new file with the same characteristics.
For e.g., If we set for hourly suffix then it will create a new file every hour.
Time rotating configuration for creating log file hourly basis.
Step 1:
Search for <periodic-rotating-file-handler> tag in jboss-logging.xml file.
Update “suffix” attribute value from “.yyyy-MM-dd” to “.yyyy-MM-dd-HH” and save the file.
This will create a new log file every hour.
Below is the actual screenshot of the tag from jboss-logging.xml
Edited Sample:
<periodic-rotating-file-handler
file-name="${jboss.server.log.dir}/server.log"
name="FILE"
autoflush="true"
append="true"
suffix=".yyyy-MM-dd-HH">
<error-manager>
<only-once/>
</error-manager>
<formatter>
<pattern-formatter pattern="%d %-5p [%c] (%t:%x) %m%n"/>
</formatter>
</periodic-rotating-file-handler>
Change the attributes of the tag like below
1. file-name: Path of the file
Can mention absolute path in this attribute of the local system or the remote system but the remote systems folder must be shared.
2. Suffix: update to “.yyyy-MM-dd-HH”, this will create hourly-based files.
3.append: When the append property is set to "true", all messages written by this handler will be appended to an existing file. If set to "false" a new file will be created each time the application server launches. Changes to append require a server reboot to take effect. Note: this will overwrite the previously created file in that particular hour. False will create a new file.
Step 2:
Save the file.
Below is the screenshot which shows hourly logs captured
Note:
1. Only one configuration can be done at a time. (Either time or size in JBoss AS 6).
2. Size-based rolling will create given no. of files (in max-backup-index) and rotate within the same i.e. There is a loss of data as it will create given no. of files only.
3. Time-based rolling can be done on an hourly basis(So every hour new file will be created. No loss of data).
4. If you want to store the logs on a shared drive, In the configuration file you can set mapped drive or UNC path. Can set the absolute path of the folder in the “file-name” attribute of the handler tag as given below. Also, ensure for each node there should be a separate shared folder.
Comments
Post a Comment