Python Forum
Python logging RotatingFileHandler writes to random file after the first log rotation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python logging RotatingFileHandler writes to random file after the first log rotation
#1
I am using python logging.handlers.RotatingFileHandler for my log rotation. It is working fine and writting logs to let's say app.log file but after the first rotation it doesn't write to the app.log file all the time. sometimes it start writting to app.log.1 or any other file like that and also it rotates the file too early even though the max byte has not reached. The correct behaviour should be to write to the app.log file alawys. And i want that behaviour only. I have multiple module and every module write to a separate file. Every module use the below method to get its logger by passing log_name and log_file_name.

 
    def get_logger(log_name, log_filename):
         log = logging.getLogger(log_name)
         logs_file = os.path.join(log_path, log_filename)
         log.setLevel(logging.DEBUG)
         file_formatter = logging.Formatter('%(asctime)s - %(pathname)s - %(levelname)s - %(message)s')
         file_handler = logging.handlers.RotatingFileHandler(logs_file, maxBytes=int(1.5e7), backupCount=15)
         file_handler.setFormatter(file_formatter)
         file_handler.setLevel(logging.DEBUG)
         log.addHandler(file_handler)
         return log
If anyone have face this kind of issue, what solution did you apply.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can rich.logging output to file? pyfoo 1 276 Mar-21-2024, 10:30 AM
Last Post: pyfoo
  logging: change log file permission with RotatingFileHandler erg 0 1,052 Aug-09-2023, 01:24 PM
Last Post: erg
  Array Rotation Solution hannah 3 1,508 Mar-31-2022, 09:28 AM
Last Post: paul18fr
  create new log file on logging? korenron 6 2,317 Mar-22-2022, 07:14 AM
Last Post: korenron
  writelines only writes one line to file gr3yali3n 2 2,391 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  Random pictures from a file aliwien 2 4,345 Apr-23-2021, 06:00 PM
Last Post: snippsat
  Calculate transformation and Rotation Sandra2312 1 1,814 Jan-31-2021, 12:53 PM
Last Post: jefsummers
  Logging to a file - Formatting Maxximiliann 0 1,448 Dec-18-2020, 02:06 AM
Last Post: Maxximiliann
  Level curves don't match after rotation schniefen 1 1,549 Dec-14-2020, 09:56 PM
Last Post: schniefen
  Rotation Effect on live Webcam Feed Leziiy 0 1,620 Sep-12-2020, 04:25 PM
Last Post: Leziiy

Forum Jump:

User Panel Messages

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