0.0.6 • Published 5 years ago

self-log v0.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

self-log

Language

English | Chinese.

Description

The logs based on log4js.

Installation

// npm
npm install self-log

// yarn
yarn add self-log

Use

1. self-log

Use self-log logs.

const SelfLog = require('self-log');
const selfLog = new SelfLog(filename);

# use self-log default category 'app'
selfLog.debug('debug')
selfLog.info('info')
selfLog.warn('warn')
selfLog.error('error')

# getLogger
const logger = SelfLog.getLogger('test');

logger.debug();
  • filename: String - Optional; Log file path; If the filename parameter is passed, the infowarnerror logs will output to console and filename.log.
  • getLogger: see log4js-getLogger getLogger

2. self-log + log4js

log4js configuration with self-log then use log4js logger.

Install log4js
yarn add log4js
Use
const log4js = require('log4js');
new (require('self-log'))(filename);
const logger = log4js.getLogger('test');

logger.debug();
  1. Use in koa
var koa = require('koa');
var selfLog = new (require('self-log'))('app');

var app = koa();
app.use(selfLog.requestLogger()); //Logs requests and responses.

app.use(function (ctx, next) {
  selfLog.info('Got a request from %s for %s', ctx.request.ip, ctx.path);
  return next();
});

app.listen(8000);

Note: self-log does not record static resource logs. Exclude ['js', 'css', 'jpg', 'png', 'html', 'ico', 'map'].

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago