@rawnodes/logger 2.3.0 → 2.5.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/README.md CHANGED
@@ -272,7 +272,6 @@ const logger = Logger.create({
272
272
  console: { format: 'plain' },
273
273
  cloudwatch: {
274
274
  logGroupName: '/app/my-service',
275
- logStreamName: `${hostname}-${Date.now()}`,
276
275
  region: 'us-east-1',
277
276
  accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
278
277
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
@@ -284,6 +283,91 @@ const logger = Logger.create({
284
283
  });
285
284
  ```
286
285
 
286
+ #### Log Stream Name
287
+
288
+ The `logStreamName` field is optional and supports multiple configuration formats:
289
+
290
+ ```typescript
291
+ // Option 1: Static string
292
+ cloudwatch: {
293
+ logGroupName: '/app/my-service',
294
+ logStreamName: 'my-static-stream',
295
+ // ...
296
+ }
297
+
298
+ // Option 2: Predefined pattern
299
+ cloudwatch: {
300
+ logGroupName: '/app/my-service',
301
+ logStreamName: { pattern: 'hostname-date' },
302
+ // ...
303
+ }
304
+
305
+ // Option 3: Custom template
306
+ cloudwatch: {
307
+ logGroupName: '/app/my-service',
308
+ logStreamName: { template: '{hostname}/{env}/{date}' },
309
+ // ...
310
+ }
311
+
312
+ // Option 4: Omit for default (hostname)
313
+ cloudwatch: {
314
+ logGroupName: '/app/my-service',
315
+ // logStreamName defaults to hostname
316
+ // ...
317
+ }
318
+ ```
319
+
320
+ **Available patterns:**
321
+
322
+ | Pattern | Example Output |
323
+ |---------|----------------|
324
+ | `hostname` | `my-server` |
325
+ | `hostname-date` | `my-server/2025-01-15` |
326
+ | `hostname-uuid` | `my-server-a1b2c3d4` |
327
+ | `date` | `2025-01-15` |
328
+ | `uuid` | `a1b2c3d4-e5f6-7890-abcd` |
329
+
330
+ **Template variables:**
331
+
332
+ | Variable | Description |
333
+ |----------|-------------|
334
+ | `{hostname}` | Server hostname (config.hostname → HOSTNAME env → os.hostname()) |
335
+ | `{date}` | Current date (YYYY-MM-DD) |
336
+ | `{datetime}` | Current datetime (YYYY-MM-DD-HH-mm-ss) |
337
+ | `{uuid}` | 8-char UUID (generated once at startup) |
338
+ | `{pid}` | Process ID |
339
+ | `{env}` | NODE_ENV (default: "development") |
340
+
341
+ **Hostname resolution priority:**
342
+ 1. `config.hostname` (from logger config)
343
+ 2. `process.env.HOSTNAME` (useful in Docker/Kubernetes)
344
+ 3. `os.hostname()`
345
+
346
+ **Examples:**
347
+
348
+ ```typescript
349
+ // Kubernetes-friendly: pod name as stream
350
+ cloudwatch: {
351
+ logGroupName: '/app/my-service/production',
352
+ logStreamName: { pattern: 'hostname' }, // -> "my-app-pod-abc123"
353
+ // ...
354
+ }
355
+
356
+ // Daily rotation with hostname
357
+ cloudwatch: {
358
+ logGroupName: '/app/my-service',
359
+ logStreamName: { pattern: 'hostname-date' }, // -> "my-server/2025-01-15"
360
+ // ...
361
+ }
362
+
363
+ // Custom format with environment
364
+ cloudwatch: {
365
+ logGroupName: '/app/my-service',
366
+ logStreamName: { template: '{env}/{hostname}/{date}' }, // -> "production/my-server/2025-01-15"
367
+ // ...
368
+ }
369
+ ```
370
+
287
371
  ### Transport Options
288
372
 
289
373
  All external transports support:
package/dist/index.d.mts CHANGED
@@ -64,9 +64,19 @@ interface TelegramConfig extends HttpTransportBaseConfig {
64
64
  threadId?: number;
65
65
  replyToMessageId?: number;
66
66
  }
67
+ type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
68
+ interface LogStreamPatternConfig {
69
+ pattern: LogStreamPattern;
70
+ }
71
+ interface LogStreamTemplateConfig {
72
+ /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
73
+ template: string;
74
+ }
75
+ type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
67
76
  interface CloudWatchConfig extends HttpTransportBaseConfig {
68
77
  logGroupName: string;
69
- logStreamName: string;
78
+ /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
79
+ logStreamName?: LogStreamName;
70
80
  region: string;
71
81
  accessKeyId: string;
72
82
  secretAccessKey: string;
@@ -99,6 +109,8 @@ interface LoggerConfig {
99
109
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
100
110
  /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
101
111
  caller?: boolean | CallerConfig;
112
+ /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
113
+ hostname?: string;
102
114
  }
103
115
  type LoggerContext = Record<string, unknown>;
104
116
  type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
@@ -238,7 +250,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
238
250
  private sequenceToken;
239
251
  private initialized;
240
252
  private initPromise;
241
- constructor(config: CloudWatchConfig);
253
+ private resolvedLogStreamName;
254
+ constructor(config: CloudWatchConfig, configHostname?: string);
242
255
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
243
256
  private ensureInitialized;
244
257
  private initialize;
@@ -294,6 +307,10 @@ declare const FileConfigSchema: z.ZodType<FileConfig>;
294
307
  declare const HttpTransportBaseConfigSchema: z.ZodType<HttpTransportBaseConfig>;
295
308
  declare const DiscordConfigSchema: z.ZodType<DiscordConfig>;
296
309
  declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
310
+ declare const LogStreamPatternSchema: z.ZodType<LogStreamPattern>;
311
+ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
312
+ declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
313
+ declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
297
314
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
298
315
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
299
316
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
@@ -306,6 +323,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
306
323
  telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
307
324
  cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
308
325
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
326
+ hostname: z.ZodOptional<z.ZodString>;
309
327
  }, z.core.$strip>;
310
328
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
311
329
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -316,6 +334,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
316
334
  telegram?: TelegramConfig | TelegramConfig[] | undefined;
317
335
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
318
336
  caller?: boolean | CallerConfig | undefined;
337
+ hostname?: string | undefined;
319
338
  }>;
320
339
 
321
- export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
340
+ export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
package/dist/index.d.ts CHANGED
@@ -64,9 +64,19 @@ interface TelegramConfig extends HttpTransportBaseConfig {
64
64
  threadId?: number;
65
65
  replyToMessageId?: number;
66
66
  }
67
+ type LogStreamPattern = 'hostname' | 'hostname-date' | 'hostname-uuid' | 'date' | 'uuid';
68
+ interface LogStreamPatternConfig {
69
+ pattern: LogStreamPattern;
70
+ }
71
+ interface LogStreamTemplateConfig {
72
+ /** Custom template with variables: {hostname}, {date}, {datetime}, {uuid}, {pid}, {env} */
73
+ template: string;
74
+ }
75
+ type LogStreamName = string | LogStreamPatternConfig | LogStreamTemplateConfig;
67
76
  interface CloudWatchConfig extends HttpTransportBaseConfig {
68
77
  logGroupName: string;
69
- logStreamName: string;
78
+ /** Log stream name - string, pattern config, or template config. Defaults to hostname pattern */
79
+ logStreamName?: LogStreamName;
70
80
  region: string;
71
81
  accessKeyId: string;
72
82
  secretAccessKey: string;
@@ -99,6 +109,8 @@ interface LoggerConfig {
99
109
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[];
100
110
  /** Enable caller info (file:line) in logs. Pass true for defaults or CallerConfig for options */
101
111
  caller?: boolean | CallerConfig;
112
+ /** Hostname to include in all log entries. Defaults to os.hostname() if not specified */
113
+ hostname?: string;
102
114
  }
103
115
  type LoggerContext = Record<string, unknown>;
104
116
  type LevelOverrideMatch<TContext extends LoggerContext> = Partial<TContext> & {
@@ -238,7 +250,8 @@ declare class CloudWatchTransport extends BaseHttpTransport {
238
250
  private sequenceToken;
239
251
  private initialized;
240
252
  private initPromise;
241
- constructor(config: CloudWatchConfig);
253
+ private resolvedLogStreamName;
254
+ constructor(config: CloudWatchConfig, configHostname?: string);
242
255
  protected sendBatch(messages: BufferedMessage[]): Promise<void>;
243
256
  private ensureInitialized;
244
257
  private initialize;
@@ -294,6 +307,10 @@ declare const FileConfigSchema: z.ZodType<FileConfig>;
294
307
  declare const HttpTransportBaseConfigSchema: z.ZodType<HttpTransportBaseConfig>;
295
308
  declare const DiscordConfigSchema: z.ZodType<DiscordConfig>;
296
309
  declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
310
+ declare const LogStreamPatternSchema: z.ZodType<LogStreamPattern>;
311
+ declare const LogStreamPatternConfigSchema: z.ZodType<LogStreamPatternConfig>;
312
+ declare const LogStreamTemplateConfigSchema: z.ZodType<LogStreamTemplateConfig>;
313
+ declare const LogStreamNameSchema: z.ZodType<LogStreamName>;
297
314
  declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
298
315
  declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
299
316
  declare const LevelConfigSchema: z.ZodType<LevelConfig>;
@@ -306,6 +323,7 @@ declare const LoggerConfigSchema: z.ZodObject<{
306
323
  telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
307
324
  cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
308
325
  caller: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodType<CallerConfig, unknown, z.core.$ZodTypeInternals<CallerConfig, unknown>>]>>;
326
+ hostname: z.ZodOptional<z.ZodString>;
309
327
  }, z.core.$strip>;
310
328
  declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
311
329
  declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
@@ -316,6 +334,7 @@ declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
316
334
  telegram?: TelegramConfig | TelegramConfig[] | undefined;
317
335
  cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
318
336
  caller?: boolean | CallerConfig | undefined;
337
+ hostname?: string | undefined;
319
338
  }>;
320
339
 
321
- export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
340
+ export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CallerConfig, CallerConfigSchema, type CallerInfo, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, type LogStreamName, LogStreamNameSchema, type LogStreamPattern, type LogStreamPatternConfig, LogStreamPatternConfigSchema, LogStreamPatternSchema, type LogStreamTemplateConfig, LogStreamTemplateConfigSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var os = require('os');
3
4
  var pino = require('pino');
4
5
  var async_hooks = require('async_hooks');
5
6
  var stream = require('stream');
@@ -7,9 +8,9 @@ var promises = require('fs/promises');
7
8
  var rotatingFileStream = require('rotating-file-stream');
8
9
  var events = require('events');
9
10
  var clientCloudwatchLogs = require('@aws-sdk/client-cloudwatch-logs');
11
+ var crypto = require('crypto');
10
12
  var zod = require('zod');
11
13
  var path = require('path');
12
- var crypto = require('crypto');
13
14
 
14
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
 
@@ -421,13 +422,50 @@ var TelegramTransport = class extends BaseHttpTransport {
421
422
  return text.replace(/[&<>"']/g, (c) => entities[c] || c);
422
423
  }
423
424
  };
425
+ var instanceUuid = crypto.randomUUID().slice(0, 8);
426
+ function formatDate() {
427
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
428
+ }
429
+ function formatDateTime() {
430
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/[T:]/g, "-");
431
+ }
432
+ function resolveLogStreamName(config, configHostname) {
433
+ const hostname = configHostname || process.env.HOSTNAME || os.hostname();
434
+ if (!config) {
435
+ return hostname;
436
+ }
437
+ if (typeof config === "string") {
438
+ return config;
439
+ }
440
+ if ("pattern" in config) {
441
+ switch (config.pattern) {
442
+ case "hostname":
443
+ return hostname;
444
+ case "hostname-date":
445
+ return `${hostname}/${formatDate()}`;
446
+ case "hostname-uuid":
447
+ return `${hostname}-${instanceUuid}`;
448
+ case "date":
449
+ return formatDate();
450
+ case "uuid":
451
+ return crypto.randomUUID();
452
+ default:
453
+ return hostname;
454
+ }
455
+ }
456
+ if ("template" in config) {
457
+ return config.template.replace(/\{hostname\}/g, hostname).replace(/\{date\}/g, formatDate()).replace(/\{datetime\}/g, formatDateTime()).replace(/\{uuid\}/g, instanceUuid).replace(/\{pid\}/g, String(process.pid)).replace(/\{env\}/g, process.env.NODE_ENV || "development");
458
+ }
459
+ return hostname;
460
+ }
424
461
  var CloudWatchTransport = class extends BaseHttpTransport {
425
462
  config;
426
463
  client;
427
464
  sequenceToken;
428
465
  initialized = false;
429
466
  initPromise = null;
430
- constructor(config) {
467
+ resolvedLogStreamName;
468
+ constructor(config, configHostname) {
431
469
  super({
432
470
  batchSize: config.batchSize ?? 100,
433
471
  flushInterval: config.flushInterval ?? 1e3,
@@ -435,6 +473,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
435
473
  retryDelay: config.retryDelay
436
474
  });
437
475
  this.config = config;
476
+ this.resolvedLogStreamName = resolveLogStreamName(config.logStreamName, configHostname);
438
477
  this.client = new clientCloudwatchLogs.CloudWatchLogsClient({
439
478
  region: config.region,
440
479
  credentials: {
@@ -457,7 +496,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
457
496
  logEvents.sort((a, b) => (a.timestamp ?? 0) - (b.timestamp ?? 0));
458
497
  const command = new clientCloudwatchLogs.PutLogEventsCommand({
459
498
  logGroupName: this.config.logGroupName,
460
- logStreamName: this.config.logStreamName,
499
+ logStreamName: this.resolvedLogStreamName,
461
500
  logEvents,
462
501
  sequenceToken: this.sequenceToken
463
502
  });
@@ -469,7 +508,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
469
508
  await this.fetchSequenceToken();
470
509
  const retryCommand = new clientCloudwatchLogs.PutLogEventsCommand({
471
510
  logGroupName: this.config.logGroupName,
472
- logStreamName: this.config.logStreamName,
511
+ logStreamName: this.resolvedLogStreamName,
473
512
  logEvents,
474
513
  sequenceToken: this.sequenceToken
475
514
  });
@@ -515,7 +554,7 @@ var CloudWatchTransport = class extends BaseHttpTransport {
515
554
  await this.client.send(
516
555
  new clientCloudwatchLogs.CreateLogStreamCommand({
517
556
  logGroupName: this.config.logGroupName,
518
- logStreamName: this.config.logStreamName
557
+ logStreamName: this.resolvedLogStreamName
519
558
  })
520
559
  );
521
560
  } catch (error) {
@@ -528,11 +567,11 @@ var CloudWatchTransport = class extends BaseHttpTransport {
528
567
  const response = await this.client.send(
529
568
  new clientCloudwatchLogs.DescribeLogStreamsCommand({
530
569
  logGroupName: this.config.logGroupName,
531
- logStreamNamePrefix: this.config.logStreamName,
570
+ logStreamNamePrefix: this.resolvedLogStreamName,
532
571
  limit: 1
533
572
  })
534
573
  );
535
- const stream = response.logStreams?.find((s) => s.logStreamName === this.config.logStreamName);
574
+ const stream = response.logStreams?.find((s) => s.logStreamName === this.resolvedLogStreamName);
536
575
  this.sequenceToken = stream?.uploadSequenceToken;
537
576
  }
538
577
  isResourceAlreadyExistsError(error) {
@@ -712,7 +751,7 @@ function createStreams(config, store) {
712
751
  });
713
752
  }
714
753
  for (const cloudwatchConfig of toArray(config.cloudwatch)) {
715
- const transport = new CloudWatchTransport(cloudwatchConfig);
754
+ const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname);
716
755
  const cwStream = createHttpTransportStream(transport, cloudwatchConfig.level, cloudwatchConfig.rules, store);
717
756
  streams.push({
718
757
  level: "trace",
@@ -809,8 +848,7 @@ function createState(config, store) {
809
848
  level: "trace",
810
849
  // Accept all, we filter in shouldLog()
811
850
  customLevels: CUSTOM_LEVELS,
812
- base: void 0
813
- // Disable pid and hostname
851
+ base: { hostname: config.hostname ?? os.hostname() }
814
852
  };
815
853
  const pinoLogger = pino__default.default(options, streams);
816
854
  let callerConfig;
@@ -927,6 +965,24 @@ var TelegramConfigSchema = zod.z.object({
927
965
  threadId: zod.z.number().int().optional(),
928
966
  replyToMessageId: zod.z.number().int().optional()
929
967
  });
968
+ var LogStreamPatternSchema = zod.z.enum([
969
+ "hostname",
970
+ "hostname-date",
971
+ "hostname-uuid",
972
+ "date",
973
+ "uuid"
974
+ ]);
975
+ var LogStreamPatternConfigSchema = zod.z.object({
976
+ pattern: LogStreamPatternSchema
977
+ });
978
+ var LogStreamTemplateConfigSchema = zod.z.object({
979
+ template: zod.z.string().min(1, "template is required")
980
+ });
981
+ var LogStreamNameSchema = zod.z.union([
982
+ zod.z.string().min(1, "logStreamName string must not be empty"),
983
+ LogStreamPatternConfigSchema,
984
+ LogStreamTemplateConfigSchema
985
+ ]);
930
986
  var CloudWatchConfigSchema = zod.z.object({
931
987
  level: LogLevelSchema.optional(),
932
988
  rules: zod.z.array(LevelRuleSchema).optional(),
@@ -935,7 +991,7 @@ var CloudWatchConfigSchema = zod.z.object({
935
991
  maxRetries: zod.z.number().int().nonnegative().optional(),
936
992
  retryDelay: zod.z.number().int().positive().optional(),
937
993
  logGroupName: zod.z.string().min(1, "logGroupName is required"),
938
- logStreamName: zod.z.string().min(1, "logStreamName is required"),
994
+ logStreamName: LogStreamNameSchema.optional(),
939
995
  region: zod.z.string().min(1, "region is required"),
940
996
  accessKeyId: zod.z.string().min(1, "accessKeyId is required"),
941
997
  secretAccessKey: zod.z.string().min(1, "secretAccessKey is required"),
@@ -961,7 +1017,8 @@ var LoggerConfigSchema = zod.z.object({
961
1017
  discord: zod.z.union([DiscordConfigSchema, zod.z.array(DiscordConfigSchema)]).optional(),
962
1018
  telegram: zod.z.union([TelegramConfigSchema, zod.z.array(TelegramConfigSchema)]).optional(),
963
1019
  cloudwatch: zod.z.union([CloudWatchConfigSchema, zod.z.array(CloudWatchConfigSchema)]).optional(),
964
- caller: zod.z.union([zod.z.boolean(), CallerConfigSchema]).optional()
1020
+ caller: zod.z.union([zod.z.boolean(), CallerConfigSchema]).optional(),
1021
+ hostname: zod.z.string().optional()
965
1022
  });
966
1023
  function validateConfig(config) {
967
1024
  return LoggerConfigSchema.parse(config);
@@ -1401,6 +1458,10 @@ exports.LevelConfigSchema = LevelConfigSchema;
1401
1458
  exports.LevelRuleSchema = LevelRuleSchema;
1402
1459
  exports.LogFormatSchema = LogFormatSchema;
1403
1460
  exports.LogLevelSchema = LogLevelSchema;
1461
+ exports.LogStreamNameSchema = LogStreamNameSchema;
1462
+ exports.LogStreamPatternConfigSchema = LogStreamPatternConfigSchema;
1463
+ exports.LogStreamPatternSchema = LogStreamPatternSchema;
1464
+ exports.LogStreamTemplateConfigSchema = LogStreamTemplateConfigSchema;
1404
1465
  exports.Logger = Logger;
1405
1466
  exports.LoggerConfigSchema = LoggerConfigSchema;
1406
1467
  exports.LoggerStore = LoggerStore;