@akc42/server-utils 3.3.0 → 3.4.1

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.
Files changed (2) hide show
  1. package/debug.js +16 -5
  2. package/package.json +1 -1
package/debug.js CHANGED
@@ -22,7 +22,7 @@ import chalk from 'chalk';
22
22
  let config = process.env.DEBUG || '';
23
23
  let cache = [];
24
24
  let cachelimit = 50;
25
-
25
+
26
26
  export function Debug (topic) {
27
27
  const t = topic;
28
28
  let timestamp = new Date().getTime();
@@ -40,14 +40,25 @@ 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
+ let logLine = '';
44
+ if (typeof process.env.LOG_NO_DATE === 'undefined') {
45
+ if (typeof process.env.LOG_ISO_DATE !== 'undefined') {
46
+ logLine += new Date().toISOString() + ': ';
47
+ } else {
48
+ logLine += new Date().toISOString().substring(0,10) + ' ' + new Date().toLocaleTimeString() + ': ';
49
+ }
50
+ }
51
+ logLine += output;
43
52
  //eslint-disable-next-line no-console
44
- console.log(output);
45
- }
46
- cache.push(output);
53
+ console.log(logLine);
54
+ }
55
+ const time = chalk.whiteBright(new Date().toISOtring().substring(11,23)); //store millisecond timing
56
+ cache.push(`${time} ${output}`);
47
57
  if (cache.length > cachelimit) cache.splice(0,cache.length - cachelimit); //prevent it getting too big
48
58
  }
49
59
  };
50
60
  export function dumpDebugCache() {
61
+ const time = chalk.whiteBright(new Date().toISOString());
51
62
  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');
52
63
  cache.reverse();
53
64
  for(const line of cache) {
@@ -56,7 +67,7 @@ export function dumpDebugCache() {
56
67
  }
57
68
  cache.reverse();
58
69
  //eslint-disable-next-line no-console
59
- console.log(output);
70
+ console.log(`${time} - ${output}`);
60
71
  };
61
72
  export function setDebugConfig(con, limit = 50) {
62
73
  cachelimit = limit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akc42/server-utils",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
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",