В приложении apache / wsgi я пытаюсь записать, что мое приложение делает для удаленного rsyslog deamon. Но я не знаю почему, журналы, которые я должен был записать, записываются несколько раз в мой файл журнала. Когда я вызываю тестовую ссылку, у меня появляется одна новая строка журнала, во второй раз у меня две новые строки (над первой) и т. Д. Я понятия не имею, почему, и понятия не имею. Знал бы, что может вызвать такое поведение?
Спасибо
import logging, socket, os, json, requests, sys
from logging.handlers import SysLogHandler
def application(environ, start_response):
status = '200 OK'
html_output = 'App test\n'
logger = logging.getLogger('test app')
logger.setLevel(logging.INFO)
handler = logging.handlers.SysLogHandler('/dev/log')
formatter = logging.Formatter('Python: { "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.formatter = formatter
logger.addHandler(handler)
logger.info('need to sync true')
response_headers = [('Content-type', 'text/html'), ('Content-Length', str(len(html_output)))]
start_response(status, response_headers)
return [bytes(html_output, 'utf-8')]
Вот несколько строк журнала из / var / log / messages, где вы можете видеть одни и те же строки несколько раз:
Mar 27 14:42:53 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:53,687", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316573.687927", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"687", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:53 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:53,687", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316573.687927", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"687", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:56 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:56,194", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316576.194655", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"194", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:56 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:56,194", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316576.194655", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"194", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:56 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:56,194", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316576.194655", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"194", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:57 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:57,700", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316577.700038", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"700", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:57 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:57,700", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316577.700038", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"700", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:57 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:57,700", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316577.700038", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"700", "levelName":"INFO", "message":"need to sync true"}
Mar 27 14:42:57 db-test Python[20249]: { "loggerName":"test app", "timestamp":"2020-03-27 13:42:57,700", "pathName":"/home/prebid-server/serverside-mediasquare/python/test.wsgi", "logRecordCreationTime":"1585316577.700038", "functionName":"application", "levelNo":"20", "lineNo":"18", "time":"700", "levelName":"INFO", "message":"need to sync true"}