• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dev-ignis / cross-log / 16982792483

15 Aug 2025 04:15AM UTC coverage: 85.706% (-9.9%) from 95.62%
16982792483

push

github

dev-ignis
test: - ci;

489 of 647 branches covered (75.58%)

Branch coverage included in aggregate %.

944 of 1025 relevant lines covered (92.1%)

357.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.05
/src/core/types.ts
1
/**
2
 * Core types and interfaces for the universal logger
3
 */
4

5
// Log level definitions
6
export enum LogLevel {
42✔
7
  DEBUG = 0,   // Verbose information for debugging
42✔
8
  INFO = 1,    // General information
42✔
9
  WARN = 2,    // Warnings that don't affect functionality
42✔
10
  ERROR = 3,   // Errors that affect functionality
42✔
11
  SILENT = 4   // No logging
42✔
12
}
13

14
// Category-specific configuration
15
export interface CategoryConfig {
16
  enabled: boolean;
17
  minLevel: LogLevel;
18
}
19

20
// Color configuration for different environments
21
export interface ColorConfig {
22
  enabled: boolean;
23
  browser: BrowserColorConfig;
24
  ansi: AnsiColorConfig;
25
}
26

27
export interface BrowserColorConfig {
28
  debug: string;
29
  info: string;
30
  warn: string;
31
  error: string;
32
}
33

34
export interface AnsiColorConfig {
35
  debug: number;
36
  info: number;
37
  warn: number;
38
  error: number;
39
}
40

41
// Storage configuration (browser only)
42
export interface StorageConfig {
43
  enabled: boolean;
44
  keyPrefix: string;
45
}
46

47
// Browser controls configuration
48
export interface BrowserControlsConfig {
49
  enabled: boolean;
50
  windowNamespace: string;
51
}
52

53
// Main logger configuration interface
54
export interface LoggerConfig {
55
  enabled: boolean;
56
  minLevel: LogLevel;
57
  showTimestamp: boolean;
58
  includeStackTrace: boolean;
59
  categories: Record<string, CategoryConfig>;
60
  colors: ColorConfig;
61
  storage: StorageConfig;
62
  browserControls: BrowserControlsConfig;
63
}
64

65
// Environment detection interface
66
export interface Environment {
67
  isBrowser: boolean;
68
  isNode: boolean;
69
  isDevelopment: boolean;
70
  isProduction: boolean;
71
  runtime?: string;
72
}
73

74
// Logger interface that both browser and node loggers implement
75
export interface ILogger {
76
  debug(message: string, category?: string, ...args: unknown[]): void;
77
  info(message: string, category?: string, ...args: unknown[]): void;
78
  warn(message: string, category?: string, ...args: unknown[]): void;
79
  error(message: string | Error, category?: string, ...args: unknown[]): void;
80
  setLevel(level: LogLevel): void;
81
  configure(config: PartialLoggerConfig): void;
82
  enableCategory(category: string, minLevel?: LogLevel): void;
83
  disableCategory(category: string): void;
84
  enableAll(): void;
85
  disableAll(): void;
86
  getConfig(): LoggerConfig;
87
  isEnabled(): boolean;
88
  Level: typeof LogLevel;
89
}
90

91
// Log entry interface for internal use
92
export interface LogEntry {
93
  level: LogLevel;
94
  message: string;
95
  category: string | undefined;
96
  timestamp: Date;
97
  args: unknown[];
98
}
99

100
// Environment variable configuration interface
101
export interface EnvConfig {
102
  LOG_LEVEL: string | undefined;
103
  LOGGER_ENABLED: string | undefined;
104
  LOGGER_TIMESTAMPS: string | undefined;
105
  LOGGER_STACK_TRACES: string | undefined;
106
  LOGGER_COLORS: string | undefined;
107
  LOGGER_STORAGE_ENABLED: string | undefined;
108
  LOGGER_STORAGE_KEY_PREFIX: string | undefined;
109
  LOGGER_BROWSER_CONTROLS: string | undefined;
110
  LOGGER_WINDOW_NAMESPACE: string | undefined;
111
  LOGGER_COLOR_DEBUG: string | undefined;
112
  LOGGER_COLOR_INFO: string | undefined;
113
  LOGGER_COLOR_WARN: string | undefined;
114
  LOGGER_COLOR_ERROR: string | undefined;
115
  LOGGER_ANSI_DEBUG: string | undefined;
116
  LOGGER_ANSI_INFO: string | undefined;
117
  LOGGER_ANSI_WARN: string | undefined;
118
  LOGGER_ANSI_ERROR: string | undefined;
119
}
120

