core-3nweb-client-lib 0.52.1 → 0.52.2

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,6 +4,7 @@ export declare function makeLogger(utilDir: string): Readonly<{
4
4
  logWarning: (msg: string, err?: any) => Promise<void>;
5
5
  appLog: (type: "error" | "info" | "warning", appDomain: string, msg: string, err?: any) => Promise<void>;
6
6
  recordUnhandledRejectionsInProcess: () => void;
7
+ removeOlderLogs: () => Promise<void>;
7
8
  }>;
8
9
  export type Logger = ReturnType<typeof makeLogger>;
9
10
  export type LogError = Logger['logError'];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017 - 2021 3NSoft Inc.
3
+ Copyright (C) 2017 - 2021, 2026 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -23,11 +23,12 @@ const synced_1 = require("../../lib-common/processes/synced");
23
23
  const async_fs_node_1 = require("../../lib-common/async-fs-node");
24
24
  const path_1 = require("path");
25
25
  exports.LOGS_FOLDER = 'logs';
26
+ const LOG_FILE_EXT = 'log.txt';
26
27
  function logFileName(now, appDomain) {
27
28
  const dateStr = now.toISOString().slice(0, 10);
28
29
  return (appDomain ?
29
- `${dateStr}.${appDomain}.log.txt` :
30
- `${dateStr}.log.txt`);
30
+ `${dateStr}.${appDomain}.${LOG_FILE_EXT}` :
31
+ `${dateStr}.${LOG_FILE_EXT}`);
31
32
  }
32
33
  let version;
33
34
  function getCurrentCoreVersion() {
@@ -124,8 +125,29 @@ ${(0, error_1.stringifyErr)(err)}`;
124
125
  logError(err, 'Unhandled exception');
125
126
  });
126
127
  }
128
+ // XXX add cleaner
129
+ async function removeOlderLogs() {
130
+ const logs = (await (0, async_fs_node_1.readdir)(utilDir).catch(exc => {
131
+ logError(exc, `Error when removing older logs`);
132
+ return [];
133
+ }))
134
+ .filter(fName => fName.endsWith(`.${LOG_FILE_EXT}`));
135
+ const tsCutOff = Date.now() - 4 * 24 * 12 * 60 * 60 * 1000;
136
+ for (const fName of logs) {
137
+ try {
138
+ const fPath = (0, path_1.join)(utilDir, fName);
139
+ const fStats = await (0, async_fs_node_1.stat)(fPath);
140
+ if (fStats.birthtimeMs < tsCutOff) {
141
+ await (0, async_fs_node_1.unlink)(fPath);
142
+ }
143
+ }
144
+ catch (exc) {
145
+ logError(exc, `Error when removing older logs`);
146
+ }
147
+ }
148
+ }
127
149
  return Object.freeze({
128
- logError, logWarning, appLog, recordUnhandledRejectionsInProcess
150
+ logError, logWarning, appLog, recordUnhandledRejectionsInProcess, removeOlderLogs
129
151
  });
130
152
  }
131
153
  function noop() { }
@@ -34,7 +34,8 @@ const logger = {
34
34
  logWarning: async (msg, err) => {
35
35
  inspector_1.console.error(`\n --- test logWarning called with ---\nMessage: ${msg}\nError:`, err);
36
36
  },
37
- recordUnhandledRejectionsInProcess: () => { }
37
+ recordUnhandledRejectionsInProcess: () => { },
38
+ removeOlderLogs: async () => { }
38
39
  };
39
40
  async function logErrorInTest(err, msg) {
40
41
  inspector_1.console.error(`\n --- test logError callled with ---\nMessage: ${msg}\nError:`, err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.52.1",
3
+ "version": "0.52.2",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",