Python Forum
Closing logger to rename directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing logger to rename directory
#1
I have 2 functions, one is creating a logs in directory and other should rename directory to "directory_old" and then create new "directory". Problem is that I will not have acces to rename this directory untill logger is initiated so I want to disable loggers, rename directory and enable loggers again. I know there is module ".close()" but in my case it doesn't work at all or I don't know how to use it(more probably).

def start_logger(self):
    self.log = logging.getLogger()
    self.log.handlers = []
    Filehandler = logging.FileHandler(filename="directory\\logs\\stages" + '.log', mode="w")
    self.log.info("succes")
    self.log.addHandler(Filehandler)


def clear_logger(self):
    #close logger??
    self.log.close()
    os.rename("directory","directory_old")
    #create new directory
    os.mkdir("directory\\logs")
    #start logger again
    #???
Reply
#2
Just a hunch but you could perhaps use self.log.removeHandler(...) instead of «closing» the logger. Read about Logger objects API here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to share a configured logger between running processes? somhairle69tx 5 1,486 Sep-06-2024, 11:10 PM
Last Post: somhairle69tx
  logger behaviour setdetnet 1 1,506 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  how to write exception error into logger mg24 3 1,803 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  python insert blank line in logger mg24 1 4,868 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 3,117 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger from other function problem Paqqno 1 1,769 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  logger option , where is the file? korenron 1 2,449 Apr-25-2021, 01:28 PM
Last Post: snippsat
  Rename Multiple files in directory to remove special characters nyawadasi 9 10,055 Feb-16-2021, 09:49 PM
Last Post: BashBedlam
  How to assign input file name as logger name Mekala 5 4,122 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 8,359 Jun-14-2019, 03:58 PM
Last Post: nirvantosh

Forum Jump:

User Panel Messages

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