121
/**
122
 * Deep partial type that makes all properties and nested properties optional
123
 */
124
export type DeepPartial<T> = T extends object
125
  ? {
126
      [P in keyof T]?: DeepPartial<T[P]>;
127
    }
128
  : T;
129

130
/**
131
 * Helper type for partial logger configuration with better inference
132
 */
133
export type PartialLoggerConfig = {
134
  enabled?: boolean;
135
  minLevel?: LogLevel;
136
  showTimestamp?: boolean;
137
  includeStackTrace?: boolean;
138
  categories?: Record<string, Partial<CategoryConfig>>;
139
  colors?: {
140
    enabled?: boolean;
141
    browser?: Partial<BrowserColorConfig>;
142
    ansi?: Partial<AnsiColorConfig>;
143
  };
144
  storage?: Partial<StorageConfig>;
145
  browserControls?: Partial<BrowserControlsConfig>;
146
};
147

148
/**
149
 * Type for log level values (string or enum)
150
 */
151
export type LogLevelValue = LogLevel | keyof typeof LogLevel;
152

153
/**
154
 * Type guard to check if a value is a valid LogLevel
155
 */
156
export function isLogLevel(value: unknown): value is LogLevel {
42✔
157
  return typeof value === 'number' && value >= LogLevel.DEBUG && value <= LogLevel.SILENT;
×
158
}
159

160
/**
161
 * Type guard to check if a value is a valid LogLevel string
162
 */
163
export function isLogLevelString(value: unknown): value is keyof typeof LogLevel {
42✔
164
  return typeof value === 'string' && value in LogLevel;
×
165
}
166

167
/**
168
 * Deep merge configuration objects
169
 */
170
export function mergeConfig(base: LoggerConfig, partial: PartialLoggerConfig): LoggerConfig {
42✔
171
  const result = { ...base };
657✔
172

173
  if (partial.enabled !== undefined) result.enabled = partial.enabled;
657✔
174
  if (partial.minLevel !== undefined) result.minLevel = partial.minLevel;
657✔
175
  if (partial.showTimestamp !== undefined) result.showTimestamp = partial.showTimestamp;
657✔
176
  if (partial.includeStackTrace !== undefined) result.includeStackTrace = partial.includeStackTrace;
657✔
177

178
  if (partial.categories) {
657✔
179
    result.categories = { ...base.categories };
117✔
180
    // Merge partial category configs
181
    for (const [key, value] of Object.entries(partial.categories)) {
117✔
182
      if (value) {
69✔
183
        result.categories[key] = {
69✔
184
          enabled: value.enabled ?? base.categories[key]?.enabled ?? true,
414!
185
          minLevel: value.minLevel ?? base.categories[key]?.minLevel ?? LogLevel.DEBUG
414!
186
        };
187
      }
188
    }
189
  }
190

191
  if (partial.colors) {
657✔
192
    result.colors = {
255✔
193
      enabled: partial.colors.enabled ?? base.colors.enabled,
765!
194
      browser: partial.colors.browser ? { ...base.colors.browser, ...partial.colors.browser } : base.colors.browser,
255!
195
      ansi: partial.colors.ansi ? { ...base.colors.ansi, ...partial.colors.ansi } : base.colors.ansi
255!
196
    };
197
  }
198

199
  if (partial.storage) {
657✔
200
    result.storage = { ...base.storage, ...partial.storage };
156✔
201
  }
202

203
  if (partial.browserControls) {
657✔
204
    result.browserControls = { ...base.browserControls, ...partial.browserControls };
168✔
205
  }
206

207
  return result;
657✔
208
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc