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

slf

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slf

Simple Logging Facade

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.8K
decreased by-31.95%
Maintainers
1
Weekly downloads
 
Created
Source

slf

Surikat Log Facade

Install

npm install --save slf

API

Get a logger

import { LoggerFactory } from 'slf';

const log = LoggerFactory.getLogger('name');

const log = LoggerFactory.getLogger('name:subname:subsubname');

Logging

log('Hello!'); // As level info
log.log('info', 'Hello!'); // as level info
log.log('Hello!'); // as level info (implicit)

log.trace('My Trace');
log.debug('My Debug');
log.info('My Info');
log.warn('My Warning');
log.error('My Error');
log.critical('My Critical Error');

Formatting

Using util.format(...)

  • %s - String.
  • %d - Number (both integer and float).
  • %j - JSON. Replaced with the string '[Circular]' if the argument contains circular references.
  • %% - single percent sign ('%'). This does not consume an argument.
log.info('My Formatted %s', 'Message')
>> 'My Formatted Message'
log.info('My Formatted %d', 123)
>> 'My Formatted 123'
log.info('My Formatted %d', 123)
>> 'My Formatted 123'

Json Formatting

log.info({ a: 'aloha' })
>> { a: 'aloha' }
log.info('My Formatted %d', 123)
>> 'My Formatted 123'
log.info('My Formatted %d', 123)
>> 'My Formatted 123'

Configuring a Provider

LoggerFactory.setFactory(<factory-function>);
LoggerFacotry.setFactory(ConsoleLogger);

Log Levels

When setting a factory provider, you can also set a level to ensure not to send logs if the level is too low.

Set Level
LoggerFacotry.setFactory(ConsoleLogger, Level.Info);
Hierarchy
  • Critical
  • Error
  • Warn
  • Info
  • Debug

Writing a Provider

SLF is nothing without a backing logging implementation. The most tiny implementation of a console.log based implementation is shipped with SLF

API

factory-function has the following signature:

function(loggerName) {
  return function(event) {
    //do something with logEvent
  }
}
event = {
  timeStamp: 123456767,
  params: [],
  name: 'logger:name'
  level: 'error'
}

Keywords

FAQs

Package last updated on 04 Oct 2022

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