#Help with logging

1 messages · Page 1 of 1 (latest)

zenith yoke
#

I would like to have the same logs go to stdout as well as bot.log, but the log file only logs info messages (no stack traces or anything). this is my logging setup:

crewbot.py:

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler1 = logging.FileHandler("bot.log")
handler2 = logging.StreamHandler(sys.stdout)
logger.addHandler(handler1)
logger.addHandler(handler2)

class Crewbot(commands.Bot):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        self.logger = logger

db.py:

handler = logging.FileHandler("sql.log")
logging.getLogger("sqlalchemy.engine").addHandler(handler)
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
logging.getLogger("sqlalchemy.pool").addHandler(handler)
logging.getLogger("sqlalchemy.pool").setLevel(logging.DEBUG)```
lavish turret
#

Use print

#

Besides that joke, what you set up above doesn't print to both stdout and the file?

zenith yoke
#

correct

rain turtle
#

and it prints out what it is put in the logs file

rain turtle
zenith yoke
#

you said "on top of everything"

rain turtle
#

oh no no

zenith yoke
#

how is that different from logger.setLevel(logging.INFO)

rain turtle
#
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler1 = logging.FileHandler("bot.log")
handler2 = logging.StreamHandler(sys.stdout)
logger.addHandler(handler1)
logger.addHandler(handler2)
rain turtle
#

try it and see