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

Log file shows packages logs and only current app logs #22

Open
shlomiLan opened this issue Aug 17, 2017 · 6 comments
Open

Log file shows packages logs and only current app logs #22

shlomiLan opened this issue Aug 17, 2017 · 6 comments

Comments

@shlomiLan
Copy link

In my app I create a logger using:


def create_logger(log_path, log_name, log_level=logging.INFO):
    daiquiri.setup(
        level=log_level,
        outputs=(daiquiri.output.File(
            directory=log_path, program_name=log_name), 
            daiquiri.output.STDOUT,))

    return daiquiri.getLogger(program_name=log_name)

When I look at the console, I see logs for my app and also for all the packages that I use in my app, before when I used the default logger I didn't see those messages.

Can I turn it off, so that in my log I will only see my app logs?

@jd
Copy link
Member

jd commented Aug 17, 2017

The level argument is global. What you want do is:

def create_logger(log_path, log_name, log_level=logging.INFO):
    daiquiri.setup(
        outputs=(daiquiri.output.File(
            directory=log_path, program_name=log_name), 
            daiquiri.output.STDOUT,))

    logger = daiquiri.getLogger(program_name=log_name)
    logger.setLevel(log_level)
    return logger

@jd
Copy link
Member

jd commented Aug 17, 2017

Setting documentation tag since it could be a cool example in doc.

@shlomiLan
Copy link
Author

Thanks

@jd jd reopened this Aug 17, 2017
@shlomiLan
Copy link
Author

I have tried to use your code and got the following error:

  File "utils.py", line 22, in create_logger
    logger.setLevel(log_level)
AttributeError: 'KeywordArgumentAdapter' object has no attribute 'setLevel'

What I'm doing wrong?

@jd
Copy link
Member

jd commented Aug 18, 2017

@shlomiLan

My bad, the adapter returned by daiquiri does not support that. We should probably enhance that too. Try:

def create_logger(log_path, log_name, log_level=logging.INFO):
    daiquiri.setup(
        outputs=(daiquiri.output.File(
            directory=log_path, program_name=log_name), 
            daiquiri.output.STDOUT,))

    logging.getLogger(log_name).setLevel(log_level)
    return daiquiri.getLogger(program_name=log_name)

@shlomiLan
Copy link
Author

The only way I have managed to change the logger log level is with:
daiquiri.getLogger(program_name=log_name).logger.level = log_level

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

No branches or pull requests

2 participants