|
| 1 | +--- |
| 2 | +title: LogEngine |
| 3 | +description: Complete API reference for the LogEngine singleton |
| 4 | +icon: code |
| 5 | +--- |
| 6 | + |
| 7 | +The `LogEngine` object is the main interface for all logging operations. It's a singleton that provides a simple, intuitive API with security-first design. |
| 8 | + |
| 9 | +```typescript |
| 10 | +import { LogEngine } from '@wgtechlabs/log-engine'; |
| 11 | +``` |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +### configure |
| 16 | + |
| 17 | +Configure the logger with new settings. |
| 18 | + |
| 19 | +```typescript |
| 20 | +LogEngine.configure(config: Partial<LoggerConfig>): void |
| 21 | +``` |
| 22 | + |
| 23 | +<ParamField body="config" type="Partial<LoggerConfig>" required> |
| 24 | + Configuration object. See [LoggerConfig](/api-reference/types#loggerconfig) for all options. |
| 25 | +</ParamField> |
| 26 | + |
| 27 | +```typescript |
| 28 | +LogEngine.configure({ |
| 29 | + mode: LogMode.DEBUG, |
| 30 | + format: { |
| 31 | + includeIsoTimestamp: true, |
| 32 | + includeLocalTime: true, |
| 33 | + includeEmoji: true |
| 34 | + } |
| 35 | +}); |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Logging Methods |
| 41 | + |
| 42 | +All standard logging methods accept the same parameters: |
| 43 | + |
| 44 | +<ParamField body="message" type="string" required> |
| 45 | + The log message to display. |
| 46 | +</ParamField> |
| 47 | + |
| 48 | +<ParamField body="data" type="LogData"> |
| 49 | + Optional data object to log. Sensitive fields are automatically redacted. |
| 50 | +</ParamField> |
| 51 | + |
| 52 | +<ParamField body="options" type="LogCallOptions"> |
| 53 | + Optional per-call options (e.g., emoji override). |
| 54 | +</ParamField> |
| 55 | + |
| 56 | +### debug |
| 57 | + |
| 58 | +Log a debug message. Only shown in DEBUG mode. |
| 59 | + |
| 60 | +```typescript |
| 61 | +LogEngine.debug(message: string, data?: LogData, options?: LogCallOptions): void |
| 62 | +``` |
| 63 | + |
| 64 | +### info |
| 65 | + |
| 66 | +Log an info message. Shown in DEBUG and INFO modes. |
| 67 | + |
| 68 | +```typescript |
| 69 | +LogEngine.info(message: string, data?: LogData, options?: LogCallOptions): void |
| 70 | +``` |
| 71 | + |
| 72 | +### warn |
| 73 | + |
| 74 | +Log a warning message. Shown in DEBUG, INFO, and WARN modes. |
| 75 | + |
| 76 | +```typescript |
| 77 | +LogEngine.warn(message: string, data?: LogData, options?: LogCallOptions): void |
| 78 | +``` |
| 79 | + |
| 80 | +### error |
| 81 | + |
| 82 | +Log an error message. Shown in DEBUG, INFO, WARN, and ERROR modes. |
| 83 | + |
| 84 | +```typescript |
| 85 | +LogEngine.error(message: string, data?: LogData, options?: LogCallOptions): void |
| 86 | +``` |
| 87 | + |
| 88 | +### log |
| 89 | + |
| 90 | +Log a critical message. Always shown regardless of mode (except OFF). |
| 91 | + |
| 92 | +```typescript |
| 93 | +LogEngine.log(message: string, data?: LogData, options?: LogCallOptions): void |
| 94 | +``` |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Raw Logging Methods |
| 99 | + |
| 100 | +<Warning> |
| 101 | + Raw methods bypass all data redaction. Use with caution. |
| 102 | +</Warning> |
| 103 | + |
| 104 | +### debugRaw / infoRaw / warnRaw / errorRaw / logRaw |
| 105 | + |
| 106 | +Same signature as standard methods, but without automatic redaction: |
| 107 | + |
| 108 | +```typescript |
| 109 | +LogEngine.debugRaw(message: string, data?: LogData, options?: LogCallOptions): void |
| 110 | +LogEngine.infoRaw(message: string, data?: LogData, options?: LogCallOptions): void |
| 111 | +LogEngine.warnRaw(message: string, data?: LogData, options?: LogCallOptions): void |
| 112 | +LogEngine.errorRaw(message: string, data?: LogData, options?: LogCallOptions): void |
| 113 | +LogEngine.logRaw(message: string, data?: LogData, options?: LogCallOptions): void |
| 114 | +``` |
| 115 | + |
| 116 | +### withoutRedaction |
| 117 | + |
| 118 | +Returns a LogEngine instance with redaction bypassed. |
| 119 | + |
| 120 | +```typescript |
| 121 | +LogEngine.withoutRedaction(): ILogEngineWithoutRedaction |
| 122 | +``` |
| 123 | + |
| 124 | +```typescript |
| 125 | +LogEngine.withoutRedaction().info('Debug data', sensitiveObject); |
| 126 | +``` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Redaction Configuration |
| 131 | + |
| 132 | +### configureRedaction |
| 133 | + |
| 134 | +Configure data redaction settings. |
| 135 | + |
| 136 | +```typescript |
| 137 | +LogEngine.configureRedaction(config: Partial<RedactionConfig>): void |
| 138 | +``` |
| 139 | + |
| 140 | +```typescript |
| 141 | +LogEngine.configureRedaction({ |
| 142 | + redactionText: '***HIDDEN***', |
| 143 | + maxContentLength: 200, |
| 144 | + sensitiveFields: ['myCustomField', 'internalSecret'] |
| 145 | +}); |
| 146 | +``` |
| 147 | + |
| 148 | +### getRedactionConfig |
| 149 | + |
| 150 | +Get the current redaction configuration. |
| 151 | + |
| 152 | +```typescript |
| 153 | +LogEngine.getRedactionConfig(): RedactionConfig |
| 154 | +``` |
| 155 | + |
| 156 | +### refreshRedactionConfig |
| 157 | + |
| 158 | +Refresh redaction configuration from environment variables. |
| 159 | + |
| 160 | +```typescript |
| 161 | +LogEngine.refreshRedactionConfig(): void |
| 162 | +``` |
| 163 | + |
| 164 | +### resetRedactionConfig |
| 165 | + |
| 166 | +Reset redaction configuration to defaults. |
| 167 | + |
| 168 | +```typescript |
| 169 | +LogEngine.resetRedactionConfig(): void |
| 170 | +``` |
| 171 | + |
| 172 | +### addCustomRedactionPatterns |
| 173 | + |
| 174 | +Add custom regex patterns for advanced field detection. |
| 175 | + |
| 176 | +```typescript |
| 177 | +LogEngine.addCustomRedactionPatterns(patterns: RegExp[]): void |
| 178 | +``` |
| 179 | + |
| 180 | +```typescript |
| 181 | +LogEngine.addCustomRedactionPatterns([/internal.*/i, /company.*/i]); |
| 182 | +``` |
| 183 | + |
| 184 | +### clearCustomRedactionPatterns |
| 185 | + |
| 186 | +Clear all custom redaction patterns. |
| 187 | + |
| 188 | +```typescript |
| 189 | +LogEngine.clearCustomRedactionPatterns(): void |
| 190 | +``` |
| 191 | + |
| 192 | +### addSensitiveFields |
| 193 | + |
| 194 | +Add custom sensitive field names to the existing list. |
| 195 | + |
| 196 | +```typescript |
| 197 | +LogEngine.addSensitiveFields(fields: string[]): void |
| 198 | +``` |
| 199 | + |
| 200 | +```typescript |
| 201 | +LogEngine.addSensitiveFields(['companySecret', 'internalToken']); |
| 202 | +``` |
| 203 | + |
| 204 | +### testFieldRedaction |
| 205 | + |
| 206 | +Test if a field name would be redacted with the current configuration. |
| 207 | + |
| 208 | +```typescript |
| 209 | +LogEngine.testFieldRedaction(fieldName: string): boolean |
| 210 | +``` |
| 211 | + |
| 212 | +```typescript |
| 213 | +LogEngine.testFieldRedaction('password'); // true |
| 214 | +LogEngine.testFieldRedaction('username'); // false |
| 215 | +``` |
0 commit comments