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 Working #14

Open
aress31 opened this issue Sep 10, 2022 · 1 comment
Open

Not Working #14

aress31 opened this issue Sep 10, 2022 · 1 comment

Comments

@aress31
Copy link

aress31 commented Sep 10, 2022

Hi @xolox,

I am a huge fan of coloredlogs, I consistently use it in all my Python projects and by reading the doc I have just came across verboselogs. Obviously, I now need to adopt it as well, however, I am currently having a tough time getting verboselogs to work - at the root logger level.

Please see my code and kindly advise where I messed up:

import coloredlogs
import logging
import verboselogs


def init_logger(log_level):
    verboselogs.install()
    coloredlogs.install(
        fmt="%(level_name)s %(message)s",
        level=logging.getLevelName(log_level)
    )

    logging.getLogger('requests').setLevel(logging. ERROR)
    logging.getLogger('urllib3').setLevel(logging. ERROR)
import logging
import verboselogs

from configuration.Logger import init_logger

def main():
    args = init_args()
    init_logger(args.log_level)
    print(logging.getLogger(__name__))
    # <VerboseLogger __main__ (SPAM)>
    logging.spam('This is a trace message')

if __name__ == "__main__":
    main()

The resulting error stack-trace:

Traceback (most recent call last):
  File "C:\Users\REDACTED.py", line 95, in <module>
    main()
  File "C:\Users\REDACTED.py", line 27, in main
    logging. Spam('This is a trace message')
AttributeError: module 'logging' has no attribute 'spam'
@Cheekie25
Copy link

Cheekie25 commented Sep 27, 2022

I think you need to first create a logger like in the exemple :
logger = logging.getLogger(__name__) # will be a VerboseLogger instance

And log with that instead of using logging directly.

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