@things-factory/env 5.0.0-alpha.4 → 5.0.0-alpha.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/logger.js CHANGED
@@ -1,3 +1,6 @@
1
+ const Raygun = require('./winston-raygun')
2
+ const moment = require('moment-timezone')
3
+
1
4
  var config = require('./config')
2
5
  var { createLogger, format, transports } = require('winston')
3
6
  require('winston-daily-rotate-file')
@@ -5,6 +8,7 @@ require('winston-daily-rotate-file')
5
8
  const { combine, timestamp, splat, simple, printf } = format
6
9
 
7
10
  var { file: fileConfig, console: consoleConfig } = config.get('logger', {})
11
+ var { apiKey: RaygunApiKey } = config.get('raygun', {})
8
12
 
9
13
  var logTransports = []
10
14
 
@@ -27,11 +31,25 @@ if (consoleConfig) {
27
31
  logTransports.push(new transports.Console(Object.assign({}, CONSOLE_LOGGER_CONFIG, consoleConfig)))
28
32
  }
29
33
 
34
+ if (RaygunApiKey) {
35
+ logTransports.push(
36
+ new Raygun({
37
+ apiKey: RaygunApiKey
38
+ })
39
+ )
40
+ }
41
+
42
+ const SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone
43
+ const systemTimestamp = format((info, opts) => {
44
+ if (opts.tz) info.timestamp = moment().tz(opts.tz).format()
45
+ return info
46
+ })
47
+
30
48
  const logFormat = printf(({ level, message, timestamp }) => {
31
49
  return `${timestamp} ${level}: ${message}`
32
50
  })
33
51
 
34
52
  module.exports = createLogger({
35
- format: combine(timestamp(), splat(), logFormat),
53
+ format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), logFormat),
36
54
  transports: logTransports
37
55
  })
@@ -0,0 +1,26 @@
1
+ const Transport = require('winston-transport')
2
+ const raygun = require('raygun')
3
+
4
+ module.exports = class Raygun extends Transport {
5
+ constructor(opts) {
6
+ super(opts)
7
+
8
+ var opts = opts || {}
9
+ this.name = 'raygun'
10
+ this.apiKey = opts.apiKey
11
+
12
+ this.raygunClient = opts.raygunClient || new raygun.Client().init({ apiKey: this.apiKey })
13
+ }
14
+
15
+ log(info, callback) {
16
+ setImmediate(() => {
17
+ this.emit('logged', info)
18
+ })
19
+
20
+ if (info.level === 'error') {
21
+ return this.raygunClient.send(info)
22
+ }
23
+
24
+ callback()
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/env",
3
- "version": "5.0.0-alpha.4",
3
+ "version": "5.0.0-alpha.42",
4
4
  "description": "Things Factory running environment helper library",
5
5
  "main": "index.js",
6
6
  "author": "heartyoh@hatiolab.com",
@@ -22,9 +22,10 @@
22
22
  "dependency-solver": "^1.0.6",
23
23
  "fs-extra": "^9.0.1",
24
24
  "loader-utils": "^1.2.3",
25
+ "raygun": "^0.13.2",
25
26
  "schema-utils": "^1.0.0",
26
27
  "winston": "^3.2.1",
27
28
  "winston-daily-rotate-file": "^4.2.1"
28
29
  },
29
- "gitHead": "77253f86954dc6f5c14356ea85887c323fd2511a"
30
+ "gitHead": "ce348ff1299a244b261a9285290597b9be6c8e80"
30
31
  }