Proteus Logger is a logging framework to support application logging.
This module collaborate with Proteus Cluster to support logging under the clustered environment (under the clustered environment, workers sends log data to the master, and master unify the log management).
Proteus Logger also provides date-time based file rotation in cluster environment.
To initialize logger, call configure() or define logger info using Proteus Configurator by setting configure key as "logger".
var proteusLogger = require('proteus-logger');
proteusLogger.configure({
appenders: {
console: { type: 'console' }
}
loggers: {
logger1: {
level: 'info',
appenders: ['console']
}
}
});
{
"appenders": {
"console": { "type": "console" }
},
"loggers": {
"category2": {
"level": "info",
"appenders": ["console"]
}
}
}
var logger = require('proteus-logger').get('category1');
logger.info('this is the information log');
logger.warn('this is the warning log');
logger.error('this is the error log', err);
require('proteus-logger').configure({
appenders: {
console: {
type: 'console',
layout: {
pattern: '%yyyy-%MM-%dd %HH:%mm:%ss %loggerc %msg %argsc (%linec)%nstack'
}
}
}
});
meta characters | comments |
---|---|
yyyy | Year (4 digits) |
MM | Month |
dd | Date |
HH | Hour (2 digits) |
mm | Minute (2 digits) |
ss | Seconds (2 digits) |
sss | Milliseconds (3 digits) |
T | Just 'T' to split date and time. |
level | Logged level |
levelc | Logged level (colored) |
logger | Logger name |
loggerc | Logger name (colored) |
msg | Logging message |
error | Error mesage |
stack | Stack trace of the error without line break. |
nstack | Stack trace of the error with line break before trace. |
line | File name and line number |
linec | File name and line number (colored) |
path | Relative path and line number |
pathc | Relative path and line number (colored) |
n | Line break |
proteusLogger.configure({
appenders: {
file: {
type: "dailyRotateFile",
filename: "rotated.log", // file to be appended
pattern: "rotated.%yyyy-%MM-%dd.log" // file to be replaced
}
},
"loggers": {
"category": {
"level": "info",
"appenders": ["file"]
}
}
});
According to the above settings, file will be created as "rotated.log" and rotated daily. Rotated files will be something like "rotated.2014-03-12.log". You can use the following meta characters in pattern.
meta characters | comments |
---|---|
yyyy | Year (4 digits) |
MM | Month (2 digits) |
dd | Day (2 digits) |
hh | Hours (2 digits) |
mm | Minutes (2 digits) |
Since pattern has hours and minutes, rotation interval can be modified in configuration. You can set interval property in milliseconds.
proteusLogger.configure({
appenders: {
file: {
type: "dailyRotateFile",
filename: "rotated.log", // file to be appended
pattern: "rotated.%yyyy-%MM-%dd-%hh.log" // file to be replaced,
interval: 3600000 // 1 hour interval
}
},
"loggers": {
"category": {
"level": "info",
"appenders": ["file"]
}
}
});
Copyright 2012 CyberAgent, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.