@autofleet/node-common 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -35,3 +35,10 @@ RIDE_SERVICE_HOST=jsonplaceholder.typicode.com
35
35
  ```
36
36
 
37
37
  To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
38
+
39
+ ## Publish package
40
+ bump the version number in package.json
41
+ and run
42
+ ```
43
+ npm publish
44
+ ```
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
2
  Network: require('./network'),
3
+ Logger: require('./logger'),
3
4
  }
@@ -0,0 +1,31 @@
1
+ const winston = require('winston')
2
+
3
+ const createLogger = (logLevel) => {
4
+ let level = logLevel ? logLevel : 'info'
5
+ const logger = winston.createLogger({
6
+ level,
7
+ format: winston.format.simple(),
8
+ transports: [
9
+ //
10
+ // - Write to all logs with level `info` and below to `combined.log`
11
+ // - Write all logs error (and below) to `error.log`.
12
+ //
13
+ new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
14
+ new winston.transports.File({ filename: 'logs/combined.log' })
15
+ ]
16
+ });
17
+
18
+ //
19
+ // If we're not in production then log to the `console` with the format:
20
+ // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
21
+ //
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ logger.add(new winston.transports.Console({
24
+ format: winston.format.simple()
25
+ }));
26
+ }
27
+
28
+ return logger
29
+ }
30
+
31
+ module.exports = createLogger
package/logger/test.js ADDED
@@ -0,0 +1,4 @@
1
+ const logger = require('./index')('debug')
2
+ logger.info('it is working')
3
+ logger.error('errors displayed in logs/error.log')
4
+ logger.debug('debug with object', {a: 5})
package/network/index.js CHANGED
@@ -8,7 +8,7 @@ if (process.env.NODE_ENV === 'test') {
8
8
  axios.defaults.adapter = require('axios/lib/adapters/http')
9
9
  }
10
10
 
11
- const Methods = [
11
+ const HTTPMethods = [
12
12
  'get',
13
13
  'post',
14
14
  'delete',
@@ -55,6 +55,6 @@ module.exports = class Network {
55
55
  */
56
56
  buildClassHttpMethods() {
57
57
  this.axios = axios.create(this.settings);
58
- Methods.map((method) => this[method] = (...args) => this.axios[method](...args))
58
+ HTTPMethods.map((method) => this[method] = (...args) => this.axios[method](...args))
59
59
  }
60
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/node-common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "homepage": "https://gitlab.com/AutoFleet/node-common#README",
19
19
  "dependencies": {
20
- "axios": "^0.18.0"
20
+ "axios": "^0.18.0",
21
+ "winston": "^3.0.0-rc5"
21
22
  }
22
23
  }