Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger improvements #7729

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Logger improvements #7729

wants to merge 16 commits into from

Conversation

estrattonbailey
Copy link
Member

@estrattonbailey estrattonbailey commented Feb 12, 2025

This PR implements some long overdue updates to the logger. There are only a few functional changes.

Debug context has been reimplemented

This was vestigial from a previous project I used this logger on, and we never used it here at Bluesky. But there is utility here, so this PR migrates the existing logger.DebugContext.* 3rd param setup to something more reasonable:

const logger = Logger.create(Logger.Context.Notifications)

This "context" shows up as labels in Sentry to better understand where logs originated, as well as show up in the console for easier debugging. It can also be used via LOG_DEBUG which will filter all debug logs except those that match the filter.

This context is also entirely optional, and existing usages of import {logger} from '#/logger' use the default context logger.

Re-organizes logger files

Transports are now in /transports, all types in /types, etc.

Enables Sentry on web only, never loads on native

To that end, I co-located Sentry files in #/logger/sentry. The sentryTransport is conditionally applied on web only. I left the native interface, as it's the same library anyway, and who knows, we may want it in the future.

Updates Sentry logs to use "context"

This will show up as labels on breadcrumbs, and as (<context>) <message> in results of captureMessage for quicker scanning.

Added some fun colors to console logs (dev only)

Wanted to make logs a little easier to scan, esp on native when they stream back in your terminal without any formatting.

If any extra metadata is passed, the logs appear as a collapsed group to keep things tidy. On native it looks less good, but still a little better than we had before.

const custom = Logger.create('custom') // sub whatever, or use default logger instance
custom.debug(`some dev-only log occurred`, {time: 123})
custom.info(`some breadcrumb event occurred`, {time: 123})
custom.log(`a generic log`)
custom.warn(`ope, a warning`, {message: 'retrying'})
custom.error(`an error without an Error`, {message: 'expected failure'})
custom.error(new Error(`unexpected error`), {message: 'issue might be this:'})

CleanShot 2025-02-12 at 11 19 20@2x

Copy link

Old size New size Diff
7.02 MB 7.02 MB 2.31 KB (0.03%)

@arcalinea arcalinea temporarily deployed to logger-improvements - social-app PR #7729 February 12, 2025 17:29 — with Render Destroyed
@estrattonbailey estrattonbailey marked this pull request as ready for review February 12, 2025 17:29
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.

2 participants