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

[ BUG ] Logging scopes do not all start with "caracara" #87

Closed
59e5aaf4 opened this issue Apr 12, 2023 · 1 comment · Fixed by #92
Closed

[ BUG ] Logging scopes do not all start with "caracara" #87

59e5aaf4 opened this issue Apr 12, 2023 · 1 comment · Fixed by #92
Assignees
Labels
bug 🐛 Something isn't working

Comments

@59e5aaf4
Copy link

Describe the bug

Some caracara modules do not carry the "caracara" name in their logging scope. This causes logging.getLogger('caracara').setLevel(logging.WARNING) to only affect some parts of caracara.

2023-04-12 09:24:16,742	CustomIoaApiModule	Initialising API module: CustomIoaApiModule
2023-04-12 09:24:16,742	FlightControlApiModule	Initialising API module: FlightControlApiModule
2023-04-12 09:24:16,742	FlightControlApiModule	Configuring the FalconPy Flight Control API
2023-04-12 09:24:16,743	HostsApiModule	Initialising API module: HostsApiModule
2023-04-12 09:24:16,743	HostsApiModule	Configuring the FalconPy Hosts API
2023-04-12 09:24:16,743	HostsApiModule	Configuring the FalconPy Host Group API
2023-04-12 09:24:16,743	PreventionPoliciesApiModule	Initialising API module: PreventionPoliciesApiModule
2023-04-12 09:24:16,745	PreventionPoliciesApiModule	Configuring the FalconPy Prevention Policies API
2023-04-12 09:24:16,745	ResponsePoliciesApiModule	Initialising API module: ResponsePoliciesApiModule
2023-04-12 09:24:16,745	ResponsePoliciesApiModule	Configuring the FalconPy Response Policies API
2023-04-12 09:24:16,746	RTRApiModule	Initialising API module: RTRApiModule

To Reproduce

Run some code like the following, that just silences the 'caracara' module to a specified level :

# Silence a little bit all this debug noise enabled by default
for caracara_logging_scope in (
    'caracara',
    #'CustomIoaApiModule',
    #'FlightControlApiModule',
    #'HostsApiModule',
    #'PreventionPoliciesApiModule',
    #'RTRApiModule',
    #'ResponsePoliciesApiModule',
):  
    if self.debug:
        pass
    else: 
        l = logging.getLogger(caracara_logging_scope)
        l.setLevel(logging.WARNING)

It's not much, and we have a workaround ready with the list of modules generating logs added to a hardcoded list. That being said, I have a vague feeling that some PEP might suggest prefixing logging scopes.

Expected behavior

All code loaded by caracara receives the same log level

Suggested fixes

Prefix these logging scopes with caracara or caracara.modules. What we do in our code base is just pick the current module and call it a day. Prior to that we even added the class name, but having one class per file makes it simpler. ( I won't comment on my spaghetti code base file lengths :D )

self.logger = logging.getLogger(".".join([
    self.__module__,
    # self.__class__.__name__,
]))

Environment

Operating System Version

Debian bookworm

Python Version

Python 3.10.5

Poetry Version

Poetry (version 1.4.1)

Python Package Versions

$ pip freeze | grep -E '(caracara|falconpy)'
caracara==0.2.2
crowdstrike-falconpy==1.2.12
@59e5aaf4 59e5aaf4 added the bug 🐛 Something isn't working label Apr 12, 2023
@ChristopherHammond13 ChristopherHammond13 self-assigned this Apr 25, 2023
@ChristopherHammond13
Copy link
Member

@jshcodes I think this is a very reasonable bug report, and one I'd like to get sorted. I wanted to tag you here to check whether this was something we'd done out of spec in any other Python libraries we offer, such as FalconPy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants