11
submitted 7 months ago* (last edited 7 months ago) by driving_crooner@lemmy.eco.br to c/python@programming.dev

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
[-] nxdefiant@startrek.website 1 points 7 months ago* (last edited 7 months ago)

If you're talking about the package icecream, there's "ic.format()" that returns a string you can log, instead of printing directly to standard out.

More generically, you can have pythons logger capture all of standard out, but that's kind of a shotgun approach, and depending on what your doing, may have some side effects you don't want.

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

Python

6339 readers
9 users here now

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

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

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

founded 1 year ago
MODERATORS