New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@dotcom-reliability-kit/logger

Package Overview
Dependencies
Maintainers
5
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotcom-reliability-kit/logger - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

1

lib/logger.d.ts

@@ -43,2 +43,3 @@ export = Logger;

transforms?: LogTransform[] | undefined;
withPrettifier?: boolean | undefined;
withTimestamps?: boolean | undefined;

@@ -45,0 +46,0 @@ };

@@ -23,2 +23,4 @@ const pino = require('pino').default;

* Transforms to apply to logs before sending.
* @property {boolean} [withPrettifier = true]
* Whether to prettify log output if it's possible.
* @property {boolean} [withTimestamps = true]

@@ -184,2 +186,8 @@ * Whether to send the timestamp that each log method was called.

// Default and set the prettifier option
const withPrettifier =
typeof options.withPrettifier === 'boolean'
? options.withPrettifier
: !Boolean(process.env.LOG_DISABLE_PRETTIFIER);
// Default and set the timestamps option.

@@ -206,3 +214,3 @@ const withTimestamps = options.withTimestamps !== false;

};
if (PRETTIFICATION_AVAILABLE) {
if (withPrettifier && PRETTIFICATION_AVAILABLE) {
pinoOptions.transport = {

@@ -344,2 +352,10 @@ target: 'pino-pretty',

if (sanitizedLogData.error && sanitizedLogData.error instanceof Error) {
sanitizedLogData.error = serializeError(sanitizedLogData.error);
}
if (sanitizedLogData.err && sanitizedLogData.err instanceof Error) {
sanitizedLogData.err = serializeError(sanitizedLogData.err);
}
// Transform the log data

@@ -346,0 +362,0 @@ let transformedLogData = clone(sanitizedLogData, {

{
"name": "@dotcom-reliability-kit/logger",
"version": "2.1.0",
"version": "2.2.0",
"description": "A simple and fast logger based on Pino, with FT preferences baked in",

@@ -22,4 +22,12 @@ "repository": {

"@ungap/structured-clone": "^1.0.2",
"pino": "^8.11.0"
"pino": "^8.12.0"
},
"peerDependencies": {
"pino-pretty": "^10.0.0"
},
"peerDependencyMeta": {
"pino-pretty": {
"optional": true
}
},
"devDependencies": {

@@ -26,0 +34,0 @@ "@financial-times/n-logger": "^10.3.0",

55

README.md

@@ -13,2 +13,3 @@

* [`options.transforms`](#optionstransforms)
* [`options.withPrettifier`](#optionswithprettifier)
* [`options.withTimestamps`](#optionswithtimestamps)

@@ -193,2 +194,10 @@ * [`logger.log()` and shortcut methods](#loggerlog-and-shortcut-methods)

#### `options.withPrettifier`
Whether to send prettified logs if available. This option has no effect if you have the `NODE_ENV` environment variable set to either `production` or if you have not installed [pino-pretty](https://github.com/pinojs/pino-pretty#readme). See [local development usage](#local-development-usage) for more information.
Must be a `Boolean` and defaults to `true`.
It's also possible to set this option as an environment variable, which is how you configure the default logger. Set the `LOG_DISABLE_PRETTIFIER` environment variable to `true` if you want to force the prettifier not to load.
#### `options.withTimestamps`

@@ -494,18 +503,38 @@

Errors found in sub-properties of the log data are _not_ serialized like this. This is for performance reasons: looping over every nested property to check if it's an error is expensive. Do **not** do this:
Errors found in sub-properties of the log data are _not_ serialized like this due to performance reasons: looping over every nested property to check if it's an error is expensive (do **not** do this). Also, be mindful of passing in errors with a custom error property e.g. `myErrorProperty`, as you'll have to serialize them yourself like below:
```js
logger.info({ err: new Error('Oops') });
// Outputs:
// {
// "level": "info",
// "err": {}
// }
```
```js
logger.info({ myErrorProperty: serializeError(new Error('Oops')) });
```
If you _need_ to pass error objects as a property, you must serialize it yourself:
... if not, you'll get the following output:
```js
logger.info({ myErrorProperty: new Error('Oops') });
// Outputs:
// {
// "level": "info",
// "myErrorProperty": {}
// }
```
The exception to this is if the sub-property name is either `error` or `err`, as these are automatically serialized. E.g.
```js
logger.info({ err: serializeError(new Error('Oops')) });
```
logger.info({ error: new Error('Oops') });
// Outputs:
// {
// "level": "info",
// "error": {
// "cause": null,
// "code": "UNKNOWN",
// "data": {},
// "isOperational": false,
// "message": "Oops",
// "name": "Error",
// "relatesToSystems": [],
// "statusCode": null
// }
// }
```

@@ -539,2 +568,4 @@ #### Order of precedence

3. Ensure you don't disable prettification via the [`withPrettifier` option](#optionswithprettifier).
### Production usage

@@ -541,0 +572,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc