Util to generate Logger with consistent naming schema #5574

Closed
opened 2022-02-14 21:52:58 +01:00 by i-am-zaidali · 3 comments
i-am-zaidali commented 2022-02-14 21:52:58 +01:00 (Migrated from github.com)

Type of feature request

Other

Description of the feature you're suggesting

After a slightly detailed discussion in #coding on the main server, it came to the conclusion that unified namespaces for loggers of 3rd party cogs would be cool. It was proposed that a function could be added to the utils folder that takes the cog name and the repo name as its arguments, with an optional sub_module argument and returns the Logger object with a namespace as follows: red.RepoName.CogName[.SubModule].
This new addition is useful in ways like having consistency in all logger names for all 3rd party cogs (that use this), core devs could force a certain namespace format, devs won't have to worry about their logs being silenced if they use the wrong namespace and this would strip the namespace to a specified char limit so that it doesn't look weird on consoles with extra large names.

Anything else?

This would also merely be an addition and would not change or break any existing functionality in red.

I would like other's opinions on this and would be happy to PR this addition if agreed to.

### Type of feature request Other ### Description of the feature you're suggesting After a slightly detailed discussion in #coding on the main server, it came to the conclusion that unified namespaces for loggers of 3rd party cogs would be cool. It was proposed that a function could be added to the utils folder that takes the cog name and the repo name as its arguments, with an optional sub_module argument and returns the `Logger` object with a namespace as follows: `red.RepoName.CogName[.SubModule]`. This new addition is useful in ways like having consistency in all logger names for all 3rd party cogs (that use this), core devs could force a certain namespace format, devs won't have to worry about their logs being silenced if they use the wrong namespace and this would strip the namespace to a specified char limit so that it doesn't look weird on consoles with extra large names. ### Anything else? This would also merely be an addition and would not change or break any existing functionality in red. I would like other's opinions on this and would be happy to PR this addition if agreed to.
Drapersniper commented 2022-02-14 21:56:51 +01:00 (Migrated from github.com)

If this will be done you should take this opportunity to ensure a clean logger namespace.
something akin to the following:

def get_logger(cog: str, repo:str, type: Literal["cog", "lib"] = "cog", sub_module: Optional[str] = None):
  base_namespace = "red.3pt"
  parts = [base_namespace, type, repo, cog]
  if sub_module:
    parts.append(sub_module.replace(" ", "."))
  final_namespace = ".".join(parts).lower()
  ... # check if duplicate and handle it
  return logging.getLogger(final_namespace)

To expand on

and this would strip the namespace to a specified char limit so that it doesn't look weird on consoles with extra-large names.

In addition to the code block above, due to to potential for having very large logger names (Audio cog for example), a character limiter should be added to
https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/logging.py#L189

        if logger_name:
          output.append(f"[{logger_name[:32]}] ", style="bright_black")

This would ensure a consistent length of logger names printed on the console (while keeping the logger names in the logging file untouched)

if this is approved,
https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/docs/guide_cog_creators.rst#recommendations-for-cog-creators
should be updated to direct cog creators to use this util method to ensure consistency in the logging namespace

If this will be done you should take this opportunity to ensure a clean logger namespace. something akin to the following: ```py def get_logger(cog: str, repo:str, type: Literal["cog", "lib"] = "cog", sub_module: Optional[str] = None): base_namespace = "red.3pt" parts = [base_namespace, type, repo, cog] if sub_module: parts.append(sub_module.replace(" ", ".")) final_namespace = ".".join(parts).lower() ... # check if duplicate and handle it return logging.getLogger(final_namespace) ``` To expand on > and this would strip the namespace to a specified char limit so that it doesn't look weird on consoles with extra-large names. In addition to the code block above, due to to potential for having very large logger names (Audio cog for example), a character limiter should be added to https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/logging.py#L189 ```py if logger_name: output.append(f"[{logger_name[:32]}] ", style="bright_black") ``` This would ensure a consistent length of logger names printed on the console (while keeping the logger names in the logging file untouched) if this is approved, https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/docs/guide_cog_creators.rst#recommendations-for-cog-creators should be updated to direct cog creators to use this util method to ensure consistency in the logging namespace
Drapersniper commented 2022-04-02 14:24:39 +02:00 (Migrated from github.com)

This would likely make more sense to go into https://github.com/Cog-Creators/Red-Common, at least the get_logger section - but the second part should still be done in Red as Red is the lib that controls the log formatting.

This would likely make more sense to go into https://github.com/Cog-Creators/Red-Common, at least the `get_logger` section - but the second part should still be done in Red as Red is the lib that controls the log formatting.
Owner

Offene Diskussion bzw. Feature-Wunsch mit geringem Nutzen im Verhältnis zum Aufwand (oder Nischenfall), der seit Langem ohne Ergebnis offen ist. Ich schließe das Issue; bei konkretem Bedarf kann es gern wieder geöffnet werden.


Generated by Claude Code

Offene Diskussion bzw. Feature-Wunsch mit geringem Nutzen im Verhältnis zum Aufwand (oder Nischenfall), der seit Langem ohne Ergebnis offen ist. Ich schließe das Issue; bei konkretem Bedarf kann es gern wieder geöffnet werden. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#5574
No description provided.