@sentio/runtime 2.11.0-rc.7 → 2.11.0

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.
@@ -0,0 +1 @@
1
+ export declare function setupJsonLogger(): void;
package/lib/logger.js ADDED
@@ -0,0 +1,26 @@
1
+ import util from 'util';
2
+ import { createLogger, format, transports } from 'winston';
3
+ export function setupJsonLogger() {
4
+ const utilFormatter = {
5
+ transform: (info) => {
6
+ const args = info[Symbol.for('splat')];
7
+ if (args) {
8
+ info.message = util.format(info.message, ...args);
9
+ }
10
+ else {
11
+ info.message = util.format(info.message);
12
+ }
13
+ return info;
14
+ },
15
+ };
16
+ const logger = createLogger({
17
+ format: format.combine(format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), utilFormatter, format.errors({ stack: true }), format.json()),
18
+ transports: [new transports.Console()],
19
+ });
20
+ console.log = (...args) => logger.info.call(logger, ...args);
21
+ console.info = (...args) => logger.info.call(logger, ...args);
22
+ console.warn = (...args) => logger.warn.call(logger, ...args);
23
+ console.error = (...args) => logger.error.call(logger, ...args);
24
+ console.debug = (...args) => logger.debug.call(logger, ...args);
25
+ }
26
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE1D,MAAM,UAAU,eAAe;IAC7B,MAAM,aAAa,GAAG;QACpB,SAAS,EAAE,CAAC,IAAS,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;YACtC,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,G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port { createLogger, format, transports } from 'winston'\n\nexport function setupJsonLogger() {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n } else {\n info.message = util.format(info.message)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.test.js","sourceRoot":"","sources":["../src/logger.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC5B,eAAe,EAAE,CAAA;QACjB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACpB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAEnB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { setupJsonLogger } from './logger.js'\n\ndescribe('Test logger', () => {\n test('check log output', () => {\n setupJsonLogger()\n console.log('asdf')\n console.log(console)\n console.log('asdf')\n\n console.log({ a: 'asdf', b: 'Asdf' })\n })\n})\n"]}
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'path';
3
3
  import fs from 'fs-extra';
4
- import * as util from 'util';
5
4
  import commandLineArgs from 'command-line-args';
6
5
  import { createServer } from 'nice-grpc';
7
- import { createLogger, transports, format } from 'winston';
8
6
  import { compressionAlgorithms } from '@grpc/grpc-js';
9
7
  import { register as globalRegistry, Registry } from 'prom-client';
10
8
  import { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus';
@@ -14,6 +12,7 @@ import { ProcessorDefinition } from './gen/processor/protos/processor.js';
14
12
  import { ProcessorServiceImpl } from './service.js';
15
13
  import { Endpoints } from './endpoints.js';
16
14
  import { FullProcessorServiceImpl } from './full-service.js';
15
+ import { setupJsonLogger } from './logger.js';
17
16
  const optionDefinitions = [
18
17
  { name: 'target', type: String, defaultOption: true },
19
18
  { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
@@ -32,24 +31,7 @@ const optionDefinitions = [
32
31
  ];
33
32
  const options = commandLineArgs(optionDefinitions, { partial: true });
34
33
  if (options['log-format'] === 'json') {
35
- const utilFormatter = {
36
- transform: (info) => {
37
- const args = info[Symbol.for('splat')];
38
- if (args) {
39
- info.message = util.format(info.message, ...args);
40
- }
41
- return info;
42
- },
43
- };
44
- const logger = createLogger({
45
- format: format.combine(format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), utilFormatter, format.errors({ stack: true }), format.json()),
46
- transports: [new transports.Console()],
47
- });
48
- console.log = (...args) => logger.info.call(logger, ...args);
49
- console.info = (...args) => logger.info.call(logger, ...args);
50
- console.warn = (...args) => logger.warn.call(logger, ...args);
51
- console.error = (...args) => logger.error.call(logger, ...args);
52
- console.debug = (...args) => logger.debug.call(logger, ...args);
34
+ setupJsonLogger();
53
35
  }
54
36
  if (options.debug) {
55
37
  console.log('Starting with', options.target);
@@ -1 +1 @@
1
- {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;A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AG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzD,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,UAAU,GAAG,IAAI;KACpB,YAAY,CAAC,KAAK,WAAW,GAAG,EAAE,GAAG;IACpC,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,KAAK,UAAU,EAAE;QACrF,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;QAC9C,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACnB;SAAM;QACL,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;KACnB;IACD,GAAG,CAAC,GAAG,EAAE,CAAA;AACX,CAAC,CAAC;KACD,MAAM,CAAC,WAAW,CAAC,CAAA;AAEtB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAA;AAErD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE;IACnB,MAAM,CAAC,aAAa,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAEnC,UAAU,CAAC,KAAK,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { register as globalRegistry, Registry } from 'prom-client'\nimport { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'\nimport http from 'http'\n\nconst mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])\n\nimport { ProcessorDefinition } from './gen/processor/protos/processor.js'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n}).use(prometheusServerMiddleware())\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n\nconst metricsPort = 4040\nconst httpServer = http\n .createServer(async function (req, res) {\n if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {\n const metrics = await mergedRegistry.metrics()\n res.write(metrics)\n } else {\n res.writeHead(404)\n }\n res.end()\n })\n .listen(metricsPort)\n\nconsole.log('Metric Server Started at:', metricsPort)\n\nprocess.on('SIGINT', function () {\n server.forceShutdown()\n console.log('RPC server shut down')\n\n httpServer.close(function () {\n console.log('Http server shut down')\n process.exit(0)\n })\n})\n"]}
1
+ {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eA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C,IAAI,EAAE,CAAC,CAAC,QAAQ,KAAK,UAAU,EAAE;QACrF,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;QAC9C,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACnB;SAAM;QACL,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;KACnB;IACD,GAAG,CAAC,GAAG,EAAE,CAAA;AACX,CAAC,CAAC;KACD,MAAM,CAAC,WAAW,CAAC,CAAA;AAEtB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAA;AAErD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE;IACnB,MAAM,CAAC,aAAa,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAEnC,UAAU,CAAC,KAAK,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { register as globalRegistry, Registry } from 'prom-client'\nimport { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'\nimport http from 'http'\n\nconst mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])\n\nimport { ProcessorDefinition } from './gen/processor/protos/processor.js'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\nimport { setupJsonLogger } from './logger.js'\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n setupJsonLogger()\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n}).use(prometheusServerMiddleware())\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n\nconst metricsPort = 4040\nconst httpServer = http\n .createServer(async function (req, res) {\n if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {\n const metrics = await mergedRegistry.metrics()\n res.write(metrics)\n } else {\n res.writeHead(404)\n }\n res.end()\n })\n .listen(metricsPort)\n\nconsole.log('Metric Server Started at:', metricsPort)\n\nprocess.on('SIGINT', function () {\n server.forceShutdown()\n console.log('RPC server shut down')\n\n httpServer.close(function () {\n console.log('Http server shut down')\n process.exit(0)\n })\n})\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
3
  "license": "Apache-2.0",
4
- "version": "2.11.0-rc.7",
4
+ "version": "2.11.0",
5
5
  "scripts": {
6
6
  "compile": "tsc",
7
7
  "build": "yarn compile",
@@ -13,7 +13,7 @@
13
13
  "start_js": "ts-node-esm --files ./lib/processor-runner.js $PWD/../../debug/dist/lib.js"
14
14
  },
15
15
  "dependencies": {
16
- "@sentio/protos": "^2.11.0-rc.7",
16
+ "@sentio/protos": "^2.11.0",
17
17
  "command-line-args": "^5.2.1",
18
18
  "command-line-usage": "^7.0.1",
19
19
  "fs-extra": "^11.0.0",
@@ -45,5 +45,5 @@
45
45
  "!{lib,src}/tests",
46
46
  "!**/*.test.{js,ts}"
47
47
  ],
48
- "gitHead": "ed1100b3d58c22865b6afd24af6a57c07059e582"
48
+ "gitHead": "5a8d13d49176b40f23c941261146dc4a246e720e"
49
49
  }
package/src/logger.ts ADDED
@@ -0,0 +1,31 @@
1
+ import util from 'util'
2
+ import { createLogger, format, transports } from 'winston'
3
+
4
+ export function setupJsonLogger() {
5
+ const utilFormatter = {
6
+ transform: (info: any) => {
7
+ const args = info[Symbol.for('splat')]
8
+ if (args) {
9
+ info.message = util.format(info.message, ...args)
10
+ } else {
11
+ info.message = util.format(info.message)
12
+ }
13
+ return info
14
+ },
15
+ }
16
+ const logger = createLogger({
17
+ format: format.combine(
18
+ format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),
19
+ utilFormatter,
20
+ format.errors({ stack: true }),
21
+ format.json()
22
+ ),
23
+ transports: [new transports.Console()],
24
+ })
25
+
26
+ console.log = (...args) => logger.info.call(logger, ...args)
27
+ console.info = (...args) => logger.info.call(logger, ...args)
28
+ console.warn = (...args) => logger.warn.call(logger, ...args)
29
+ console.error = (...args) => logger.error.call(logger, ...args)
30
+ console.debug = (...args) => logger.debug.call(logger, ...args)
31
+ }
@@ -2,11 +2,9 @@
2
2
 
3
3
  import path from 'path'
4
4
  import fs from 'fs-extra'
5
- import * as util from 'util'
6
5
 
7
6
  import commandLineArgs from 'command-line-args'
8
7
  import { createServer } from 'nice-grpc'
9
- import { createLogger, transports, format } from 'winston'
10
8
  import { compressionAlgorithms } from '@grpc/grpc-js'
11
9
 
12
10
  import { register as globalRegistry, Registry } from 'prom-client'
@@ -21,6 +19,7 @@ import { Endpoints } from './endpoints.js'
21
19
 
22
20
  import { FullProcessorServiceImpl } from './full-service.js'
23
21
  import { ChainConfig } from './chain-config.js'
22
+ import { setupJsonLogger } from './logger.js'
24
23
 
25
24
  const optionDefinitions = [
26
25
  { name: 'target', type: String, defaultOption: true },
@@ -42,30 +41,7 @@ const optionDefinitions = [
42
41
  const options = commandLineArgs(optionDefinitions, { partial: true })
43
42
 
44
43
  if (options['log-format'] === 'json') {
45
- const utilFormatter = {
46
- transform: (info: any) => {
47
- const args = info[Symbol.for('splat')]
48
- if (args) {
49
- info.message = util.format(info.message, ...args)
50
- }
51
- return info
52
- },
53
- }
54
- const logger = createLogger({
55
- format: format.combine(
56
- format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),
57
- utilFormatter,
58
- format.errors({ stack: true }),
59
- format.json()
60
- ),
61
- transports: [new transports.Console()],
62
- })
63
-
64
- console.log = (...args) => logger.info.call(logger, ...args)
65
- console.info = (...args) => logger.info.call(logger, ...args)
66
- console.warn = (...args) => logger.warn.call(logger, ...args)
67
- console.error = (...args) => logger.error.call(logger, ...args)
68
- console.debug = (...args) => logger.debug.call(logger, ...args)
44
+ setupJsonLogger()
69
45
  }
70
46
  if (options.debug) {
71
47
  console.log('Starting with', options.target)