click-log icon indicating copy to clipboard operation
click-log copied to clipboard

Not clear on setting file handler and format

Open natemarks opened this issue 5 years ago • 1 comments

Only getting unformatted console output when I try this. I'll be happy to submit some updated docs if you can help me through this:D

`import click import click_log import logging

logger = logging.getLogger(name)

fh = logging.FileHandler(name + '.log') formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) logger.addHandler(fh)

click_log.basic_config(logger)

@click.command() @click_log.simple_verbosity_option(default='DEBUG', metavar='LEVEL') @click.option('--execution_mode', default='dry_run', help="mode: [dry_run/install/force]") def main(execution_mode, phase, load_local_files): logger.info("beginning with execution mode: " + execution_mode)`

natemarks avatar Sep 26 '18 16:09 natemarks

Hi, use the ColorFormatter on your filehandler.

Also note that basic_config will replace all of your handlers with the ClickHandler, so I would first call basic_config and then set up your additional handler.

untitaker avatar Sep 27 '18 20:09 untitaker