utilitas 1989.9.26 → 1989.9.27
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/lib/tape.mjs +9 -3
- package/package.json +1 -1
package/lib/tape.mjs
CHANGED
|
@@ -7,12 +7,12 @@ import * as utilitas from './utilitas.mjs';
|
|
|
7
7
|
// Handle, report, or silently ignore connection errors and failures
|
|
8
8
|
const handleError = (err) => { process.stdout.write(`${err.message}\n`); };
|
|
9
9
|
const consoleMap = { log: 'verbose', info: 0, debug: 0, warn: 0, error: 0 };
|
|
10
|
-
const TAPE = 'TAPE';
|
|
10
|
+
const [TAPE, defBufSize] = ['TAPE', 1000];
|
|
11
11
|
const modLog = (content) => { return utilitas.modLog(content, TAPE); };
|
|
12
12
|
const getLogger = async () => { return (await init()).logger; };
|
|
13
13
|
const [BOT, RSYSLOG, PAPERTRAIL] = ['BOT', 'RSYSLOG', 'PAPERTRAIL'];
|
|
14
14
|
|
|
15
|
-
let chatIds, tarLevel, botBuffer, logger, silent, provider;
|
|
15
|
+
let chatIds, tarLevel, botBuffer, bufferSize, logger, silent, provider;
|
|
16
16
|
|
|
17
17
|
// Do something after the connection to the Papertrail server is established
|
|
18
18
|
const handleConnect = (data) => {
|
|
@@ -77,6 +77,9 @@ const botLoggerInit = async (options) => {
|
|
|
77
77
|
chatIds = utilitas.ensureArray(options?.chatId);
|
|
78
78
|
utilitas.assert(chatIds.length, 'ChatId is required.', 501);
|
|
79
79
|
handleConnect(`Sending logs via bot, chatId: ${chatIds.join(', ')}.`);
|
|
80
|
+
bufferSize = utilitas.ensureInt(
|
|
81
|
+
options?.bufferSize || defBufSize, { min: 1, max: defBufSize }
|
|
82
|
+
);
|
|
80
83
|
logger = botLogger;
|
|
81
84
|
await event.loop(
|
|
82
85
|
botLoggerSync, ~~options?.interval || 5, ~~options?.tout || 10,
|
|
@@ -97,8 +100,11 @@ const botLogger = {
|
|
|
97
100
|
log: (level, message) => {
|
|
98
101
|
if (tarLevel !== 'verbose' && level === 'verbose') { return; }
|
|
99
102
|
(botBuffer = botBuffer || []).push([level, message]);
|
|
103
|
+
botBuffer.splice(0, botBuffer.length - defBufSize);
|
|
104
|
+
},
|
|
105
|
+
end: () => {
|
|
106
|
+
chatIds = undefined; botBuffer = undefined; event.end(TAPE);
|
|
100
107
|
},
|
|
101
|
-
end: () => { chatIds = null; botBuffer = null; event.end(TAPE); },
|
|
102
108
|
};
|
|
103
109
|
|
|
104
110
|
// use options.level = 'verbose' to send console.log logs
|