A Logging Formatter for Python's logging module to properly handle Syslog RFC5424 messages
Project description
python-rfc5424-logging-formatter
================================
A Logging Formatter for Python's logging module to properly handle Syslog RFC5424 messages
What is provided by this formatter
----------------------------------
A derived formatter than allows for isotime specification
for full RFC5424 compliancy (with corrected TZ format)
For a "proper" ISOTIME format, use "%(isotime)s" in a
formatter instance of this class or a class derived from
this class. This is for a work-around where strftime
has no mechanism to produce timezone in the format of
"-08:00" as required by RFC5424.
The '%(isotime)s' replacement will read in the record
timestamp and try and reparse it. This really is a
problem with RFC5424 and strftime. I am unsure if this
will be fixed in the future (in one or the other case)
This formatter has an added benefit of allowing for
'%(hostname)s' to be specified which will return a '-'
as specified in RFC5424 if socket.gethostname() returns
bad data (exception).
RFC5424 Format
--------------
RFC: http://tools.ietf.org/html/rfc5424
__The RFC5424 Format should only be used when talking to a Syslog server
over the network stack. Specifically the Linux KSyslog implementation
still uses RFC3164 format (and something akin to RSyslog still adheres
to that)__
The RFC5424 format string should look somthing like:
```
%(isotime)s %(hostname)s %(name)s %(process)d - - %(message)s
```
The section after the two "- -" is technically the message
section, and can have any data applied to it e.g.:
```
<...> %(levelname)s [%(module)s %(funcName)s] %(message)s
```
The '- -' section is the "msg ID" and "Structured-Data" Elements,
respectively
Example usage of the formatter
-------------------------------
```python
import logging
logger = logging.getLogger('rfc5424_example')
handler = logging.handlers.SysLogHandler(address=<Address of SysLogServer>)
format = '%(isotime)s %(hostname)s %(name)s %(process)d - - %(message)s'
formatter = RFC5424Syslog(format)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.info('RFC5424 Log Message Format in use')
```
License
-------
Copyright (C) 2013 Morgan Fainberg and Metacloud, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
================================
A Logging Formatter for Python's logging module to properly handle Syslog RFC5424 messages
What is provided by this formatter
----------------------------------
A derived formatter than allows for isotime specification
for full RFC5424 compliancy (with corrected TZ format)
For a "proper" ISOTIME format, use "%(isotime)s" in a
formatter instance of this class or a class derived from
this class. This is for a work-around where strftime
has no mechanism to produce timezone in the format of
"-08:00" as required by RFC5424.
The '%(isotime)s' replacement will read in the record
timestamp and try and reparse it. This really is a
problem with RFC5424 and strftime. I am unsure if this
will be fixed in the future (in one or the other case)
This formatter has an added benefit of allowing for
'%(hostname)s' to be specified which will return a '-'
as specified in RFC5424 if socket.gethostname() returns
bad data (exception).
RFC5424 Format
--------------
RFC: http://tools.ietf.org/html/rfc5424
__The RFC5424 Format should only be used when talking to a Syslog server
over the network stack. Specifically the Linux KSyslog implementation
still uses RFC3164 format (and something akin to RSyslog still adheres
to that)__
The RFC5424 format string should look somthing like:
```
%(isotime)s %(hostname)s %(name)s %(process)d - - %(message)s
```
The section after the two "- -" is technically the message
section, and can have any data applied to it e.g.:
```
<...> %(levelname)s [%(module)s %(funcName)s] %(message)s
```
The '- -' section is the "msg ID" and "Structured-Data" Elements,
respectively
Example usage of the formatter
-------------------------------
```python
import logging
logger = logging.getLogger('rfc5424_example')
handler = logging.handlers.SysLogHandler(address=<Address of SysLogServer>)
format = '%(isotime)s %(hostname)s %(name)s %(process)d - - %(message)s'
formatter = RFC5424Syslog(format)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.info('RFC5424 Log Message Format in use')
```
License
-------
Copyright (C) 2013 Morgan Fainberg and Metacloud, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rfc5424syslog-0.0.1.tar.gz
(3.1 kB
view details)
File details
Details for the file rfc5424syslog-0.0.1.tar.gz
.
File metadata
- Download URL: rfc5424syslog-0.0.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ee2f87d44fa92f81cf9d3c9e8ea0571e9469e4589a6da5f55271f916ef786ed |
|
MD5 | c54fc672277c445e115d45fb58e52925 |
|
BLAKE2b-256 | ff91530aeba0b5389a3cde2771111f53d3b37728e99522be0d3012457032c3d6 |