Skip to content

fix(cmd/librarian): log errors with error level#2754

Merged
zhumin8 merged 3 commits intomainfrom
log-err
Nov 3, 2025
Merged

fix(cmd/librarian): log errors with error level#2754
zhumin8 merged 3 commits intomainfrom
log-err

Conversation

@zhumin8
Copy link
Copy Markdown
Contributor

@zhumin8 zhumin8 commented Nov 3, 2025

Log level Error were lost in main when calling log.Fatal instead of slog.Error. Errors returned appear as INFO messages instead of ERROR.

This was likely an oversight switching to slog as default logger. In internal/librarian/librarian.go, the setupLogger function calls slog.SetDefault(). This tells the slog package to become the default logger for the entire application. A side effect of this is that slog also intercepts any output from the standard log package with no level info.

Also added a validation step in e2e test on failure case for generate, to verify error is reported with Error level.

Test run below to verify now it correctly reports error:

╰─$ go run ./cmd/librarian generate -push                                                                              
time=2025-11-03T12:56:21.109-05:00 level=INFO msg="Temporary working directory" dir=/tmp/librarian-4043056686
time=2025-11-03T12:56:21.110-05:00 level=INFO msg="repo not specified, using current working directory as repo root" path=/usr/local/google/home/zhumin/repos/librarian
time=2025-11-03T12:56:21.110-05:00 level=ERROR msg="librarian command failed" err="failed to validate config: no GitHub token supplied for push"
exit status 1

Fix #2686

@zhumin8 zhumin8 requested a review from a team as a code owner November 3, 2025 16:06
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zhumin8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical logging discrepancy within the librarian command-line tool. Previously, errors that should have been reported at the ERROR level were appearing as INFO messages, hindering effective debugging and monitoring. The change ensures that all fatal errors are now correctly logged with the appropriate ERROR severity, significantly improving the clarity and reliability of the application's log output.

Highlights

  • Logging Correction: Corrected an issue where critical error messages were logged at the 'INFO' level instead of the intended 'ERROR' level. This was due to the use of 'log.Fatal' which, after 'slog' was set as the default logger, was intercepted without proper level information.
  • Slog Integration: Updated the main command file to explicitly use 'slog.Error' for logging fatal errors, ensuring consistency with the application's default structured logger and correct error reporting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue where errors were being logged at the INFO level instead of ERROR. The switch from log.Fatal to slog.Error is the right approach. I've added one suggestion to further align the implementation with structured logging best practices, which will improve the queryability of your logs.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (13bcf28) to head (f44890e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/librarian/main.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2754      +/-   ##
==========================================
- Coverage   86.93%   86.92%   -0.01%     
==========================================
  Files         118      118              
  Lines        9895     9896       +1     
==========================================
  Hits         8602     8602              
- Misses        914      915       +1     
  Partials      379      379              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhumin8 zhumin8 merged commit bdc662c into main Nov 3, 2025
10 checks passed
@zhumin8 zhumin8 deleted the log-err branch November 3, 2025 18:47
zhumin8 added a commit that referenced this pull request Nov 3, 2025
…ling (#2759)

Use t.Fatal instead of log.Fatal in TestRun.
Came across this when working on #2754.
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.

librarian: log errors messages as errors instead of INFO

2 participants