Skip to main content
errata fixes
Source Link
boardrider
  • 6.3k
  • 7
  • 59
  • 92

Piecing things together from here and other places, this is what I came up with that works on unbuntuubuntu 12.04 and centOS6

Create ana file in /etc/rsyslog.d/ that ends in .conf and add the following text

local6.* /var/log/my-logfile 

Restart rsyslog, reloading did NOT seem to work for the new log files. Maybe it only reloads existing conf files?

sudo restart rsyslog 

Then you can use this test program to make sure it actually works.

import logging, sys from logging import config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s %(module)s P%(process)d T%(thread)d %(message)s' }, }, 'handlers': { 'stdout': { 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'verbose', }, 'sys-logger6': { 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': "local6", 'formatter': 'verbose', }, }, 'loggers': { 'my-logger': { 'handlers': ['sys-logger6','stdout'], 'level': logging.DEBUG, 'propagate': True, }, } } config.dictConfig(LOGGING) logger = logging.getLogger("my-logger") logger.debug("Debug") logger.info("Info") logger.warn("Warn") logger.error("Error") logger.critical("Critical") 

Piecing things together from here and other places, this is what I came up with that works on unbuntu 12.04 and centOS6

Create an file in /etc/rsyslog.d/ that ends in .conf and add the following text

local6.* /var/log/my-logfile 

Restart rsyslog, reloading did NOT seem to work for the new log files. Maybe it only reloads existing conf files?

sudo restart rsyslog 

Then you can use this test program to make sure it actually works.

import logging, sys from logging import config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s %(module)s P%(process)d T%(thread)d %(message)s' }, }, 'handlers': { 'stdout': { 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'verbose', }, 'sys-logger6': { 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': "local6", 'formatter': 'verbose', }, }, 'loggers': { 'my-logger': { 'handlers': ['sys-logger6','stdout'], 'level': logging.DEBUG, 'propagate': True, }, } } config.dictConfig(LOGGING) logger = logging.getLogger("my-logger") logger.debug("Debug") logger.info("Info") logger.warn("Warn") logger.error("Error") logger.critical("Critical") 

Piecing things together from here and other places, this is what I came up with that works on ubuntu 12.04 and centOS6

Create a file in /etc/rsyslog.d/ that ends in .conf and add the following text

local6.* /var/log/my-logfile 

Restart rsyslog, reloading did NOT seem to work for the new log files. Maybe it only reloads existing conf files?

sudo restart rsyslog 

Then you can use this test program to make sure it actually works.

import logging, sys from logging import config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s %(module)s P%(process)d T%(thread)d %(message)s' }, }, 'handlers': { 'stdout': { 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'verbose', }, 'sys-logger6': { 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': "local6", 'formatter': 'verbose', }, }, 'loggers': { 'my-logger': { 'handlers': ['sys-logger6','stdout'], 'level': logging.DEBUG, 'propagate': True, }, } } config.dictConfig(LOGGING) logger = logging.getLogger("my-logger") logger.debug("Debug") logger.info("Info") logger.warn("Warn") logger.error("Error") logger.critical("Critical") 
Source Link
boatcoder
  • 18.2k
  • 21
  • 126
  • 188

Piecing things together from here and other places, this is what I came up with that works on unbuntu 12.04 and centOS6

Create an file in /etc/rsyslog.d/ that ends in .conf and add the following text

local6.* /var/log/my-logfile 

Restart rsyslog, reloading did NOT seem to work for the new log files. Maybe it only reloads existing conf files?

sudo restart rsyslog 

Then you can use this test program to make sure it actually works.

import logging, sys from logging import config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s %(module)s P%(process)d T%(thread)d %(message)s' }, }, 'handlers': { 'stdout': { 'class': 'logging.StreamHandler', 'stream': sys.stdout, 'formatter': 'verbose', }, 'sys-logger6': { 'class': 'logging.handlers.SysLogHandler', 'address': '/dev/log', 'facility': "local6", 'formatter': 'verbose', }, }, 'loggers': { 'my-logger': { 'handlers': ['sys-logger6','stdout'], 'level': logging.DEBUG, 'propagate': True, }, } } config.dictConfig(LOGGING) logger = logging.getLogger("my-logger") logger.debug("Debug") logger.info("Info") logger.warn("Warn") logger.error("Error") logger.critical("Critical")