-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const path = require('path'); | ||
|
||
// publish config object to be used by tektrans-logger | ||
global.TEKTRANS_LOGGER_CONFIG = { | ||
level: 'silly', | ||
label: 'REDIS-EXAMPLE', | ||
|
||
// default is "logs" directory on current workdir | ||
directory: path.join(process.cwd(), 'logs'), | ||
|
||
filename: 'redis-log', | ||
|
||
// default is using generic level value | ||
console_level: null, | ||
|
||
// default is using generic level value | ||
file_level: null, | ||
|
||
// default is no old file removal | ||
max_files: '10d', | ||
|
||
redis: { | ||
host: 'localhost', | ||
port: 6379, | ||
auth: null, | ||
channel: null, | ||
}, | ||
}; | ||
|
||
const logger = require('..'); | ||
|
||
const sleep = (ms) => new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, ms); | ||
}); | ||
|
||
const main = async () => { | ||
// await sleep(2000); | ||
|
||
logger.silly('This is a silly log.'); | ||
logger.debug('This is a debug log.'); | ||
logger.verbose('This is a verbose log'); | ||
|
||
// looks like redis transport doesn't support log with metadata, | ||
// log with metadata will be skipped by redis transport | ||
logger.verbose('This is a verbose example of log with metadata', { | ||
a: 'metadata1', | ||
b: 'metadata2', | ||
c: { | ||
c1: 'compund', | ||
}, | ||
}); | ||
|
||
logger.http('This in a http log'); | ||
logger.info('This is an info log'); | ||
logger.warn('This is an warn log'); | ||
logger.error('This in an error'); | ||
|
||
// give few seconds to make sure all logs | ||
// has been emitted to redis before close the log | ||
await sleep(2000); | ||
|
||
// don't forget to close the logger at the end | ||
logger.end(); | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const WinstonRedis = require('winston-redis'); | ||
|
||
const config = require('../config'); | ||
|
||
const DEFAULT_REDIS_HOST = 'localhost'; | ||
const DEFAULT_REDIS_PORT = 6379; | ||
const DEFAULT_REDIS_AUTH = null; | ||
const DEFAULT_REDIS_CHANNEL = [ | ||
'TEKTRANS-LOGGER', | ||
'B707E453', | ||
(config.label || '').toUpperCase(), | ||
].filter((item) => item).join('_'); | ||
|
||
if (!config.redis) { | ||
module.exports = null; | ||
} else { | ||
if (typeof config.redis !== 'object') { | ||
config.redis = {}; | ||
} | ||
|
||
config.redis.level = config.redis.level || config.level; | ||
config.redis.host = config.redis.host || DEFAULT_REDIS_HOST; | ||
config.redis.port = config.redis.port || DEFAULT_REDIS_PORT; | ||
config.redis.auth = config.redis.auth || DEFAULT_REDIS_AUTH; | ||
config.redis.channel = config.redis.channel || DEFAULT_REDIS_CHANNEL; | ||
|
||
const options = { | ||
level: config.redis.level, | ||
host: config.redis.host, | ||
port: config.redis.port, | ||
auth: config.redis.auth, | ||
channel: config.redis.channel, | ||
meta: { | ||
pid: process.pid, | ||
}, | ||
}; | ||
|
||
const transport = new WinstonRedis(options); | ||
|
||
module.exports = transport; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters