Skip to content

Conversation

@SaurabhCodesAI
Copy link
Contributor

@SaurabhCodesAI SaurabhCodesAI commented Oct 22, 2025

Fixes

Description

Fixed logging output routing so info/warning messages go to stdout and errors go to stderr. Also added colors to log messages so they're easier to read in the terminal.

Technical details

Replaced basicConfig() with dual handlers for proper output routing, then added a ColoredFormatter class with the ANSI color codes.

Tests

Run python scripts/1-fetch/gcs_fetch.py --help and you'll see colored log output routed correctly.

Screenshots

Checklist

  • I have read and understood the Developer Certificate of Origin (DCO), below, which covers the contents of this pull request (PR).
  • My pull request doesn't include code or content generated with AI.
  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@SaurabhCodesAI SaurabhCodesAI requested review from a team as code owners October 22, 2025 00:35
@SaurabhCodesAI SaurabhCodesAI requested review from TimidRobot and possumbilities and removed request for a team October 22, 2025 00:35
@cc-open-source-bot cc-open-source-bot moved this to In review in TimidRobot Oct 22, 2025
@SaurabhCodesAI SaurabhCodesAI changed the title Fix logging output routing Fix logging output routing and added colorized logging (#205, #206) Oct 22, 2025
…mons#205, creativecommons#206)

- Routed info/warning messages to stdout, errors to stderr
- Added ANSI color codes for different log levels
- Implemented ColoredFormatter with specified color scheme
@SaurabhCodesAI
Copy link
Contributor Author

About the basicConfig thing, I tried keeping it at first but it messed with the new handlers, so I just replaced it entirely.

Used a dictionary for the colors since it was easier than a bunch of if statements.

Did both issues together since #206 needed #205 done first anyway.

Thanks @TimidRobot for the clear issue descriptions, made it much easier to understand what was needed!

@TimidRobot TimidRobot self-assigned this Oct 22, 2025
Copy link
Member

@TimidRobot TimidRobot left a comment

Choose a reason for hiding this comment

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

Great work!

A couple of the comments are asking you to fix my own mistakes 🙃

Testing this was made a little more difficult due to the branch/PR being out of date (not synchronized with main). I suspect this is also why the changes to the update_readme function were included.

class ColoredFormatter(logging.Formatter):
"""Adds colors to log messages."""

COLORS = {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment above this dictionary:

# https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add that comment for clarity. Thanks!

COLORS = {
logging.DEBUG: "\033[90m", # bright black
logging.INFO: "\033[37m", # white
logging.WARNING: "\033[103m", # bright yellow
Copy link
Member

Choose a reason for hiding this comment

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

Please update to 93 per #206 (comment)

It is important that you test the changes before you submit them (103 is a background color).

Copy link
Member

@TimidRobot TimidRobot Oct 22, 2025

Choose a reason for hiding this comment

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

  • I tried running the project locally and verified that there are no visible errors.

Did you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see the issue now ,103 is a background color. I was up late working on this and didn't catch that when testing. Will fix it to 93 and actually verify the colors this time.

logging.DEBUG: "\033[90m", # bright black
logging.INFO: "\033[37m", # white
logging.WARNING: "\033[103m", # bright yellow
logging.ERROR: "\033[33m", # yellow
Copy link
Member

Choose a reason for hiding this comment

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

Please update to 91 bright red per #206 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, will change to 91.

Comment on lines +262 to +266
while (
entry_end_index + 1 < len(lines)
and not lines[entry_end_index + 1].strip()
):
entry_end_index += 1
Copy link
Member

Choose a reason for hiding this comment

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

Why are you reverting fix from #202 here?

It is important that you review pull requests yourself after you submit them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That wasn't intentional, as you mentioned my branch was out of sync with main. I'll sync it up and make sure the fix from #202 stays in.

@TimidRobot
Copy link
Member

TimidRobot commented Oct 22, 2025

  • I added or updated tests for the changes I made (if applicable).

Which tests did you add or update?

  • I added or updated documentation (if applicable).

What documentation did you update?

@SaurabhCodesAI
Copy link
Contributor Author

  • I added or updated tests for the changes I made (if applicable).

Which tests did you add or update?

  • I added or updated documentation (if applicable).

What documentation did you update?

I apologize, I missed the "(if applicable)" part and checked those boxes without thinking. I'm still learning the open source contribution process and will be more careful with the checklist. Thanks for your valuable guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Colorize logging based on log level Logging outputs to stderr instead of stdout

2 participants