Socket
Book a DemoInstallSign in
Socket

logger-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logger-interceptor

### Install

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
16
45.45%
Maintainers
1
Weekly downloads
 
Created
Source

Logger Interceptor

Install

npm i logger-interceptor

Examples

  • With console
const interceptor = new LoggerInterceptor(console)

interceptor.on(({ logger, ...instance }) => {
  logger.log(JSON.stringify(instance))
})

console.log("test log")
console.info("test info")
console.error("test error")
console.warn("test warn")
console.table("test table")
console.debug("test debug")

// logs
/*
{"date":"2024-01-24T10:34:23.244Z","type":"log","timestamp":"1/24/2024, 12:34:23 PM","messages":["test log"]}
test log
{"date":"2024-01-24T10:34:23.260Z","type":"info","timestamp":"1/24/2024, 12:34:23 PM","messages":["test info"]}
test info
{"date":"2024-01-24T10:34:23.260Z","type":"error","timestamp":"1/24/2024, 12:34:23 PM","messages":["test error"]}
test error
{"date":"2024-01-24T10:34:23.261Z","type":"warn","timestamp":"1/24/2024, 12:34:23 PM","messages":["test warn"]}
test warn
{"date":"2024-01-24T10:34:23.261Z","type":"log","timestamp":"1/24/2024, 12:34:23 PM","messages":["test table"]}
test table
{"date":"2024-01-24T10:34:23.261Z","type":"debug","timestamp":"1/24/2024, 12:34:23 PM","messages":["test debug"]}
test debug
*/
  • With Custom Logger
const customLogger = {
  log: console.log.bind(console),
  warn: console.warn.bind(console),
  error: console.error.bind(console),
}
const interceptor = new LoggerInterceptor(customLogger)

interceptor.on(({ logger, ...instance }) => {
  logger.log(JSON.stringify(instance))
})

customLogger.log("test log")
customLogger.info("test info")
customLogger.error("test error")
customLogger.warn("test warn")
customLogger.table("test table")
customLogger.debug("test debug")

// logs
/*
{"date":"2024-01-24T10:37:43.564Z","type":"log","timestamp":"1/24/2024, 12:37:43 PM","messages":["test log"]}
test log
{"date":"2024-01-24T10:37:43.578Z","type":"error","timestamp":"1/24/2024, 12:37:43 PM","messages":["test error"]}
test error
{"date":"2024-01-24T10:37:43.578Z","type":"warn","timestamp":"1/24/2024, 12:37:43 PM","messages":["test warn"]}
test warn
*/

Keywords

logger

FAQs

Package last updated on 24 Jan 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.