dcp-worker 3.2.30-2 → 3.2.30-4

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.
@@ -4,66 +4,45 @@
4
4
  * @date August 2022
5
5
  *
6
6
  * This logger module emits log lines to a remote syslogd, writing all
7
- * console logs to it. Most worker events are passed through to be handled
8
- * by the console logger.
9
- *
10
- * @TODO: This could likely be improved by handling worker events directly
11
- * and emitting events to the event log more deliberately than just
12
- * redirecting the base console output. ~ER20220831
7
+ * console logs to it.
13
8
  */
9
+ 'use strict';
14
10
 
15
- require('./common-types');
16
- const consoleLogger = require('./console');
17
-
18
- const syslog = require('syslog-client');
11
+ const os = require('os');
12
+ const syslog = require('syslog-client');
13
+ const process = require('process');
19
14
 
20
15
  // Copy the original global console object's properties onto a backup
21
16
  const _console = Object.assign({}, console);
17
+ var syslogClient;
18
+ var processName;
22
19
 
23
-
24
- const eventlogLogger = {
25
- /**
26
- * Initialize the syslog worker logger
27
- *
28
- * @param {Worker} worker DCP Worker object to log
29
- * @param {object} options Options for logger behaviour (passed
30
- * through to consoleLogger)
31
- */
32
- init(worker, options) {
33
- consoleLogger.init(worker, options);
34
-
35
- this.options = Object.assign({}, options);
20
+ /**
21
+ * Initialize the syslog worker logger
22
+ *
23
+ * @param {object} cliArgs Options for logger behaviour (passed
24
+ * through to consoleLogger)
25
+ */
26
+ exports.init = function syslog$$init(cliArgs)
27
+ {
28
+ {
36
29
  const syslogOptions = {
37
- transport: options.syslogTransport || 'udp', // tcp, udp, unix, tls
38
- port: options.syslogPort || 514,
30
+ syslogHostname: os.hostname(),
31
+ transport: cliArgs.syslogTransport || 'udp', // tcp, udp, unix, tls
32
+ port: cliArgs.syslogPort,
33
+ facility: syslog.Facility[cliArgs.syslogFacility[0].toUpperCase() + cliArgs.syslogFacility.slice(1)],
39
34
  }
40
35
 
41
- this._syslog = syslog.createClient(options.syslogAddress || '127.0.0.1', options);
42
- this._processName = require('path').basename(process.mainModule.filename || process.argv0);
43
-
44
- ['debug','error','info','log','warn'].forEach(level => {
45
- console[level] = (...args) => this._log(level, ...args);
46
- });
47
- },
36
+ syslogClient = syslog.createClient(cliArgs.syslogAddress || '127.0.0.1', syslogOptions);
37
+ processName = require('path').basename(process.mainModule.filename || process.argv0);
38
+ exports.close = () => syslogClient.close();
39
+ }
40
+ }
48
41
 
49
- _log(level, ...items) {
50
- const strBuilder = [`${this._processName}[${process.pid}]:`];
51
-
52
- items.forEach(i => {
53
- try {
54
- switch (typeof i) {
55
- case 'object':
56
- strBuilder.push(JSON.stringify(i));
57
- default:
58
- strBuilder.push(String(i));
59
- }
60
- }
61
- catch (e) {
62
- if (e instanceof TypeError) {
63
- strBuilder.push('[encoding error: ' + e.message + ']');
64
- }
65
- }
66
- });
42
+ function log(level, ...argv)
43
+ {
44
+ {
45
+ const logPrefix = `${processName}[${process.pid}]: `;
67
46
 
68
47
  // Use the string log-level to look up the severity number:
69
48
  let severity = {
@@ -74,18 +53,17 @@ const eventlogLogger = {
74
53
  debug: syslog.Severity.Debug,
75
54
  }[level];
76
55
 
77
- this._syslog.log(strBuilder.join(' '), {
78
- severity,
79
- }, error => {
80
- if (error)
81
- _console.error('168: Unexpected error writing to syslog:', error);
82
- });
83
- }
84
- };
56
+ const logMessages = argv.join(' ').split('\n');
85
57
 
86
- for (const [prop, value] of Object.entries(consoleLogger))
87
- {
88
- if (typeof value === 'function')
89
- exports[prop] = value.bind(consoleLogger);
58
+ for (let logMessage of logMessages)
59
+ {
60
+ logMessage = logPrefix + logMessage;
61
+ syslogClient.log(logMessage, { severity }, error => {
62
+ if (error)
63
+ _console.error('168: Unexpected error writing to syslog:');
64
+ });
65
+ }
66
+ }
90
67
  }
91
- Object.assign(exports, eventlogLogger);
68
+
69
+ exports.at = log;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcp-worker",
3
- "version": "3.2.30-2",
3
+ "version": "3.2.30-4",
4
4
  "description": "JavaScript portion of DCP Workers for Node.js",
5
5
  "main": "bin/dcp-worker",
6
6
  "keywords": [
@@ -37,8 +37,9 @@
37
37
  "blessed": "^0.1.81",
38
38
  "blessed-contrib": "^4.11.0",
39
39
  "chalk": "^4.1.0",
40
- "dcp-client": "4.2.32",
41
- "semver": "^7.3.8"
40
+ "dcp-client": "gitlab:Distributed-Compute-Protocol/dcp-client#develop",
41
+ "semver": "^7.3.8",
42
+ "syslog-client": "1.1.1"
42
43
  },
43
44
  "optionalDependencies": {
44
45
  "telnet-console": "^1.0.4"
@@ -47,6 +48,14 @@
47
48
  "@kingsds/eslint-config": "^1.0.1",
48
49
  "eslint": "7.30.0"
49
50
  },
51
+ "peerDependencies": {
52
+ "node-eventlog": "https://gitpkg.now.sh/Distributive-Network/node-eventlog/package?dcp/0.0.1"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "node-eventlog": {
56
+ "optional": true
57
+ }
58
+ },
50
59
  "engines": {
51
60
  "node": ">=16",
52
61
  "npm": ">=7"
@@ -1,24 +0,0 @@
1
- /**
2
- * @typedef WorkerLogger
3
- * @property {onSandboxReady} onSandboxReady
4
- * @property {function} onPayment
5
- * @property {function} onFetchingSlices
6
- * @property {function} onFetchedSlices
7
- * @property {function} onFetchSlicesFailed
8
- * @property {SandboxCallback} sandbox$onSliceStart
9
- * @property {SandboxCallback} sandbox$onSliceProgress
10
- * @property {SandboxCallback} sandbox$onSliceFinish
11
- * @property {SandboxCallback} sandbox$onWorkerStop
12
- */
13
-
14
- /**
15
- * @typedef {function} onSandboxReady
16
- * @param {Sandbox} sandbox
17
- * @returns {object} workerData
18
- */
19
-
20
- /**
21
- * @typedef {function} SandboxCallback
22
- * @param {Sandbox} sandbox
23
- * @param {object} workerData
24
- */