Metadata-Version: 2.1
Name: tlssysloghandler
Version: 1.0.2
Summary: SysLogHandler with TLS
Author-email: A Tammy <atammy@bsd.ac>, Craig Weber <crgwbr@gmail.com>
License: Copyright (c) 2023, A Tammy <atammy@bsd.ac>
        Copyright (c) 2016, Craig Weber <crgwbr@gmail.com>
        
        Permission to use, copy, modify, and/or distribute this software for any
        purpose with or without fee is hereby granted, provided that the above
        copyright notice and this permission notice appear in all copies.
        
        THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        
Keywords: handler,logging,logger,syslog,tls
Classifier: Programming Language :: Python
Requires-Python: >=3.11
Description-Content-Type: text/x-rst
License-File: LICENSE

======================
SysLogHandler with TLS
======================

Python logging.handler as a drop-in replacement for logging.SysLogHandler with support for sending syslog messages over TCP with TLS.

Installation
------------

.. code:: bash

    pip install tlssysloghandler


Usage
-----

.. code:: python

    import logging
    from tlssysloghandler import TLSSysLogHandler

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # with default system certificate store
    handler1 = TLSSysLogHandler(address=('secure-logging.example.com', 6514),
                                socktype=socket.SOCK_STREAM,
                                secure=True)
    logger.addHandler(handler1)

    # with custom certificates, via cafile/capath/cadata
    # refer to https://docs.python.org/3/library/ssl.html#ssl.create_default_context
    handler2 = TLSSysLogHandler(address=('secure-logging.example.com', 6514), 
                                socktype=socket.SOCK_STREAM,
                                secure={cafile='/path/to/ca/file'})
    logger.addHandler(handler2)

    # with custom SSLContext
    context = ssl.create_default_context(cafile='/path/to/ca/file')
    handler3 = TLSSysLogHandler(address=('secure-logging.example.com', 6514), 
                                socktype=socket.SOCK_STREAM,
                                secure=context)
    logger.addHandler(handler3)

    # or allow TLS without verification
    handler4 = TLSSysLogHandler(address=('secure-logging.example.com', 6514), 
                                socktype=socket.SOCK_STREAM,
                                secure="noverify")
    logger.addHandler(handler4)

    logger.info('Hello World!')
