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

elecpen

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elecpen

a simple logger

  • 0.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ElecPen

Build Status npm version

We take logger as a function to receive a record and output to a stream, and elecPen is a simple logger creator.

API

elecPen(writable, prefix, dateFormat)

ParamDescription
writablesOne or an array of writable stream for logging
prefixThe prefix of the record
dateFormatDate format for logger or pass true to use the default format

Default logger

A set of logger is provided by a default logger creator which provide some useful logger like info or error.

Options

OptionTypeDescription
infoFilestring, functionFile name for logging info and verbose
errFilestring, functionFile name for logging error and warning
timestampstring, booleanDate format for logger or pass true to use the default format
appendbooleanIf file exists, append new entries to it instead of truncating
logToConsolebooleanOutput the message to console, it will be default to true in dev mode

Methods

  • logger.verbose
  • logger.info
  • logger.warning
  • logger.error

Example

You can you a set of default logger:

// use default logger
const opts = {
  infoFile: 'info.log',  // record info and verbose
  errFile: 'err.log', // record error and warning
  timestamp: true,
  append: true // default to true
}
const http = requrie('http')
const logger = require('elecpen').defaultLogger(opts)

http.createServer((req, res) => {
  logger.info('Recieve a request. Path: %s', req.path)
  res.end('Hello world.')
})
.listen(4000, _ => {
  logger.info('Server listening...')
})

Dynamic file name is supported, and it is useful to record log by separated file.

const opts = {
  infoFile () {
    const now = new Date()
    return `log-${now.getFullYear()}-${now.getMonth() + 1}`
  },
  errFile: 'err.log'
}
const logger = require('elecpen').defaultLogger(opts)
logger.info('Hello World!')

Or create you own logger:

const fs = require('fs')
const elecpen = require('elecpen')
const recorder = elecpen.streamRecorder()

const log = function (msg) {
  // dynamic stream
  const stream = recorder(
    _ => `log-${Date.now()}.log`,
    name => fs.createWriteStream(name, { flags: 'a' })
  )
  stream && elecpen(stream, 'Message', timestamp)(msg)
}
log('Hello World!')

License

MIT

Keywords

FAQs

Package last updated on 14 Feb 2016

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