Python rfc5424 syslog logging handler
.. image:: https://readthedocs.org/projects/rfc5424-logging-handler/badge/?version=latest
:target: https://rfc5424-logging-handler.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/pypi/v/rfc5424-logging-handler.svg
:target: https://pypi.python.org/pypi/rfc5424-logging-handler
.. image:: https://img.shields.io/pypi/pyversions/rfc5424-logging-handler.svg
:target: https://pypi.python.org/pypi/rfc5424-logging-handler#downloads
.. image:: https://travis-ci.org/jobec/rfc5424-logging-handler.svg?branch=master
:target: https://travis-ci.org/jobec/rfc5424-logging-handler
.. image:: https://codecov.io/github/jobec/rfc5424-logging-handler/coverage.svg?branch=master
:target: https://codecov.io/github/jobec/rfc5424-logging-handler?branch=master
An up-to-date, RFC 5424 <https://tools.ietf.org/html/rfc5424>
_ compliant syslog handler for the Python logging framework.
Features
RFC 5424 <https://tools.ietf.org/html/rfc5424>
_ Compliant.
- Python Logging adapter for easier sending of rfc5424 specific fields.
- No need for complicated formatting strings.
- TLS/SSL syslog support.
- Alternate transports like streams (ex. stderr, stdout, file, ...).
Installation
Python package::
pip install rfc5424-logging-handler
Usage
After installing you can use this package like this:
.. code-block:: python
import logging
from rfc5424logging import Rfc5424SysLogHandler
logger = logging.getLogger('syslogtest')
logger.setLevel(logging.INFO)
sh = Rfc5424SysLogHandler(address=('10.0.0.1', 514))
logger.addHandler(sh)
logger.info('This is an interesting message', extra={'msgid': 'some_unique_msgid'})
This will send the following message to the syslog server::
<14>1 2020-01-01T05:10:20.841485+01:00 myserver syslogtest 5252 some_unique_msgid - \xef\xbb\xbfThis is an interesting message
Note the UTF8 Byte order mark (BOM) preceding the message. While required by
RFC 5424 section 6.4 <https://tools.ietf.org/html/rfc5424#section-6.4>
_ if the message is known to be UTF-8 encoded,
there are still syslog receivers that cannot handle it. To bypass this limitation, when initializing the handler Class,
set the msg_as_utf8
parameter to False
like this:
.. code-block:: python
sh = Rfc5424SysLogHandler(address=('10.0.0.1', 514), msg_as_utf8=False)
For more examples, have a look at the documentation <http://rfc5424-logging-handler.readthedocs.org/>
_
Changelog
1.4.3
_ - 2019/05/19
**Changed**
* `#34`_ Allow enterprise ID to contain sub-identifiers.
**Fixed**
* `#31`_ Correct handling of failed connection attempt in TCP transport handler.
`1.4.2`_ - 2019/04/08
Changed
#32
_ address
can now also be a list, making loading settings form a config file possible.
Added
- Python 3.7 tests and support.
1.4.1
_ - 2019/02/16
**Fixed**
* `#29`_ Fix AttributeError when using TLS connection.
`1.4.0`_ - 2019/01/30
Added
#27
_ Make it possible to log to streams as an alternate transport.
- Added API documentation.
Changed
- Syslog facilities and framing options have moved from the
RfcSysLogHandler
class
to module level variables. You may have to adjust your references to them.
1.3.0
_ - 2018/10/19
**Added**
* `#23`_ Add support for TLS/SSL
`1.2.1`_ - 2018/09/21
Fixed
#21
_ Registered structured data IDs where also suffixed with an enterprise ID.
Added
#22
_ Add utc_timestamp
parameter to allow logging in UTC time.
1.1.2
_ - 2018/02/03
**Fixed**
* `#15`_ When logging to ``/dev/log`` with python 2.7, the connection was permanently lost when the local syslog server
was restarted.
* `#16`_ The ``extra`` info of a message did not overwrite that of the logging adapter instance.
`1.1.1`_ - 2017/12/08
Fixed
#14
_ Fixed handling of extra
parameter in logging adapter.
1.1.0
_ - 2017/11/24
**Added**
* The ``msg`` parameter for the logger handler can now be absent allowing "structured data only" messages.
**Fixed**
* Correct the automatic value of the ``hostname`` when the value is anything other then ``NILVALUE``
* The syslog message is now empty in conformance with RFC5424 when it's value is ``None`` or an empty string.
`1.0.3`_ - 2017/10/08
No functional changes. Only documentation was changed.
Added
- Logstash configuration example for RFC5424.
Changed
- Moved most of the documentation out of the readme file.
1.0.2
_ - 2017/08/31
**Fixed**
* Package description rendering on PyPi due to bug `pypa/wheel#189 <https://github.com/pypa/wheel/issues/189>`_
`1.0.1`_ - 2017/08/30
Added
#12
: It's now possible to send syslog messages as MSG-ANY <https://tools.ietf.org/html/rfc5424#section-6>
which suppresses the UTF-8 byte order mark (BOM) when sending messages.
1.0.0
_ - 2017/05/30
**Changed**
* `#10`_: Procid, appname and hostname can now be set per message, both with the handler as well as with the adapter
.. note::
This release has a slight change in behaviour. Setting one of the appnama, hostname of procid message to None or an
empty string will cause it to be filled in automatically. Previously, setting it to an empty string caused it to
be set to NILVALUE (a - ). You now need to set it explicilty to NILVALUE if you want to omit it from the message.
`0.2.0`_ - 2017/01/27
Fixed
- Better input handling
- Better sanitizing of invalid input
0.1.0
_ - 2017/01/22
**Added**
* `#4`_: Adapter class to make it easier to log message IDs or structured data
* Logging of EMERGENCY, ALERT and NOTICE syslog levels by using the adapter class
* Extensive test suite
`0.0.2`_ - 2017/01/18
Added
#5
_ Introduced Python 2.7 compatibility
0.0.1 - 2017/01/11
* Initial release
.. _1.4.3: https://github.com/jobec/rfc5424-logging-handler/compare/1.4.2...1.4.3
.. _1.4.2: https://github.com/jobec/rfc5424-logging-handler/compare/1.4.1...1.4.2
.. _1.4.1: https://github.com/jobec/rfc5424-logging-handler/compare/1.4.0...1.4.1
.. _1.4.0: https://github.com/jobec/rfc5424-logging-handler/compare/1.3.0...1.4.0
.. _1.3.0: https://github.com/jobec/rfc5424-logging-handler/compare/1.2.1...1.3.0
.. _1.2.1: https://github.com/jobec/rfc5424-logging-handler/compare/1.1.2...1.2.1
.. _1.1.2: https://github.com/jobec/rfc5424-logging-handler/compare/1.1.1...1.1.2
.. _1.1.1: https://github.com/jobec/rfc5424-logging-handler/compare/1.1.0...1.1.1
.. _1.1.0: https://github.com/jobec/rfc5424-logging-handler/compare/1.0.3...1.1.0
.. _1.0.3: https://github.com/jobec/rfc5424-logging-handler/compare/1.0.2...1.0.3
.. _1.0.2: https://github.com/jobec/rfc5424-logging-handler/compare/1.0.1...1.0.2
.. _1.0.1: https://github.com/jobec/rfc5424-logging-handler/compare/1.0.0...1.0.1
.. _1.0.0: https://github.com/jobec/rfc5424-logging-handler/compare/0.2.0...1.0.0
.. _0.2.0: https://github.com/jobec/rfc5424-logging-handler/compare/0.1.0...0.2.0
.. _0.1.0: https://github.com/jobec/rfc5424-logging-handler/compare/0.0.2...0.1.0
.. _0.0.2: https://github.com/jobec/rfc5424-logging-handler/compare/0.0.1...0.0.2
.. _#34: https://github.com/jobec/rfc5424-logging-handler/issues/34
.. _#32: https://github.com/jobec/rfc5424-logging-handler/issues/32
.. _#31: https://github.com/jobec/rfc5424-logging-handler/issues/31
.. _#29: https://github.com/jobec/rfc5424-logging-handler/issues/29
.. _#27: https://github.com/jobec/rfc5424-logging-handler/issues/27
.. _#23: https://github.com/jobec/rfc5424-logging-handler/issues/23
.. _#22: https://github.com/jobec/rfc5424-logging-handler/issues/22
.. _#21: https://github.com/jobec/rfc5424-logging-handler/issues/21
.. _#16: https://github.com/jobec/rfc5424-logging-handler/pull/16
.. _#15: https://github.com/jobec/rfc5424-logging-handler/issues/15
.. _#14: https://github.com/jobec/rfc5424-logging-handler/pull/14
.. _#12: https://github.com/jobec/rfc5424-logging-handler/pull/12
.. _#10: https://github.com/jobec/rfc5424-logging-handler/pull/10
.. _#5: https://github.com/jobec/rfc5424-logging-handler/issues/5
.. _#4: https://github.com/jobec/rfc5424-logging-handler/pull/4