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

express-log-middleware

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-log-middleware

### 说明

  • 1.1.8
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

express-log-middleware

说明

app.use(
	require('express-log-middleware')(config)
);

nametypedescription
config.modelstring项目模板名称(用于指定Elasticsearch中的index) 必填项
config.levelstring日志输出级别
config.logDirstring日志输出路径
config.getBusinessDatafunction获取业务专有数据(这些数据会一同发送到日志服务) 参数 params req
config.onParamsfunction对缺省params进行处理,返回处理后params 参数 params req
config.filterfunction过滤函数,不提供此函数或返回true代表需要输出日志 参数 req
config.logEnvstring日志环境 目前EFK/ELK 项目迁移进openshift之后使用其中集成的EFK不用再使用log4js收集日志; default: "ELK"

使用实例

不对参数进行处理
//logEnv = "EFK"
app.use(
  require('express-log-middleware')({logEnv: 'EFK'}); //如果logEnv是EFK, 只用这一个配置即可;
)

//logEnv = "ELK"
app.use(
	require('express-log-middleware')({model: 'education_cloud'})
);  
使用onParams 定制参数
app.use(
require('express-log-middleware')({
		model: 'education_cloud',
		onParams: (params,req) => ({userId:req.user.id})
	})
);
使用getBusinessData 增加额外信息
app.use(require('express-log-middleware')({
  model: 'education_cloud',
  getBusinessData: function (params, req) {
    let user = req.user || {};
    const customer = req.customer || {};
    return {
      userId: user.id || -1,
      customeUrl:customer.url || '-'
    }
  }
}));
logEnv->ELK debug
req.logger.log('xxx')
req.logger.error('xxx')

logEnv->EFK debug
console.log(JSON.stringify({})); //如果输出日志是jsonstring, EFK会处parse之后提取key/value
console.log('this is a test');   //字符串输出 

console.warn('debug尽量不要换行输出');

FAQs

Package last updated on 27 Aug 2018

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