Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not clear on setting file handler and format #17

Open
natemarks opened this issue Sep 26, 2018 · 1 comment
Open

Not clear on setting file handler and format #17

natemarks opened this issue Sep 26, 2018 · 1 comment

Comments

@natemarks
Copy link

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)`

@untitaker
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants