Store logger.log() output into variable
See original GitHub issueHi.
I want to store the output of logger.log("Some logging message")
into variable.
The reason for that is that I want to send some logging messages into my Email from the program same as they shown in the terminal console
for instance
>> log_msg = logging.log("Storing data...")
# Nothing should print into the terminal console
>> print(log_msg)
# Expected output
2021-02-20 23:11:48.955 | INFO | TeleBot:store_data:69 - Storing data...
# And of course, I would like to send it to my mail
>> send_logging_message_to_mail(log_msg)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Python rolling log to a variable - Stack Overflow
Use the technique described in Capturing Python Log Output In A Variable, but capture it into a custom stream that throws away old...
Read more >Capturing Python Log Output In A Variable - gists · GitHub
Capturing Python Log Output In A Variable. ... logger = logging.getLogger('basic_logger'). logger.setLevel(logging.DEBUG) ... log_capture_string.close().
Read more >Capturing Python Log Output In A Variable - Alan W. Smith
Capturing Python Log Output In A Variable · Create the logger. logger = logging. · Setup the console handler with a StringIO object...
Read more >Logger log() Method in Java with Examples - GeeksforGeeks
log (Level level, String msg): This method is used to Log a message, with no arguments.only message will be written in logger Output....
Read more >AWS Lambda function logging in Java
This page describes how to produce log output from your Lambda function's code, or access logs using the AWS Command Line Interface, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The first parameter can also be a callable (function) so should work as is, just update to point to your function that takes message as a parameter.
Thanks @obviousrebel for pointing that out. Indeed, it’s not possible to retrieve the output of a logging call. Actually, there is no such output because it depends entirely of the added handlers and their
format
configuration. Each handler has its own output.You should instead add your
send_logging_message_to_mail()
as a sink and use maybe afilter
combined withbind()
to decide when to send the email.