Skip to content

Feature Request: Support for Abbreviated Logger Names in Format ({name:abbrev}) #1400

@raulcarlomagno

Description

@raulcarlomagno

Hi.

In large Python applications, the full module path printed by the {name} token in the Loguru format can become excessively long (e.g., src.common.database.services.user_retrieval). This consumes valuable terminal space and makes log lines difficult to scan quickly.

The current workaround requires manual effort in every module to logger.bind(short_name=...) and then manually define a custom format string using {extra[short_name]}, which defeats Loguru's goal of easy configuration.

I propose adding a precision/abbreviation modifier to the {name} token in the format string, similar to how Logback/log4j implement %logger{n} in Java.
This would allow users to specify the abbreviation style directly in the format string, eliminating the need for logger.bind() in every file.
Proposed Syntax:
{name:short} (or {name:1}): Abbreviate all package segments except the last one.
Input: src.common.db.resources
Output: s.c.d.resources
{name:2}: Show the first letter of all segments except the last two.
Input: src.common.db.resources
Output: s.c.db.resources
{name:all_short} (or {name:all_1}): Show the first letter of every segment.
Input: src.common.db.resources
Output: s.c.d.r

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureRequest for adding a new feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions