egg-logger-remote
v1.1.0
Published
Logger transport for remote server
Downloads
9
Readme
egg-logger-remote
Install
$ npm i egg-logger-remote --save
Usage
// {app_root}/config/plugin.js
exports.loggerRemote = {
enable: true,
package: 'egg-logger-remote',
};
Configuration
// {app_root}/config/config.default.js
exports.loggerRemote = {
};
see config/config.default.js for more detail.
Disable Logger
You and disable logger with disable
config.
exports.loggerRemote = {
disable: [
// won't upload this logger
'myLogger',
],
}
Transform and Filter
You can transform the log data before upload.
exports.loggerRemote = {
transform(log, args) {
return log;
},
}
If you want to ignore some log, you can return false when transform.
exports.loggerRemote = {
transform(log) {
if (some condition) return false;
return log;
},
}
There is two arguments that transform have.
- One is log object, it contains the default property, which is
ip
,hostname
,env
,appName
,loggerName
,loggerFileName
,level
. The last one iscontent
that is the log string formated from the arguments when you call log method. - The other is original arguments when you call log method, it will not format to content.
Data Structure
The data structure uploaded in below, you can create index in aliyun console as your wish.
- level: logger level
- content: the infomation that you logged
- ip: the host ip
- hostname: the host name
- env: the egg environment
- appName: the package name
- loggerName: the logger name defined by Egg
- loggerFileName: the logger file path
Logger Level
The default logger in Egg contains two level: level and consoleLevel, If you want set level for sls, you can use slsLevel
.
// config/config.default.js
module.exports = {
loggerRemote: {
// for all logs
remoteLevel: 'DEBUG',
},
};
If slsLevel
is not specified, it will use level instead.
Example
Questions & Suggestions
Please open an issue here.