0

I have problem sending loggging stream over udp to targeted third part machine that collects log streams.

I've got just couple of lines of init to appear on remote console. The encoding over the udp should be UTF-8, too.

## setup_loggin function body
handler=logging.StreamHandler()
handler.setFormatter(formatter)
socketHandler=logging.handlers.SysLogHandler(address(SYSLOG_IP, 514))
socketHandler.setFormatter(formatter)
logger = logging.getLogger(name)
if not logger.handlers:
    logger.setLevel(log_level)
    logger.addHandler(handler)
    logger.addHandler(socketHandler)
return logger

The remote server gets just begining of the logging at end results. Probably because it expects UDP to receive "UTF-8", and than parses it through.

Is there a way to change logging encoding to "UTF-8" using SysLogHandler or any other loggin handler.?

NotTooTechy
  • 448
  • 5
  • 9
  • how big are the messages you're logging? AFAICT messages tend to get [truncated at 1k](https://stackoverflow.com/a/41822232/1358308) – Sam Mason Oct 25 '19 at 16:52
  • The size of the data is not an issue. I can see on third party server that it complains when it parses through incoming messages that expects "UTF-8". I added rsyslogd to the client and it works fine now. Not really solution I prefer but it workds. – NotTooTechy Oct 25 '19 at 21:32
  • `SysLogHandler` should be sending utf8 encoded messages, see e.g. https://github.com/python/cpython/blob/3.8/Lib/logging/handlers.py#L910 – Sam Mason Oct 25 '19 at 21:39

1 Answers1

0

Problem solved. Third party syslog was parsing based on RFC3164

The MSG part has two fields known as the TAG field and the CONTENT field. So, formatter would be something like

formatter_syslog = logging.Formatter(fmt='foo: %(levelname)s - %(module)s.%(funcName)s - %(message)s')
Community
  • 1
  • 1
NotTooTechy
  • 448
  • 5
  • 9