diff --git a/README.md b/README.md index 54c4485..13fe05a 100644 --- a/README.md +++ b/README.md @@ -353,15 +353,13 @@ If you prefer using web hooks to the getUpdates method, you can use the `process ### Logging You can use the Telebot module logger to log debug info about Telebot. Use `telebot.logger` to get the logger of the TeleBot module. +It is possible to add custom logging Handlers to the logger. Refer to the [Python logging module page](https://docs.python.org/2/library/logging.html) for more info. ```python +import logging + logger = telebot.logger -formatter = logging.Formatter('[%(asctime)s] %(thread)d {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', - '%m-%d %H:%M:%S') -ch = logging.StreamHandler(sys.stdout) -logger.addHandler(ch) -logger.setLevel(logging.DEBUG) # or use logging.INFO -ch.setFormatter(formatter) +telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console. ``` ## F.A.Q. diff --git a/telebot/__init__.py b/telebot/__init__.py index 6e9af53..d99db79 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -10,9 +10,9 @@ import logging logger = logging.getLogger('TeleBot') formatter = logging.Formatter('%(asctime)s (%(filename)s:%(lineno)d) %(levelname)s - %(name)s: "%(message)s"') -ch = logging.StreamHandler(sys.stderr) -ch.setFormatter(formatter) -logger.addHandler(ch) +console_output_handler = logging.StreamHandler(sys.stderr) +console_output_handler.setFormatter(formatter) +logger.addHandler(console_output_handler) logger.setLevel(logging.ERROR)