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

Add a minimal message option for cleaner logs #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tigawanna
Copy link

@tigawanna tigawanna commented Jan 18, 2025

Add a minimal messgae option for cleaner logs

ex: with minimal enabled

  return logger({
    pino: pino(
      {
        level: envVariables.LOG_LEVEL || "info",
      },
      envVariables.NODE_ENV === "production" ? undefined : pretty({
        colorize: true,
      }),
    ),
    http: {
      reqId: () => crypto.randomUUID(),
      minimalMessage:true,
    },
  });
[10:37:26.771] INFO (223659): ✅  /api/v1/inventory GET  200 OK  application/json 29ms

With custom bindings

  return logger({
    pino: pino(
      {
        level: envVariables.LOG_LEVEL || "info",
      },
      envVariables.NODE_ENV === "production" ? undefined : pretty({
        colorize: true,
      }),
    ),
    http: {
      reqId: () => crypto.randomUUID(),
      minimalMessage:(b,c)=>{
        return {
          extra:"i want to log this too",
          ...b,
        }
      }
    },
  });
[10:38:23.093] INFO (225266): Request completed
    extra: "i want to log this too"
    res: {
      "status": 200,
      "headers": {}
    }
    req: {
      "url": "/api/v1/inventory",
      "method": "GET",
      "headers": {

@tigawanna tigawanna changed the title Main Add a minimal messgae option for cleaner logs Jan 18, 2025
@tigawanna tigawanna changed the title Add a minimal messgae option for cleaner logs Add a minimal message option for cleaner logs Jan 19, 2025
@maou-shonen
Copy link
Owner

Hi, Thank you for liking this package and contributing to it.
I originally planned to provide something similar using transport(but I've busy with work lately),
like this:

pinoLogger({
  pino: {
    transport: 'hono-pino/simple-logger'
  }
})

For me, delegating the task of formatting messages to the pino transport is a better choice.
However, there are indeed some limitations to this approach.
Could you provide some ideas to help me decide how to improve the API for this feature?

@tigawanna
Copy link
Author

Anything that exposes a way to format the final output would be nice , personally i wanted minimal logs by default especially on dev to reduce the amount of scrolling necessary to find specific requests since currently a single request can span the entire terminal height

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (31aec6f) to head (f7d62f6).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main       #68    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            5         5            
  Lines          169       290   +121     
  Branches        62        73    +11     
==========================================
+ Hits           169       290   +121     

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

@maou-shonen
Copy link
Owner

After considering it, I still believe this is the responsibility of pino.transport.
Would you be willing to modify it to the pino.transport version?

@tigawanna
Copy link
Author

Will look at it later

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