Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logging in python
#1
I have a logger method like as follows
import logging
def log():
    logger = logging.getLogger("exampleApp")
    logger.setLevel(logging.INFO)
 
    # create the logging file handler
    fh = logging.FileHandler("new_snake.log")
 
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
 
    # add handler to logger object
    logger.addHandler(fh)
     return logger
Now i have a
def abc():
   Import log
   logger=log()
   logger.info(“hi”)
   
and
def food():
   Import abc
   abc()
   import log
   logger=log()
   logger.info(“hi”)
Now when i am call def food which in turn calls abc
The log of abc gets executed once while every log in food gets executed twice
Reply
#2
Your code is completely non-functional. It has syntax errors (Import), import errors (and import at the top of the file, not in the function body), indentation errors (the return in the logger). Please give us functional code so we can get to the error you are actually having.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python logging RotatingFileHandler writes to random file after the first log rotation rawatg 0 337 Feb-15-2024, 11:15 AM
Last Post: rawatg
  Python logging error Mekala 2 1,902 Jun-25-2020, 04:03 AM
Last Post: Mekala
  Python Logging and Handling phillyfa 2 4,490 Mar-20-2020, 05:13 PM
Last Post: phillyfa
  Python logging RotatingFileHandler and TimedRotatingFileHandler is not working with Q waytosatyam7 2 4,726 Dec-24-2019, 08:44 AM
Last Post: buran
  Error while Logging on to outlook email account using Python inside VDI Shilton 0 4,269 Sep-09-2018, 06:53 AM
Last Post: Shilton
  Asynchronous Logging in python 2.7 Elbi 4 8,406 Oct-09-2016, 06:10 PM
Last Post: Elbi

Forum Jump:

User Panel Messages

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