@akc42/server-utils 3.0.0 → 3.2.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.
- package/README.md +1 -2
- package/debug.js +7 -31
- package/logger.js +2 -11
- package/package.json +2 -4
- package/version.js +2 -2
package/README.md
CHANGED
|
@@ -41,8 +41,7 @@ to `dumpDebugCache`
|
|
|
41
41
|
|
|
42
42
|
Breaking change as of 3.0.0 logger is now an async function returning a promise fulfilled when (if set) a log file entry is made
|
|
43
43
|
|
|
44
|
-
both `Debug` and `logger`
|
|
45
|
-
console. If it is not undefined these two modules will write to the log file rather than the console.
|
|
44
|
+
both `Debug` and `logger` have had their file logging removed as its causing more issues that its worth
|
|
46
45
|
|
|
47
46
|
|
|
48
47
|
These are installed with as many of few of the items that you want like so:-
|
package/debug.js
CHANGED
|
@@ -40,14 +40,8 @@ export function Debug (topic) {
|
|
|
40
40
|
}, '');
|
|
41
41
|
const output = `${chalk.greenBright(topic)} ${chalk.cyan(message)} ${chalk.whiteBright(`(${gap}ms)`)}`
|
|
42
42
|
if (enabled) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(output);
|
|
46
|
-
} else {
|
|
47
|
-
fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true}, err => {
|
|
48
|
-
if (err) console.warn('Failed to write following message to log file', output);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
43
|
+
//eslint-disable-next-line no-console
|
|
44
|
+
console.log(output);
|
|
51
45
|
}
|
|
52
46
|
cache.push(output);
|
|
53
47
|
if (cache.length > cachelimit) cache.splice(0,cache.length - cachelimit); //prevent it getting too big
|
|
@@ -57,38 +51,20 @@ export function dumpDebugCache() {
|
|
|
57
51
|
const output = chalk.white.bgBlue('Above are all the debug calls (most recent first) which lead up to, and then followed on from, the error above');
|
|
58
52
|
cache.reverse();
|
|
59
53
|
for(const line of cache) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
console.log(line);
|
|
63
|
-
} else {
|
|
64
|
-
fs.appendFile(process.env.LOG_FILE, line + '\n',{flush: true}, err => {
|
|
65
|
-
if (err) console.warn('Failed to write following message to log file', line);
|
|
66
|
-
})
|
|
67
|
-
}
|
|
54
|
+
//eslint-disable-next-line no-console
|
|
55
|
+
console.log(line);
|
|
68
56
|
}
|
|
69
57
|
cache.reverse();
|
|
70
|
-
if (typeof process.env.LOG_FILE === 'undefined') {
|
|
71
58
|
//eslint-disable-next-line no-console
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true}, err => {
|
|
75
|
-
if (err) console.warn('Failed to write following message to log file', output);
|
|
76
|
-
})
|
|
77
|
-
}
|
|
59
|
+
console.log(output);
|
|
78
60
|
};
|
|
79
61
|
export function setDebugConfig(con, limit = 50) {
|
|
80
62
|
cachelimit = limit;
|
|
81
63
|
if (con !== config) {
|
|
82
64
|
config = con;
|
|
83
65
|
const output = `${chalk.greenBright('debug server config')} ${chalk.redBright(`new server config "${config}"`)}`
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
console.log(output);
|
|
87
|
-
} else {
|
|
88
|
-
fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true}, err => {
|
|
89
|
-
if (err) console.warn('Failed to write following message to log file', output);
|
|
90
|
-
})
|
|
91
|
-
}
|
|
66
|
+
//eslint-disable-next-line no-console
|
|
67
|
+
console.log(output);
|
|
92
68
|
}
|
|
93
69
|
};
|
|
94
70
|
|
package/logger.js
CHANGED
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
|
|
21
21
|
import chalk from 'chalk';
|
|
22
22
|
import { isIP } from 'node:net';
|
|
23
|
-
import fs from 'node:fs/promises'
|
|
24
23
|
|
|
25
24
|
const COLOURS = {
|
|
26
25
|
app: chalk.rgb(255, 136, 0).bold, //orange,
|
|
@@ -47,7 +46,7 @@ function cyrb53 (str, seed = 0) {
|
|
|
47
46
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
export default
|
|
49
|
+
export default function logger(ip,level, ...messages) {
|
|
51
50
|
if (process.env.LOG_NONE === undefined) {
|
|
52
51
|
let logLine = '';
|
|
53
52
|
if (typeof process.env.LOG_NO_DATE === 'undefined') logLine += new Date().toISOString() + ': ';
|
|
@@ -63,16 +62,8 @@ export default async function logger(ip,level, ...messages) {
|
|
|
63
62
|
message = messages.join(' ');
|
|
64
63
|
}
|
|
65
64
|
logLine += COLOURS[logcolor](message);
|
|
66
|
-
|
|
67
|
-
//eslint-disable-next-line no-console
|
|
65
|
+
//eslint-disable-next-line no-console
|
|
68
66
|
console.log(logLine.trim());
|
|
69
|
-
} else {
|
|
70
|
-
try {
|
|
71
|
-
await fs.appendFile(process.env.LOG_FILE, logLine.trim() + '\n',{flush: true})
|
|
72
|
-
} catch(err) {
|
|
73
|
-
console.warn('Error writing log file:',err,'message being logged', logLine.trim());
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akc42/server-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Set of Utilities to use on the Server Side of a Project",
|
|
6
6
|
"main": "./utils.js",
|
|
@@ -22,8 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/akc42/server-utils#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"chalk": "^5.3.0",
|
|
27
|
-
"debug": "^4.3.4"
|
|
25
|
+
"chalk": "^5.3.0"
|
|
28
26
|
}
|
|
29
27
|
}
|
package/version.js
CHANGED
|
@@ -25,9 +25,9 @@ import { exec } from 'node:child_process';
|
|
|
25
25
|
|
|
26
26
|
const debug = Debug('version');
|
|
27
27
|
|
|
28
|
-
function shCmd(cmd, root) {
|
|
28
|
+
async function shCmd(cmd, root) {
|
|
29
29
|
debug('About to execute Command ', cmd);
|
|
30
|
-
return new Promise((accept, reject) => {
|
|
30
|
+
return new Promise(async (accept, reject) => {
|
|
31
31
|
exec(cmd, { cwd: root }, (err, stdout, stderr) => {
|
|
32
32
|
if (stderr) {
|
|
33
33
|
debug('Command ', cmd, 'about to fail with ', err);
|