@rawnodes/logger 2.12.0 → 2.12.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.
package/README.md CHANGED
@@ -316,6 +316,8 @@ telegram: {
316
316
  }
317
317
  ```
318
318
 
319
+ File open, write, and rotation errors disable only the affected file destination. Console and remote transports continue logging. By default, a single diagnostic with the error code is written to stderr. Set `file.onError` to handle the error yourself; the callback receives the original `Error`.
320
+
319
321
  ### CloudWatch
320
322
 
321
323
  Send logs to AWS CloudWatch Logs:
@@ -871,6 +873,7 @@ interface LoggerConfig {
871
873
  maxFiles?: string;
872
874
  maxSize?: string;
873
875
  zippedArchive?: boolean;
876
+ onError?: (error: Error) => void;
874
877
  };
875
878
  }
876
879
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LoggerContext, a as LoggerConfig, b as LevelOverrideMatch, c as LogLevel, d as LevelOverride, M as Meta, D as DiscordConfig, T as TelegramConfig, C as CloudWatchConfig, e as MaskReplacer, Z as ZohoCliqConfig, f as CallerConfig, g as CallerInfo, h as LogFormat, i as LevelRule, j as ConsoleConfig, F as FileConfig, H as HttpTransportBaseConfig, k as LevelConfigObject, l as LevelConfig, R as RelayConfig, A as AutoShutdownConfig, m as LogStreamPattern, n as LogStreamPatternConfig, o as LogStreamTemplateConfig, p as LogStreamName } from './types-lfJLhC8J.mjs';
2
- export { q as LOG_LEVELS, x as MaskSecretsOptions, t as ZohoCliqBotConfig, s as assertLogLevel, v as createMasker, r as isValidLogLevel, w as maskReplacer, u as maskSecrets } from './types-lfJLhC8J.mjs';
1
+ import { L as LoggerContext, a as LoggerConfig, b as LevelOverrideMatch, c as LogLevel, d as LevelOverride, M as Meta, D as DiscordConfig, T as TelegramConfig, C as CloudWatchConfig, e as MaskReplacer, Z as ZohoCliqConfig, f as CallerConfig, g as CallerInfo, h as LogFormat, i as LevelRule, j as ConsoleConfig, F as FileConfig, H as HttpTransportBaseConfig, k as LevelConfigObject, l as LevelConfig, R as RelayConfig, A as AutoShutdownConfig, m as LogStreamPattern, n as LogStreamPatternConfig, o as LogStreamTemplateConfig, p as LogStreamName } from './types-CD5hHXR4.mjs';
2
+ export { q as LOG_LEVELS, x as MaskSecretsOptions, t as ZohoCliqBotConfig, s as assertLogLevel, v as createMasker, r as isValidLogLevel, w as maskReplacer, u as maskSecrets } from './types-CD5hHXR4.mjs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LoggerContext, a as LoggerConfig, b as LevelOverrideMatch, c as LogLevel, d as LevelOverride, M as Meta, D as DiscordConfig, T as TelegramConfig, C as CloudWatchConfig, e as MaskReplacer, Z as ZohoCliqConfig, f as CallerConfig, g as CallerInfo, h as LogFormat, i as LevelRule, j as ConsoleConfig, F as FileConfig, H as HttpTransportBaseConfig, k as LevelConfigObject, l as LevelConfig, R as RelayConfig, A as AutoShutdownConfig, m as LogStreamPattern, n as LogStreamPatternConfig, o as LogStreamTemplateConfig, p as LogStreamName } from './types-lfJLhC8J.js';
2
- export { q as LOG_LEVELS, x as MaskSecretsOptions, t as ZohoCliqBotConfig, s as assertLogLevel, v as createMasker, r as isValidLogLevel, w as maskReplacer, u as maskSecrets } from './types-lfJLhC8J.js';
1
+ import { L as LoggerContext, a as LoggerConfig, b as LevelOverrideMatch, c as LogLevel, d as LevelOverride, M as Meta, D as DiscordConfig, T as TelegramConfig, C as CloudWatchConfig, e as MaskReplacer, Z as ZohoCliqConfig, f as CallerConfig, g as CallerInfo, h as LogFormat, i as LevelRule, j as ConsoleConfig, F as FileConfig, H as HttpTransportBaseConfig, k as LevelConfigObject, l as LevelConfig, R as RelayConfig, A as AutoShutdownConfig, m as LogStreamPattern, n as LogStreamPatternConfig, o as LogStreamTemplateConfig, p as LogStreamName } from './types-CD5hHXR4.js';
2
+ export { q as LOG_LEVELS, x as MaskSecretsOptions, t as ZohoCliqBotConfig, s as assertLogLevel, v as createMasker, r as isValidLogLevel, w as maskReplacer, u as maskSecrets } from './types-CD5hHXR4.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ var os = require('os');
4
4
  var pino = require('pino');
5
5
  var async_hooks = require('async_hooks');
6
6
  var stream = require('stream');
7
- var promises = require('fs/promises');
8
7
  var rotatingFileStream = require('rotating-file-stream');
9
8
  var clientCloudwatchLogs = require('@aws-sdk/client-cloudwatch-logs');
10
9
  var crypto = require('crypto');
@@ -45,6 +44,89 @@ function assertLogLevel(level) {
45
44
  throw new Error(`Invalid log level: "${level}". Valid levels: ${Object.keys(LOG_LEVELS).join(", ")}`);
46
45
  }
47
46
  }
47
+ function reportFileFailure(error) {
48
+ const code = "code" in error && typeof error.code === "string" ? error.code : error.name;
49
+ process.stderr.write(
50
+ `[Logger] File logging stopped (${code}); other transports remain active.
51
+ `
52
+ );
53
+ }
54
+ function createFileDestination(config) {
55
+ let failed = false;
56
+ let rotatingStream;
57
+ const fail = (error) => {
58
+ if (failed) return;
59
+ failed = true;
60
+ if (config.onError) {
61
+ try {
62
+ config.onError(error);
63
+ } catch {
64
+ reportFileFailure(error);
65
+ }
66
+ } else {
67
+ reportFileFailure(error);
68
+ }
69
+ };
70
+ try {
71
+ rotatingStream = rotatingFileStream.createStream(
72
+ (time, index) => {
73
+ const date = time instanceof Date ? time : /* @__PURE__ */ new Date();
74
+ const dateStr = date.toISOString().split("T")[0];
75
+ const base = config.filename.replace(".log", "");
76
+ return `${base}-${dateStr}${index ? `.${index}` : ""}.log`;
77
+ },
78
+ {
79
+ path: config.dirname,
80
+ size: (config.maxSize || "20M").replace(
81
+ /([kmg])$/i,
82
+ (unit) => unit.toUpperCase()
83
+ ),
84
+ interval: config.interval || (config.datePattern === "YYYY-MM-DD-HH" ? "1h" : "1d"),
85
+ compress: config.zippedArchive ? "gzip" : false,
86
+ maxFiles: parseInt(config.maxFiles?.replace("d", "") || "14")
87
+ }
88
+ );
89
+ rotatingStream.on("error", fail);
90
+ } catch (error) {
91
+ fail(error instanceof Error ? error : new Error(String(error)));
92
+ }
93
+ return new stream.Writable({
94
+ write(chunk, encoding, callback) {
95
+ if (failed || !rotatingStream) {
96
+ callback();
97
+ return;
98
+ }
99
+ try {
100
+ rotatingStream.write(chunk, encoding, (error) => {
101
+ if (error) fail(error);
102
+ callback();
103
+ });
104
+ } catch (error) {
105
+ fail(error instanceof Error ? error : new Error(String(error)));
106
+ callback();
107
+ }
108
+ },
109
+ final(callback) {
110
+ if (!rotatingStream || rotatingStream.destroyed) {
111
+ callback();
112
+ return;
113
+ }
114
+ try {
115
+ rotatingStream.end((error) => {
116
+ if (error) fail(error);
117
+ callback();
118
+ });
119
+ } catch (error) {
120
+ fail(error instanceof Error ? error : new Error(String(error)));
121
+ callback();
122
+ }
123
+ },
124
+ destroy(_error, callback) {
125
+ rotatingStream?.destroy();
126
+ callback();
127
+ }
128
+ });
129
+ }
48
130
 
49
131
  // src/transports/buffer.ts
50
132
  var MessageBuffer = class {
@@ -791,7 +873,9 @@ var CloudWatchTransport = class _CloudWatchTransport extends BaseHttpTransport {
791
873
  return this.isAwsErrorNamed(error, "ResourceNotFoundException");
792
874
  }
793
875
  isAwsErrorNamed(error, name) {
794
- return typeof error === "object" && error !== null && "name" in error && error.name === name;
876
+ if (typeof error !== "object" || error === null) return false;
877
+ if ("name" in error && error.name === name) return true;
878
+ return "__type" in error && typeof error.__type === "string" && error.__type.split("#").at(-1) === name;
795
879
  }
796
880
  };
797
881
 
@@ -953,26 +1037,7 @@ function createStreams(config, state) {
953
1037
  });
954
1038
  if (config.file) {
955
1039
  const fileConfig = config.file;
956
- promises.mkdir(fileConfig.dirname, { recursive: true }).catch(() => {
957
- });
958
- const normalizeSize = (size) => {
959
- return size.replace(/([kmg])$/i, (match) => match.toUpperCase());
960
- };
961
- const rotatingStream = rotatingFileStream.createStream(
962
- (time, index) => {
963
- const date = time instanceof Date ? time : /* @__PURE__ */ new Date();
964
- const dateStr = date.toISOString().split("T")[0];
965
- const base = fileConfig.filename.replace(".log", "");
966
- return `${base}-${dateStr}${index ? `.${index}` : ""}.log`;
967
- },
968
- {
969
- path: fileConfig.dirname,
970
- size: normalizeSize(fileConfig.maxSize || "20M"),
971
- interval: fileConfig.interval || (fileConfig.datePattern === "YYYY-MM-DD-HH" ? "1h" : "1d"),
972
- compress: fileConfig.zippedArchive ? "gzip" : false,
973
- maxFiles: parseInt(fileConfig.maxFiles?.replace("d", "") || "14")
974
- }
975
- );
1040
+ const rotatingStream = createFileDestination(fileConfig);
976
1041
  const fileStream = createFormattedFilterStream(
977
1042
  fileConfig.format,
978
1043
  fileConfig.level,
@@ -1364,7 +1429,8 @@ var FileConfigSchema = zod.z.object({
1364
1429
  interval: zod.z.string().regex(/^\d+[Mdhms]$/).optional(),
1365
1430
  zippedArchive: zod.z.boolean().optional(),
1366
1431
  maxSize: zod.z.string().optional(),
1367
- maxFiles: zod.z.string().optional()
1432
+ maxFiles: zod.z.string().optional(),
1433
+ onError: zod.z.function().optional()
1368
1434
  });
1369
1435
  var HttpTransportBaseConfigSchema = zod.z.object({
1370
1436
  level: LogLevelSchema.optional(),