How to customize log format with rsyslog

This document (000019760) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 12 SP5
SUSE Linux Enterprise Server 12 SP4
SUSE Linux Enterprise Server 12 SP3
SUSE Linux Enterprise Server 12 SP2

Situation

How to customize log format with rsyslog

Resolution

1. create a new file /etc/rsyslog.d/log.conf 
#  $template <template name>, <template pattern>

# (e.g.)

$template logpattern,"%syslogpriority-text% %syslogfacility-text% %timegenerated% %HOSTNAME% %syslogtag%,%msg%\n"

# "%xxx%" is the term called the property replacer. 

The property replacers used by the above template have the following meanings:
#  %syslogpriority-text% : syslog priority
#  %syslogfacilityt-text% : syslog facility
#  %timegenerated% : timestamp when the message was received
#  %HOSTNAME% : hostname
#  %syslogtag% : tag
#  %msg% : the message sent to syslog

#  The complete documentation can be found in the doc folder of the rsyslog distribution or online at
     http://www.rsyslog.com/doc

2.Bind a custom template to logs

If binding it to all the logs as default:
#  $ActionFileDefaultTemplate <your template name>

#  (e.g.)

$ActionFileDefaultTemplate logpattern

#  If binding it only to a specific log pattern:

#  <filter pattern>                   <action>;<your temlapte name>

(e.g.)
*.*                                /var/log/messages;logpattern

3.Restart rsyslog service
systemctl restart rsyslog.service

Cause

There is a requirement to change the log output details.

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:000019760
  • Creation Date: 27-Oct-2020
  • Modified Date:28-Oct-2020
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center