Compare View
Commits (2)
Changes
Showing 2 changed files Inline Diff
logger.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const fs = require('fs'); | 3 | const fs = require('fs'); |
4 | const strftime = require('strftime'); | 4 | const strftime = require('strftime'); |
5 | const winston = require('winston'); | 5 | const winston = require('winston'); |
6 | 6 | ||
7 | require('winston-daily-rotate-file'); | 7 | require('winston-daily-rotate-file'); |
8 | require('winston-circular-buffer'); | 8 | require('winston-circular-buffer'); |
9 | 9 | ||
10 | const config = require('./config'); | 10 | const config = require('./config'); |
11 | 11 | ||
12 | const loggerTimestamp = function() { | 12 | const loggerTimestamp = function() { |
13 | return strftime('%F %T', new Date()); | 13 | return strftime('%F %T', new Date()); |
14 | } | 14 | } |
15 | 15 | ||
16 | const logDirectory = process.cwd() + '/logs'; | ||
17 | const filenamePrefix = logDirectory + "/" + (process.env.KOMODO_LOG_FILENAME || "/log"); | ||
18 | 16 | const logDirectory = process.cwd() + '/logs'; | |
19 | fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory); | 17 | const filenamePrefix = logDirectory + "/" + (process.env.KOMODO_LOG_FILENAME || "/log"); |
20 | 18 | ||
21 | const logger = new winston.Logger({ | 19 | fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory); |
22 | transports: [ | 20 | |
23 | new (winston.transports.Console)({ | 21 | const logger = new winston.Logger({ |
24 | timestamp: process.stdout.isTTY ? loggerTimestamp : null, | 22 | transports: [ |
25 | level: 'verbose', | 23 | new (winston.transports.Console)({ |
26 | }), | 24 | timestamp: process.stdout.isTTY ? loggerTimestamp : null, |
27 | |||
28 | new (winston.transports.DailyRotateFile) ({ | ||
29 | name: 'log-file-txt', | 25 | level: 'verbose', |
30 | filename: filenamePrefix, | 26 | }), |
31 | timestamp: loggerTimestamp, | 27 | |
32 | formatter: function(options) { | 28 | new (winston.transports.DailyRotateFile) ({ |
33 | return options.timestamp() | 29 | name: 'log-file-txt', |
34 | +' ' + options.level.toUpperCase() | 30 | filename: filenamePrefix, |
35 | +' ' + (undefined !== options.message ? options.message : '') | 31 | timestamp: loggerTimestamp, |
36 | + (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '' ); | 32 | formatter: function(options) { |
37 | }, | 33 | return options.timestamp() |
38 | level: 'debug', | 34 | +' ' + options.level.toUpperCase() |
39 | }), | 35 | +' ' + (undefined !== options.message ? options.message : '') |
40 | 36 | + (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '' ); | |
41 | new (winston.transports.CircularBuffer) ({ | 37 | }, |
42 | name: 'logs', | 38 | level: 'debug', |
43 | level: "verbose", | 39 | }), |
44 | json: true, | 40 | |
45 | size: 500 | 41 | new (winston.transports.CircularBuffer) ({ |
46 | }) | 42 | name: 'logs', |
47 | ] | 43 | level: "verbose", |
48 | }); | 44 | json: true, |
49 | 45 | size: 500 | |
50 | logger.verbose(__filename + ': initialized'); | 46 | }) |
51 | 47 | ] | |
52 | require('./logger-circular-buffer-web'); | 48 | }); |
53 | 49 | ||
54 | module.exports = logger; | 50 | logger.verbose(__filename + ': initialized'); |
55 | 51 |
package.json
1 | { | 1 | { |
2 | "name": "komodo-sdk", | 2 | "name": "komodo-sdk", |
3 | "version": "1.14.6", | 3 | "version": "1.15.0", |
4 | "description": "SDK for Komodo", | 4 | "description": "SDK for Komodo", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "mocha", | 7 | "test": "mocha", |
8 | "postversion": "git push && git push --tags" | 8 | "postversion": "git push && git push --tags" |
9 | }, | 9 | }, |
10 | "repository": { | 10 | "repository": { |
11 | "type": "git", | 11 | "type": "git", |
12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" | 12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" |
13 | }, | 13 | }, |
14 | "keywords": [ | 14 | "keywords": [ |
15 | "ppob", | 15 | "ppob", |
16 | "payment", | 16 | "payment", |
17 | "komodo" | 17 | "komodo" |
18 | ], | 18 | ], |
19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", | 19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", |
20 | "license": "ISC", | 20 | "license": "ISC", |
21 | "dependencies": { | 21 | "dependencies": { |
22 | "basic-auth": "^2.0.0", | 22 | "basic-auth": "^2.0.0", |
23 | "body-parser": "^1.18.2", | 23 | "body-parser": "^1.18.2", |
24 | "express": "^4.16.2", | 24 | "express": "^4.16.2", |
25 | "express-session": "^1.15.6", | 25 | "express-session": "^1.15.6", |
26 | "lru-cache": "^4.1.1", | 26 | "lru-cache": "^4.1.1", |
27 | "moment": "^2.19.1", | 27 | "moment": "^2.19.1", |
28 | "node-natural-sort": "^0.8.6", | 28 | "node-natural-sort": "^0.8.6", |
29 | "numeral": "^2.0.6", | 29 | "numeral": "^2.0.6", |
30 | "nunjucks": "^3.0.1", | 30 | "nunjucks": "^3.0.1", |
31 | "redis": "^2.8.0", | 31 | "redis": "^2.8.0", |
32 | "request": "^2.81.0", | 32 | "request": "^2.81.0", |
33 | "simple-git": "^1.80.1", | 33 | "simple-git": "^1.80.1", |
34 | "strftime": "^0.10.0", | 34 | "strftime": "^0.10.0", |
35 | "uniqid": "^4.1.1", | 35 | "uniqid": "^4.1.1", |
36 | "uuid": "^3.1.0", | 36 | "uuid": "^3.1.0", |
37 | "winston": "^2.3.1", | 37 | "winston": "^2.3.1", |
38 | "winston-circular-buffer": "^1.0.0", | 38 | "winston-circular-buffer": "^1.0.0", |
39 | "winston-daily-rotate-file": "^1.4.6" | 39 | "winston-daily-rotate-file": "^1.4.6" |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 |