wechaty/python-wechaty-puppet

there should be a debug mode for python-wechaty

Closed this issue · 3 comments

python-wechaty is at a early stage which need more detail running detail information for debugging. We have occured some problems that we can't reproduction error from the issue and we can't find more detail information to fix. So, we should enable debug mode for python-wechaty by default which can output all of the debug-level info into log file, so the user can easily put log file to the issues to check the error.

When python-wechaty is at a stable stage, we can change the debug mode to false by default. Should we do it ? @huan

huan commented

I think one of the solution would be following the TS style: set WECHATY_LOG to enable the log output, and use redirect to save log messages to file?

@huan I think we should save log message to file at this early stage. There are some reasons:

  • debug information is too detailed that chatie-grpc also exist in log-output.
  • this is much more friendly that developer can easily put the log to issue. I think this will be better for reproduce the issue.

We can enable the log with debug-level by defualt which will output INFO log to the terminal and output the DEBUG log to the file. So, In this way, the developer can't feel any difference than before. The core code is :

# create logger and set level to debug
logger = logging.getLogger()
logger.handlers = []
logger.setLevel(logging.DEBUG)
logger.propagate = False

# create file handler and set level to debug
if filepath is not None:
    file_handler = logging.FileHandler(filepath, "a")
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(log_formatter)
    logger.addHandler(file_handler)

# create console handler and set level to info
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(log_formatter)
logger.addHandler(console_handler)

@huan How do think about this solution ?

huan commented

I think this solution is ok for me.

Please go ahead with it.