Python Forum
Logging to a file - Formatting
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logging to a file - Formatting
#1
#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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Importing text file into excel spreadsheet with formatting david_dsmn 1 619 Apr-05-2021, 10:21 PM
Last Post: david_dsmn
  Help! Formatting and Writing to a File bwdu 2 880 Apr-19-2020, 09:29 PM
Last Post: deanhystad
  Formatting file data written to file. melblanc 2 882 Jan-15-2020, 03:27 PM
Last Post: melblanc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020