@rawnodes/logger 2.8.0 → 2.9.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/dist/index.mjs CHANGED
@@ -783,13 +783,27 @@ function getLevelName(levelNum) {
783
783
  if (levelNum >= 20) return "debug";
784
784
  return "silly";
785
785
  }
786
- function shouldPassTransport(log, level, rules, state) {
786
+ var DEFAULT_RESPECTS_OVERRIDES = {
787
+ console: true,
788
+ file: true,
789
+ cloudwatch: true,
790
+ relay: true,
791
+ discord: false,
792
+ telegram: false,
793
+ zohoCliq: false
794
+ };
795
+ function resolveRespectsOverrides(kind, configFlag) {
796
+ return configFlag ?? DEFAULT_RESPECTS_OVERRIDES[kind];
797
+ }
798
+ function shouldPassTransport(log, level, rules, state, respectOverrides) {
787
799
  const logLevel = getLevelName(log.level);
788
- const embeddedOverride = log.__or;
789
- if (typeof embeddedOverride === "string") {
790
- if (embeddedOverride === "off") return false;
791
- const overrideLevel = embeddedOverride;
792
- return LOG_LEVELS[logLevel] <= LOG_LEVELS[overrideLevel];
800
+ if (respectOverrides) {
801
+ const embeddedOverride = log.__or;
802
+ if (typeof embeddedOverride === "string") {
803
+ if (embeddedOverride === "off") return false;
804
+ const overrideLevel = embeddedOverride;
805
+ return LOG_LEVELS[logLevel] <= LOG_LEVELS[overrideLevel];
806
+ }
793
807
  }
794
808
  const context = log.context;
795
809
  if (rules && rules.length > 0) {
@@ -868,7 +882,7 @@ function formatLog(log, format, store) {
868
882
  return `[${timestamp}] ${levelName}: ${message}
869
883
  `;
870
884
  }
871
- function createFormattedFilterStream(format, level, rules, state, destination) {
885
+ function createFormattedFilterStream(format, level, rules, state, destination, respectOverrides) {
872
886
  return new Transform({
873
887
  transform(chunk, _encoding, callback) {
874
888
  const line = chunk.toString().trim();
@@ -881,7 +895,7 @@ function createFormattedFilterStream(format, level, rules, state, destination) {
881
895
  callback();
882
896
  return;
883
897
  }
884
- if (!shouldPassTransport(log, level, rules, state)) {
898
+ if (!shouldPassTransport(log, level, rules, state, respectOverrides)) {
885
899
  callback();
886
900
  return;
887
901
  }
@@ -899,7 +913,8 @@ function createStreams(config, state) {
899
913
  config.console.level,
900
914
  config.console.rules,
901
915
  state,
902
- process.stdout
916
+ process.stdout,
917
+ resolveRespectsOverrides("console", config.console.respectRuntimeOverrides)
903
918
  );
904
919
  streams.push({
905
920
  level: "trace",
@@ -932,7 +947,8 @@ function createStreams(config, state) {
932
947
  fileConfig.level,
933
948
  fileConfig.rules,
934
949
  state,
935
- rotatingStream
950
+ rotatingStream,
951
+ resolveRespectsOverrides("file", fileConfig.respectRuntimeOverrides)
936
952
  );
937
953
  streams.push({
938
954
  level: "trace",
@@ -942,7 +958,13 @@ function createStreams(config, state) {
942
958
  for (const discordConfig of toArray(config.discord)) {
943
959
  const transport = new DiscordTransport(discordConfig);
944
960
  transports.push(transport);
945
- const discordStream = createHttpTransportStream(transport, discordConfig.level, discordConfig.rules, state);
961
+ const discordStream = createHttpTransportStream(
962
+ transport,
963
+ discordConfig.level,
964
+ discordConfig.rules,
965
+ state,
966
+ resolveRespectsOverrides("discord", discordConfig.respectRuntimeOverrides)
967
+ );
946
968
  streams.push({
947
969
  level: "trace",
948
970
  stream: discordStream
@@ -951,7 +973,13 @@ function createStreams(config, state) {
951
973
  for (const telegramConfig of toArray(config.telegram)) {
952
974
  const transport = new TelegramTransport(telegramConfig);
953
975
  transports.push(transport);
954
- const telegramStream = createHttpTransportStream(transport, telegramConfig.level, telegramConfig.rules, state);
976
+ const telegramStream = createHttpTransportStream(
977
+ transport,
978
+ telegramConfig.level,
979
+ telegramConfig.rules,
980
+ state,
981
+ resolveRespectsOverrides("telegram", telegramConfig.respectRuntimeOverrides)
982
+ );
955
983
  streams.push({
956
984
  level: "trace",
957
985
  stream: telegramStream
@@ -960,7 +988,13 @@ function createStreams(config, state) {
960
988
  for (const zohoCliqConfig of toArray(config.zohoCliq)) {
961
989
  const transport = new ZohoCliqTransport(zohoCliqConfig);
962
990
  transports.push(transport);
963
- const zohoStream = createHttpTransportStream(transport, zohoCliqConfig.level, zohoCliqConfig.rules, state);
991
+ const zohoStream = createHttpTransportStream(
992
+ transport,
993
+ zohoCliqConfig.level,
994
+ zohoCliqConfig.rules,
995
+ state,
996
+ resolveRespectsOverrides("zohoCliq", zohoCliqConfig.respectRuntimeOverrides)
997
+ );
964
998
  streams.push({
965
999
  level: "trace",
966
1000
  stream: zohoStream
@@ -969,7 +1003,13 @@ function createStreams(config, state) {
969
1003
  for (const cloudwatchConfig of toArray(config.cloudwatch)) {
970
1004
  const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname);
971
1005
  transports.push(transport);
972
- const cwStream = createHttpTransportStream(transport, cloudwatchConfig.level, cloudwatchConfig.rules, state);
1006
+ const cwStream = createHttpTransportStream(
1007
+ transport,
1008
+ cloudwatchConfig.level,
1009
+ cloudwatchConfig.rules,
1010
+ state,
1011
+ resolveRespectsOverrides("cloudwatch", cloudwatchConfig.respectRuntimeOverrides)
1012
+ );
973
1013
  streams.push({
974
1014
  level: "trace",
975
1015
  stream: cwStream
@@ -994,7 +1034,7 @@ function toArray(value) {
994
1034
  if (!value) return [];
995
1035
  return Array.isArray(value) ? value : [value];
996
1036
  }
997
- function createHttpTransportStream(transport, level, rules, state) {
1037
+ function createHttpTransportStream(transport, level, rules, state, respectOverrides) {
998
1038
  return new Writable({
999
1039
  write(chunk, _encoding, callback) {
1000
1040
  const line = chunk.toString().trim();
@@ -1007,7 +1047,7 @@ function createHttpTransportStream(transport, level, rules, state) {
1007
1047
  callback();
1008
1048
  return;
1009
1049
  }
1010
- if (!shouldPassTransport(log, level, rules, state)) {
1050
+ if (!shouldPassTransport(log, level, rules, state, respectOverrides)) {
1011
1051
  callback();
1012
1052
  return;
1013
1053
  }
@@ -1166,12 +1206,14 @@ var LevelRuleSchema = z.object({
1166
1206
  var ConsoleConfigSchema = z.object({
1167
1207
  format: LogFormatSchema,
1168
1208
  level: LogLevelSchema.optional(),
1169
- rules: z.array(LevelRuleSchema).optional()
1209
+ rules: z.array(LevelRuleSchema).optional(),
1210
+ respectRuntimeOverrides: z.boolean().optional()
1170
1211
  });
1171
1212
  var FileConfigSchema = z.object({
1172
1213
  format: LogFormatSchema,
1173
1214
  level: LogLevelSchema.optional(),
1174
1215
  rules: z.array(LevelRuleSchema).optional(),
1216
+ respectRuntimeOverrides: z.boolean().optional(),
1175
1217
  dirname: z.string().min(1, "dirname is required"),
1176
1218
  filename: z.string().min(1, "filename is required"),
1177
1219
  datePattern: z.string().optional(),
@@ -1183,6 +1225,7 @@ var FileConfigSchema = z.object({
1183
1225
  var HttpTransportBaseConfigSchema = z.object({
1184
1226
  level: LogLevelSchema.optional(),
1185
1227
  rules: z.array(LevelRuleSchema).optional(),
1228
+ respectRuntimeOverrides: z.boolean().optional(),
1186
1229
  batchSize: z.number().int().positive().optional(),
1187
1230
  flushInterval: z.number().int().positive().optional(),
1188
1231
  maxRetries: z.number().int().nonnegative().optional(),
@@ -1196,6 +1239,7 @@ var HttpTransportBaseConfigSchema = z.object({
1196
1239
  var DiscordConfigSchema = z.object({
1197
1240
  level: LogLevelSchema.optional(),
1198
1241
  rules: z.array(LevelRuleSchema).optional(),
1242
+ respectRuntimeOverrides: z.boolean().optional(),
1199
1243
  batchSize: z.number().int().positive().optional(),
1200
1244
  flushInterval: z.number().int().positive().optional(),
1201
1245
  maxRetries: z.number().int().nonnegative().optional(),
@@ -1217,6 +1261,7 @@ var DiscordConfigSchema = z.object({
1217
1261
  var TelegramConfigSchema = z.object({
1218
1262
  level: LogLevelSchema.optional(),
1219
1263
  rules: z.array(LevelRuleSchema).optional(),
1264
+ respectRuntimeOverrides: z.boolean().optional(),
1220
1265
  batchSize: z.number().int().positive().optional(),
1221
1266
  flushInterval: z.number().int().positive().optional(),
1222
1267
  maxRetries: z.number().int().nonnegative().optional(),
@@ -1254,6 +1299,7 @@ var LogStreamNameSchema = z.union([
1254
1299
  var CloudWatchConfigSchema = z.object({
1255
1300
  level: LogLevelSchema.optional(),
1256
1301
  rules: z.array(LevelRuleSchema).optional(),
1302
+ respectRuntimeOverrides: z.boolean().optional(),
1257
1303
  batchSize: z.number().int().positive().optional(),
1258
1304
  flushInterval: z.number().int().positive().optional(),
1259
1305
  maxRetries: z.number().int().nonnegative().optional(),
@@ -1274,6 +1320,7 @@ var CloudWatchConfigSchema = z.object({
1274
1320
  var ZohoCliqConfigBaseSchema = z.object({
1275
1321
  level: LogLevelSchema.optional(),
1276
1322
  rules: z.array(LevelRuleSchema).optional(),
1323
+ respectRuntimeOverrides: z.boolean().optional(),
1277
1324
  batchSize: z.number().int().positive().optional(),
1278
1325
  flushInterval: z.number().int().positive().optional(),
1279
1326
  maxRetries: z.number().int().nonnegative().optional(),
@@ -1306,7 +1353,8 @@ var RelayConfigSchema = z.object({
1306
1353
  pollInterval: z.number().int().positive().optional(),
1307
1354
  bufferSize: z.number().int().positive().optional(),
1308
1355
  reconnectDelay: z.number().int().positive().optional(),
1309
- maxReconnectDelay: z.number().int().positive().optional()
1356
+ maxReconnectDelay: z.number().int().positive().optional(),
1357
+ respectRuntimeOverrides: z.boolean().optional()
1310
1358
  });
1311
1359
  var LevelConfigObjectSchema = z.object({
1312
1360
  default: LogLevelSchema,