You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need a set plain-text format with an ordered key sequence for my application. How I can properly change the default logging template or apply my own log-handler to asyncio.entrypoint?
Thanks!
The text was updated successfully, but these errors were encountered:
Sorry for the long answer, but I couldn't figure out how to do it right and not break anything. A good option would be the option shown in the example below:
importosimportloggingfromlogging.handlersimportRotatingFileHandlerfromgzipimportGzipFileimportaiomiscclassGzipLogFile(GzipFile):
defwrite(self, data) ->int:
ifisinstance(data, str):
data=data.encode()
returnsuper().write(data)
classRotatingGzipFileHandler(RotatingFileHandler):
defshouldRollover(self, record):
ifnotos.path.isfile(self.baseFilename):
returnFalseifself.streamisNone:
self.stream=self._open()
return0<self.maxBytes<os.stat(self.baseFilename).st_sizedef_open(self):
returnGzipLogFile(filename=self.baseFilename, mode=self.mode)
asyncdefmain():
for_inrange(1_000):
logging.info("Hello world")
withaiomisc.entrypoint(log_config=False) asloop:
# Your custom handlershandlers= [
logging.StreamHandler(),
RotatingGzipFileHandler(
"app.log.gz",
# 10 megabytesmaxBytes=10*2**20,
backupCount=100
),
]
logging.basicConfig(
level=logging.INFO,
# Wrapping all handlers in separate streams will not block the # event-loop even if gzip takes a long time to open the # file.handlers=map(aiomisc.log.wrap_logging_handler, handlers)
)
loop.run_until_complete(main())
Hi, everyone!
I need a set plain-text format with an ordered key sequence for my application. How I can properly change the default logging template or apply my own log-handler to
asyncio.entrypoint
?Thanks!
The text was updated successfully, but these errors were encountered: