Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

log4js-node supports Koa-middleware

License

NotificationsYou must be signed in to change notification settings

dominhhai/koa-log4js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A wrapper forlog4js-node which supportKoa logger middleware.Log message is forked from Express (Connect) loggerfile.

Note

This branch is use toKoa v2.x.To use Koa v0.x & v1.x, please check themaster branch.

Installation

for koa v0.x & v1.x

$ npm i --save koa-log4@1

for koa v2.x

$ npm i --save koa-log4@2

The default logger is forkoa v2.x

$ npm i --save koa-log4

Usage

Config koa-log4js is same as the originallog4js-node.

Normal log4js way

This way is same as the originallog4js-node.

constlog4js=require('koa-log4')constlog=log4js.getLogger('index')log.info('index do some awesome things')

Koa-middleware way

Similar to use Express (Connect) logger middleware.

constlog4js=require('koa-log4')app.use(log4js.koaLogger(log4js.getLogger("http"),{level:'auto'}))

There are more configuration options:

constlog4js=require("koa-log4")app.use(log4js.koaLogger(// the logger to log tolog4js.getLogger("http"),// the options object{// select the level all access logs will be set to, or use "auto" to choose depending on the status code (see next option)level:"auto",// if `level` is set to "auto" the default rule will map 200-299 to INFO, 300-399 to WARN and 400-599 to ERROR.// you can override this behavior by setting your own custom levelMapper.// (the example is the default implementation, do not copy unless you want to modify it)levelMapper:function(statusCode){if(statusCode>=400)returnlevels.ERRORif(statusCode>=300)returnlevels.WARNreturnlevels.INFO}}))

Full Example

Checkthis repo for full example withKoa v2.

Others

Seehere for more info.

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp