Created
July 20, 2016 22:43
-
-
Save randomradio/d2017117fb4f7c43c344ccc36a8ac58f to your computer and use it in GitHub Desktop.
minimal python logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
class Logger(object): | |
""" | |
this object will repalce default stdout object. | |
logging info into terminal with sys.stdout | |
save logging info into log file | |
{TODO} accept log file as argument | |
""" | |
def __init__(self): | |
self.terminal = sys.stdout | |
self.log = open("orders_log", "a") | |
def write(self, message): | |
self.terminal.write(message) | |
self.log.write(message) | |
def flush(self): | |
#this flush method is needed for python 3 compatibility. | |
#this handles the flush command by doing nothing. | |
#you might want to specify some extra behavior here. | |
pass | |
sys.stdout = Logger() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment