Python Forum
Closing logger from other function problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing logger from other function problem
#1
I have problem with loggers. One function of my program is initiazing logger in specified directory. Second function is closing this logger in order to change name of direcotry to "directory_old" and creating new "directory", then logging should be initiaze again. It must be done this way because active logger locks directory. But I don't know how to close it or disable from another function, I know about ".close()" in loggers but in my case I have no idea how to use it in clear(self) function.

import logging
import os
class self:
    def logger(self):
        self.log = logging.getLogger()
        self.log.handlers = []
        self.log.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
        loggingFilehandler = logging.FileHandler('directory\\logs.log')
        loggingFilehandler.setLevel(logging.DEBUG)
        loggingFilehandler.setFormatter(formatter)

        self.log.addHandler(loggingFilehandler)

    def clear(self):
        #
        self.log.addHandler.close()
        os.rename("directory", "directory_old", )
        # create new directory
        os.mkdir("directory")

self.logger(self)
self.clear(self)
Reply
#2
This question is similar to this other thread. See if my suggestion works. Are you a friend of @malcoverc?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 899 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  how to write exception error into logger mg24 3 991 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  python insert blank line in logger mg24 1 2,863 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 1,491 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger to rename directory malcoverc 1 1,212 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  logger option , where is the file? korenron 1 1,794 Apr-25-2021, 01:28 PM
Last Post: snippsat
  How to assign input file name as logger name Mekala 5 2,880 Aug-05-2020, 12:54 AM
Last Post: Larz60+
  Logger file rotation not working when python code started from windows service as exe nirvantosh 1 6,679 Jun-14-2019, 03:58 PM
Last Post: nirvantosh
  Coding a logger for firefox history kpiatrou 2 2,886 Dec-25-2018, 06:42 PM
Last Post: snippsat
  Updated security logger jameseroni 0 2,038 Oct-29-2018, 04:23 AM
Last Post: jameseroni

Forum Jump:

User Panel Messages

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