Python Forum
Logging to a file - Formatting - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Logging to a file - Formatting (/thread-31546.html)



Logging to a file - Formatting - Maxximiliann - Dec-18-2020

#logging.conf

[loggers]
keys=root,activity_report

[handlers]
keys=fileHandler

[formatters]
keys=activity_report_format

[logger_root]
level=INFO
handlers=fileHandler
formatter=activity_report_format

[logger_activity_report]
level=INFO
handlers=fileHandler
formatter=activity_report_format
qualname=activity_report
propogate=0

[handler_fileHandler]
class=handlers.RotatingFileHandler
level=INFO
fomatter=activity_report_format
args=('activity_report.txt', 26214400, 5) #25mb = 26,214,400 bytes

[formatter_activity_report_format]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
class=logging.Formatter
#Sandbox.py

import logging
import logging.config
from logging.handlers import RotatingFileHandler

logging.config.fileConfig('/home/maxximiliann/Desktop/Arbit/lib/Python/logging.conf')
logger = logging.getLogger(__name__)


logger.error('Trouble in Paradise . . . ')
#activity_report.txt

Trouble in Paradise . . .
What more needs to be done such that logs are recorded to activity_report.txt with the formatting defined in activity_report_format ?