Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@seek/logger

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seek/logger

Standardized logging

  • 4.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
decreased by-14.63%
Maintainers
1
Weekly downloads
 
Created
Source

@seek/logger

GitHub Release GitHub Validate Node.js version npm package semantic-release Commitizen friendly

Standardized application Logging

This allows us consistently query request and response across all apps.

Sample Usage

import createLogger from '@seek/logger';

// Initialize - by default logs to Console Stream
const logger = createLogger({
  name: 'my-app',
});

// Import logged object interfaces from a shared module OR
// declare logged object interfaces
interface MessageContext {
  activity: string;
  err?: Error | { message: string };
  req?: {
    method: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
    url: string;
  };
}

// Specify the interface and benefit from enforced structure and code completion.
logger.trace<MessageContext>({
  activity: 'Getting all the things',
  req: { method: 'GET', url: 'https://example.com/things' },
});

logger.error<MessageContext>({
  activity: 'Getting all the things',
  req: { method: 'GET', url: 'https://example.com/things' },
  err: {
    message: 'Unexpected error getting things',
  },
});

If logger is used with an object as first argument, please use req, res and err to log request, response and error respectively.

req and res objects are trimmed to contain only essential logging data.

All other objects passed will be logged directly.

For suggestions on enforcing logged object structures for consistency, see below.

The following trimming rules apply to all logging data:

  • All log structures deeper than 4 levels will be omitted from output.
    • Configure using the the maxObjectDepth LoggerOption.
  • All log structures (objects/arrays) with size bigger/longer than 64 will be trimmed.
  • All strings that are longer than 512 will be trimmed.
  • All buffers will be substituted with their string representations, eg. "Buffer(123)".

All Bearer tokens (regardless of their placement in the log object) will be redacted by the logger itself.

As trimming operations are not cheap please make sure your application logs only meaningful data which does not contain Buffers, deeply nested objects, large arrays or other large entities, because it might lead to significant performance issues of your application.

Pino

Library is utilising Pino. If you would like to customise your logging you could do so by providing options acceptable by pino while creating a logger like so:

import createLogger, { pino } from '@seek/logger';

const logger = createLogger(
  {
    name: 'my-app',
    ...myCustomPinoOptions,
  },
  myDestination,
);

const extremeLogger = createLogger({ name: 'my-app' }, pino.extreme());

Note: createLogger mutates the supplied destination in order to redact sensitive data.

Serializers

Library is utilizing standard pino serializers with custom req and res serialializers. If other serializers with same keys are provided to the library, they will take precedence over predefined ones.

Enforcing Logged Object Structures

If you would like to enforce the structure of objects being logged, define the interface to log and specify it as the generic type in the logger functions. Compatibility should be maintained with the existing serializer functions.

FAQs

Package last updated on 15 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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