11
submitted 3 months ago* (last edited 3 months ago) by [email protected] to c/[email protected]

Hi, I'm currently using this to log my python process

logging.basicConfig(filename='filename.log', level=logging.DEBUG)

logger = logging.getLogger()

sys.stderr.write = logger.error

sys.stdout.write = logger.info

And then using print(f'{datetime.now()} log message') where I want to log.

It's working OK, buy I would like to live it to ic, but can't find any info on how to send the ic output to the logger.

Thanks for any help.

you are viewing a single comment's thread
view the rest of the comments
[-] sloppy_diffuser 2 points 3 months ago

Never used ic before, but there is an example in the README on GitHub.

>>> import logging
>>> from icecream import ic
>>>
>>> def warn(s):
>>>     logging.warning(s)
>>>
>>> ic.configureOutput(outputFunction=warn)
>>> ic('eep')
WARNING:root:ic| 'eep': 'eep'
[-] [email protected] 1 points 3 months ago

Thanks, tried the next:

logging.basicConfig(filename='filename.log', level=logging.DEBUG)

logger = logging.getLogger()

def warn(s):
    logging.warn(s)

ic.configureOutput(outputFunction=warn)

But it didn't create the .log file and the ic output was printed on the screen instead of the file (that was never created anyway)

this post was submitted on 25 Mar 2024
11 points (100.0% liked)

Python

5949 readers
3 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS