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

@tng/ilog

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tng/ilog - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

28

index.js

@@ -10,6 +10,12 @@ const ilog = require('ilog')

* 日志中间件
* @param {String} serviceName 服务名称
* @param {function} parseClientFunction 解析客户端的函数
* @param {String} name 服务名称
* @param {Function} parseClientFunction 解析客户端的函数
* @param {Array} ignores 忽略的路由规则
* @param {Array} ignoreMethods 忽略的方法, 默认是 OPTIONS
*/
module.exports = function (serviceName, parseClientFunction = getClient) {
module.exports = function (options = {}) {
let serviceName = options.name || UNKNOWN_SERVICE
let parseClientFunction = options.parseClientFunction || getClient
let ignoreRoutes = options.ignores || ['/favicon.ico', '/version', '/assets']
let ignoreMethods = options.ignoreMethods || ['options']
if (typeof parseClientFunction !== 'function') {

@@ -26,10 +32,10 @@ throw new Error('getClientFunction must be a function')

// log uncaught downstream errors
log.call(this, start)
log.call(this, start, ignoreRoutes, ignoreMethods)
throw err
}
log.call(this, start)
log.call(this, start, ignoreRoutes, ignoreMethods)
}
}
function log (start) {
function log (start, ignoreRoutes, ignoreMethods) {
let ctx = this

@@ -50,2 +56,12 @@ let client = ctx.state.client

}
// 忽略的地址不做日志记录
if (ignoreRoutes.length && ignoreRoutes.some((ele) => {
return api.includes(ele)
})) {
return
}
// 跨域忽略
if (ignoreMethods.includes(method.toLowerCase())) return
ilog.info({

@@ -52,0 +68,0 @@ class: 'ilog',

{
"name": "@tng/ilog",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,3 +8,3 @@ TNG ilog 中间件

require('@tng/ilog)('Teambition X App')
require('@tng/ilog)({ name: 'Service Name' })
```

@@ -16,8 +16,13 @@

ilog('Client Name', function (ctx) {
if (_.result(ctx.state, 'consumer._id')) {
return ctx.state.consumer.name + '_' + ctx.state.consumer.clientKey
ilog({
name: 'Client Name',
ignoreRoutes: ['/version'], // 不打印日志的路由
ignoreMethods: ['GET', 'OPTIONS'], // 默认是 ['OPTIONS']
parseClientFunction: function (ctx) {
if (_.result(ctx.state, 'consumer._id')) {
return ctx.state.consumer.name + '_' + ctx.state.consumer.clientKey
}
return null
}
return null
})
```
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