Created
November 16, 2020 09:06
-
-
Save huseyinyilmaz/7e0949191825c1caf53e428ef0303030 to your computer and use it in GitHub Desktop.
this file creates a sample log messages and sends them to /dev/log. I use this to test syslog config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import logging.handlers | |
import time | |
my_logger = logging.getLogger('testlogger') | |
my_logger.setLevel(logging.DEBUG) | |
#add formatter to the handler | |
formatter = logging.Formatter( | |
'SAMPLE_CORE_KAMUSTA: { "loggerName":"%(name)s", "timestamp":"%(asctime)s", "pathName":"%(pathname)s", ' | |
'"logRecordCreationTime":"%(created)f", "functionName":"%(funcName)s", "levelNo":"%(levelno)s", ' | |
'"lineNo":"%(lineno)d", "time":"%(msecs)d", "levelName":"%(levelname)s", "message":"%(message)s"}') | |
handler = logging.handlers.SysLogHandler(address = '/dev/log') | |
handler.formatter = formatter | |
my_logger.addHandler(handler) | |
while True: | |
time.sleep(1) | |
my_logger.debug('sample-log-script [sample][debug] this is debug') | |
my_logger.info('sample-log-script [sample][info] this is info') | |
my_logger.warn('sample-log-script [sample][warn] this is warn') | |
my_logger.error('sample-log-script [sample][error] this is error') | |
my_logger.critical('sample-log-script [sample][critical] this is error') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment