question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option for custom logging format

See original GitHub issue

Using the serializers I can customize what get’s logged. However, I do not have control over the logging format. For example, I would like to log like so:

[1574212772844] INFO (35 on db805887c09f): 11.11.111.111 - GET /url/path - Status Code: 200

Essentially it would mean removing the object with res & err here in logger.js:

      log[level]({
        res: this,
        err: err || this.err || new Error('failed with status code ' + this.statusCode),
        responseTime: responseTime
      }, 'request errored')
      return
    }


    log[level]({
      res: this,
      responseTime: responseTime
    }, 'request completed')

…allowing the user to decide how to format the log.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
wayneblosscommented, Dec 9, 2019

I’d like this option as well.

The suggested 11.11.111.111 - GET /url/path - Status Code: 200 format would be preferred in any configuration instead of the default request completed message, however i’d also add an option to remove details of req and res unless I opt into getting them for specific endpoints.

This code looks easy enough to fork though, so I won’t wait around too long for it.

2reactions
rstoermercommented, Mar 29, 2021

How about using pino-pretty in the following way?

const options = {
    name: "example",
    ...(process.env.NODE_ENV !== "production"
        ? {
              prettyPrint: {
                  ignore: 'req,res,responseTime',
                  messageFormat: (log, messageKey, levelLabel) => {
                      if (log.req) return `${log.responseTime}ms - ${log.msg} - ${log.req.url}`;
                      return `${log.msg}`;
                  }
              }
          }
        : null)
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom log formats | Fastly Help Guides
Fastly provides two versions of custom log formats for use when you ... Click the Edit configuration button and then select the option...
Read more >
How do I add custom field to Python log format string?
You can give a default value to the extra field by extending the logging.Formatter class: class CustomFormatter(logging.Formatter): def format( ...
Read more >
Logging Cookbook — Python 3.11.1 documentation
Author, Vinay Sajip ,. This page contains a number of recipes related to logging, which have been found useful in the past. For...
Read more >
Console log formatting - .NET - Microsoft Learn
Learn how to use available console log formatting, or implement custom log formatting for your .NET applications.
Read more >
Create a custom log file format - SolarWinds Documentation
Add an action to log messages to a file and specify the log file format. If you do not want to use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found