Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 24, 2025

Problem

When Echo framework uses its internal logging methods (such as for server startup messages), it calls the Print and Printf methods without specifying a log level. This results in logs showing ??? or - instead of a proper log level:

2024-11-24T18:36:10Z ??? ⇨ http server started on [::]:9151

This happens because the current implementation always uses zerolog.NoLevel with a hardcoded level string of "-" for these methods.

Solution

This PR adds a new configuration option WithDefaultPrintLevel(level log.Lvl) that allows users to configure a default log level for Echo's Print methods. When configured, these methods will use the specified level instead of showing ???.

Usage

e := echo.New()
e.Logger = lecho.New(
    os.Stdout,
    lecho.WithTimestamp(),
    lecho.WithDefaultPrintLevel(log.INFO), // Print methods will use INFO level
)

Result:

2024-11-24T18:36:10Z INF ⇨ http server started on [::]:9151

Implementation Details

  • Added defaultPrintLevel *log.Lvl field to Options and Logger structs
  • Created WithDefaultPrintLevel(level log.Lvl) setter function
  • Added printEvent() helper method to determine the appropriate zerolog event
  • Updated Print, Printf, and Printj methods to use the configurable level
  • When WithDefaultPrintLevel is not specified, behavior remains exactly the same (backward compatible)

Testing

  • All existing tests pass, ensuring 100% backward compatibility
  • Added comprehensive tests covering the new functionality
  • Added specific backward compatibility verification tests
  • Manual testing confirms the feature works as expected

Documentation

Updated README.md with:

  • New option listed in "Available Options" section
  • Dedicated "Default Print Level Configuration" section with examples
  • Before/after comparison showing the improvement

This change is completely backward compatible and provides a clean solution to the "???" log level issue reported in the original issue.

Fixes #33


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Echo uses lecho and log level is missing, can we check and override ? Add WithDefaultPrintLevel option to configure default log level for Print methods Sep 24, 2025
Copilot AI requested a review from ziflex September 24, 2025 17:20
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

Successfully merging this pull request may close these issues.

Echo uses lecho and log level is missing, can we check and override ?

2 participants