hazo_logs 1.0.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.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config_loader.d.ts +12 -0
- package/dist/lib/config_loader.d.ts.map +1 -0
- package/dist/lib/config_loader.js +81 -0
- package/dist/lib/config_loader.js.map +1 -0
- package/dist/lib/context/index.d.ts +5 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/index.js +5 -0
- package/dist/lib/context/index.js.map +1 -0
- package/dist/lib/context/log-context.d.ts +83 -0
- package/dist/lib/context/log-context.d.ts.map +1 -0
- package/dist/lib/context/log-context.js +136 -0
- package/dist/lib/context/log-context.js.map +1 -0
- package/dist/lib/hazo_logger.d.ts +40 -0
- package/dist/lib/hazo_logger.d.ts.map +1 -0
- package/dist/lib/hazo_logger.js +82 -0
- package/dist/lib/hazo_logger.js.map +1 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +5 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/log-reader.d.ts +51 -0
- package/dist/lib/log-reader.d.ts.map +1 -0
- package/dist/lib/log-reader.js +248 -0
- package/dist/lib/log-reader.js.map +1 -0
- package/dist/lib/package_logger.d.ts +27 -0
- package/dist/lib/package_logger.d.ts.map +1 -0
- package/dist/lib/package_logger.js +57 -0
- package/dist/lib/package_logger.js.map +1 -0
- package/dist/lib/transports/console_transport.d.ts +10 -0
- package/dist/lib/transports/console_transport.d.ts.map +1 -0
- package/dist/lib/transports/console_transport.js +21 -0
- package/dist/lib/transports/console_transport.js.map +1 -0
- package/dist/lib/transports/file_transport.d.ts +10 -0
- package/dist/lib/transports/file_transport.d.ts.map +1 -0
- package/dist/lib/transports/file_transport.js +56 -0
- package/dist/lib/transports/file_transport.js.map +1 -0
- package/dist/lib/transports/index.d.ts +3 -0
- package/dist/lib/transports/index.d.ts.map +1 -0
- package/dist/lib/transports/index.js +3 -0
- package/dist/lib/transports/index.js.map +1 -0
- package/dist/lib/types.d.ts +66 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +5 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils/caller_info.d.ts +13 -0
- package/dist/lib/utils/caller_info.d.ts.map +1 -0
- package/dist/lib/utils/caller_info.js +65 -0
- package/dist/lib/utils/caller_info.js.map +1 -0
- package/dist/lib/utils/constants.d.ts +16 -0
- package/dist/lib/utils/constants.d.ts.map +1 -0
- package/dist/lib/utils/constants.js +27 -0
- package/dist/lib/utils/constants.js.map +1 -0
- package/dist/lib/utils/index.d.ts +3 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +3 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/ui/api/log-api-handler.d.ts +21 -0
- package/dist/ui/api/log-api-handler.d.ts.map +1 -0
- package/dist/ui/api/log-api-handler.js +151 -0
- package/dist/ui/api/log-api-handler.js.map +1 -0
- package/dist/ui/components/LogLevelBadge.d.ts +6 -0
- package/dist/ui/components/LogLevelBadge.d.ts.map +1 -0
- package/dist/ui/components/LogLevelBadge.js +16 -0
- package/dist/ui/components/LogLevelBadge.js.map +1 -0
- package/dist/ui/components/LogPagination.d.ts +6 -0
- package/dist/ui/components/LogPagination.d.ts.map +1 -0
- package/dist/ui/components/LogPagination.js +14 -0
- package/dist/ui/components/LogPagination.js.map +1 -0
- package/dist/ui/components/LogTable.d.ts +6 -0
- package/dist/ui/components/LogTable.d.ts.map +1 -0
- package/dist/ui/components/LogTable.js +33 -0
- package/dist/ui/components/LogTable.js.map +1 -0
- package/dist/ui/components/LogTimeline.d.ts +10 -0
- package/dist/ui/components/LogTimeline.d.ts.map +1 -0
- package/dist/ui/components/LogTimeline.js +95 -0
- package/dist/ui/components/LogTimeline.js.map +1 -0
- package/dist/ui/components/LogViewerPage.d.ts +6 -0
- package/dist/ui/components/LogViewerPage.d.ts.map +1 -0
- package/dist/ui/components/LogViewerPage.js +273 -0
- package/dist/ui/components/LogViewerPage.js.map +1 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +12 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/middleware/with-log-auth.d.ts +25 -0
- package/dist/ui/middleware/with-log-auth.d.ts.map +1 -0
- package/dist/ui/middleware/with-log-auth.js +49 -0
- package/dist/ui/middleware/with-log-auth.js.map +1 -0
- package/dist/ui/server.d.ts +9 -0
- package/dist/ui/server.d.ts.map +1 -0
- package/dist/ui/server.js +10 -0
- package/dist/ui/server.js.map +1 -0
- package/dist/ui/types.d.ts +135 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +5 -0
- package/dist/ui/types.js.map +1 -0
- package/hazo_logs_config.example.ini +47 -0
- package/package.json +81 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_logs - Winston logger wrapper with singleton pattern
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { createLogger, runWithLogContext } from 'hazo_logs';
|
|
6
|
+
*
|
|
7
|
+
* const logger = createLogger('my_package');
|
|
8
|
+
*
|
|
9
|
+
* // Basic logging
|
|
10
|
+
* logger.info('Hello world', { key: 'value' });
|
|
11
|
+
*
|
|
12
|
+
* // With context (session/user tracking)
|
|
13
|
+
* runWithLogContext({ sessionId: 'sess_123', reference: 'user_42' }, () => {
|
|
14
|
+
* logger.info('User action'); // automatically includes sessionId and reference
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* For UI components (requires Next.js, React, and hazo_ui):
|
|
18
|
+
* import { LogViewerPage, createLogApiHandler } from 'hazo_logs/ui';
|
|
19
|
+
*/
|
|
20
|
+
export { HazoLogger } from './lib/hazo_logger.js';
|
|
21
|
+
export { PackageLogger, createLogger } from './lib/package_logger.js';
|
|
22
|
+
export { loadConfig } from './lib/config_loader.js';
|
|
23
|
+
export { generateSessionId, startSession, startSessionAsync, runWithLogContext, runWithLogContextAsync, getLogContext, withSession, withContext, } from './lib/context/log-context.js';
|
|
24
|
+
export { readLogs, getAvailableLogDates, getUniquePackages, getUniqueExecutionIds, getUniqueSessionIds, getUniqueReferences, } from './lib/log-reader.js';
|
|
25
|
+
export type { Logger, LogLevel, LogData, LogEntry, LogContext, HazoLogConfig, PackageLoggerOptions, } from './lib/types.js';
|
|
26
|
+
export type { ReadLogsOptions, LogQueryResult } from './lib/log-reader.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,EACb,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_logs - Winston logger wrapper with singleton pattern
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { createLogger, runWithLogContext } from 'hazo_logs';
|
|
6
|
+
*
|
|
7
|
+
* const logger = createLogger('my_package');
|
|
8
|
+
*
|
|
9
|
+
* // Basic logging
|
|
10
|
+
* logger.info('Hello world', { key: 'value' });
|
|
11
|
+
*
|
|
12
|
+
* // With context (session/user tracking)
|
|
13
|
+
* runWithLogContext({ sessionId: 'sess_123', reference: 'user_42' }, () => {
|
|
14
|
+
* logger.info('User action'); // automatically includes sessionId and reference
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* For UI components (requires Next.js, React, and hazo_ui):
|
|
18
|
+
* import { LogViewerPage, createLogApiHandler } from 'hazo_logs/ui';
|
|
19
|
+
*/
|
|
20
|
+
// Core logging
|
|
21
|
+
export { HazoLogger } from './lib/hazo_logger.js';
|
|
22
|
+
export { PackageLogger, createLogger } from './lib/package_logger.js';
|
|
23
|
+
export { loadConfig } from './lib/config_loader.js';
|
|
24
|
+
// Log context
|
|
25
|
+
export { generateSessionId, startSession, startSessionAsync, runWithLogContext, runWithLogContextAsync, getLogContext, withSession, withContext, } from './lib/context/log-context.js';
|
|
26
|
+
// Log reader
|
|
27
|
+
export { readLogs, getAvailableLogDates, getUniquePackages, getUniqueExecutionIds, getUniqueSessionIds, getUniqueReferences, } from './lib/log-reader.js';
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,eAAe;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,cAAc;AACd,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,8BAA8B,CAAC;AAEtC,aAAa;AACb,OAAO,EACL,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader for hazo_logs
|
|
3
|
+
* Loads settings from hazo_logs_config.ini file
|
|
4
|
+
*/
|
|
5
|
+
import type { HazoLogConfig } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Load configuration from INI file
|
|
8
|
+
* @param configPath - Optional explicit path to config file
|
|
9
|
+
* @returns Parsed configuration with defaults applied
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadConfig(configPath?: string): HazoLogConfig;
|
|
12
|
+
//# sourceMappingURL=config_loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config_loader.d.ts","sourceRoot":"","sources":["../../src/lib/config_loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,YAAY,CAAC;AAK1D;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CA8B7D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader for hazo_logs
|
|
3
|
+
* Loads settings from hazo_logs_config.ini file
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import ini from 'ini';
|
|
8
|
+
import { DEFAULT_CONFIG } from './utils/constants.js';
|
|
9
|
+
const CONFIG_FILENAME = 'hazo_logs_config.ini';
|
|
10
|
+
/**
|
|
11
|
+
* Load configuration from INI file
|
|
12
|
+
* @param configPath - Optional explicit path to config file
|
|
13
|
+
* @returns Parsed configuration with defaults applied
|
|
14
|
+
*/
|
|
15
|
+
export function loadConfig(configPath) {
|
|
16
|
+
const resolvedPath = configPath || findConfigFile();
|
|
17
|
+
if (!resolvedPath || !fs.existsSync(resolvedPath)) {
|
|
18
|
+
console.warn(`[HazoLog] Config file not found, using defaults`);
|
|
19
|
+
return { ...DEFAULT_CONFIG };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const content = fs.readFileSync(resolvedPath, 'utf-8');
|
|
23
|
+
const parsed = ini.parse(content);
|
|
24
|
+
const logsSection = parsed['hazo_logs'] || {};
|
|
25
|
+
return {
|
|
26
|
+
log_directory: logsSection.log_directory || DEFAULT_CONFIG.log_directory,
|
|
27
|
+
log_level: validateLogLevel(logsSection.log_level),
|
|
28
|
+
enable_console: parseBool(logsSection.enable_console, DEFAULT_CONFIG.enable_console),
|
|
29
|
+
enable_file: parseBool(logsSection.enable_file, DEFAULT_CONFIG.enable_file),
|
|
30
|
+
max_file_size: logsSection.max_file_size || DEFAULT_CONFIG.max_file_size,
|
|
31
|
+
max_files: logsSection.max_files || DEFAULT_CONFIG.max_files,
|
|
32
|
+
date_pattern: logsSection.date_pattern || DEFAULT_CONFIG.date_pattern,
|
|
33
|
+
// Log Viewer UI settings
|
|
34
|
+
enable_log_viewer: parseBool(logsSection.enable_log_viewer, DEFAULT_CONFIG.enable_log_viewer),
|
|
35
|
+
log_viewer_page_size: parseInt(logsSection.log_viewer_page_size, 10) || DEFAULT_CONFIG.log_viewer_page_size,
|
|
36
|
+
log_viewer_max_results: parseInt(logsSection.log_viewer_max_results, 10) || DEFAULT_CONFIG.log_viewer_max_results,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`[HazoLog] Failed to load config: ${error}`);
|
|
41
|
+
return { ...DEFAULT_CONFIG };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Search for config file in current directory and parent directories
|
|
46
|
+
*/
|
|
47
|
+
function findConfigFile() {
|
|
48
|
+
const searchPaths = [
|
|
49
|
+
process.cwd(),
|
|
50
|
+
path.join(process.cwd(), '..'),
|
|
51
|
+
path.join(process.cwd(), '..', '..'),
|
|
52
|
+
path.join(process.cwd(), '..', '..', '..'),
|
|
53
|
+
];
|
|
54
|
+
for (const searchPath of searchPaths) {
|
|
55
|
+
const configPath = path.join(searchPath, CONFIG_FILENAME);
|
|
56
|
+
if (fs.existsSync(configPath)) {
|
|
57
|
+
return configPath;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validate and return a valid log level
|
|
64
|
+
*/
|
|
65
|
+
function validateLogLevel(level) {
|
|
66
|
+
const validLevels = ['error', 'warn', 'info', 'debug'];
|
|
67
|
+
return validLevels.includes(level) ? level : DEFAULT_CONFIG.log_level;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parse boolean from string or boolean value
|
|
71
|
+
* The ini package may return boolean or string depending on the value
|
|
72
|
+
*/
|
|
73
|
+
function parseBool(value, defaultValue) {
|
|
74
|
+
if (value === undefined)
|
|
75
|
+
return defaultValue;
|
|
76
|
+
if (typeof value === 'boolean')
|
|
77
|
+
return value;
|
|
78
|
+
const strValue = String(value).toLowerCase();
|
|
79
|
+
return strValue === 'true' || strValue === '1';
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=config_loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config_loader.js","sourceRoot":"","sources":["../../src/lib/config_loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAA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E,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IAC7C,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,GAAG,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/context/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/context/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log Context Provider
|
|
3
|
+
* Uses AsyncLocalStorage for zero-overhead context propagation
|
|
4
|
+
*/
|
|
5
|
+
import type { LogContext, Logger } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate a human-readable session ID
|
|
8
|
+
* Format: 2025-12-17-14:30:45-1234 (date-time-4digit)
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateSessionId(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Start a new session with auto-generated ID and optional auto-logging
|
|
13
|
+
* Depth starts at 1 for new sessions
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* startSession({ reference: 'user_42', logger: myLogger }, () => {
|
|
17
|
+
* // All logs in this block will have the session context
|
|
18
|
+
* logger.info('Processing request');
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
export declare function startSession<T>(options: {
|
|
22
|
+
reference?: string;
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
}, fn: () => T): T;
|
|
25
|
+
/**
|
|
26
|
+
* Start a new async session with auto-generated ID and optional auto-logging
|
|
27
|
+
* Depth starts at 1 for new sessions
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* await startSessionAsync({ reference: 'user_42', logger: myLogger }, async () => {
|
|
31
|
+
* await processRequest();
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export declare function startSessionAsync<T>(options: {
|
|
35
|
+
reference?: string;
|
|
36
|
+
logger?: Logger;
|
|
37
|
+
}, fn: () => Promise<T>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Run code within a log context
|
|
40
|
+
* All logs created within the callback will include the context
|
|
41
|
+
* Automatically inherits sessionId/reference from parent and increments depth
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* runWithLogContext({ sessionId: 'sess_123', reference: 'user_42' }, () => {
|
|
45
|
+
* logger.info('User action'); // includes sessionId and reference
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
export declare function runWithLogContext<T>(context: LogContext, fn: () => T): T;
|
|
49
|
+
/**
|
|
50
|
+
* Run async code within a log context
|
|
51
|
+
* Useful for middleware that needs to await the callback
|
|
52
|
+
* Automatically inherits sessionId/reference from parent and increments depth
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* await runWithLogContextAsync({ sessionId: req.sessionID }, async () => {
|
|
56
|
+
* await handleRequest(req, res);
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
export declare function runWithLogContextAsync<T>(context: LogContext, fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the current log context (used internally by logger)
|
|
62
|
+
* Returns undefined if not within a context
|
|
63
|
+
*/
|
|
64
|
+
export declare function getLogContext(): LogContext | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Convenience function to run code with just a session ID
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* withSession('sess_123', () => {
|
|
70
|
+
* logger.info('Session started');
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
export declare function withSession<T>(sessionId: string, fn: () => T): T;
|
|
74
|
+
/**
|
|
75
|
+
* Convenience function to run code with session and reference
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* withContext('sess_123', 'user_42', () => {
|
|
79
|
+
* logger.info('User logged in');
|
|
80
|
+
* });
|
|
81
|
+
*/
|
|
82
|
+
export declare function withContext<T>(sessionId: string, reference: string, fn: () => T): T;
|
|
83
|
+
//# sourceMappingURL=log-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-context.d.ts","sourceRoot":"","sources":["../../../src/lib/context/log-context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAItD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAM1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAChD,EAAE,EAAE,MAAM,CAAC,GACV,CAAC,CAcH;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAChD,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAcZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAaxE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,UAAU,EACnB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEnF"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log Context Provider
|
|
3
|
+
* Uses AsyncLocalStorage for zero-overhead context propagation
|
|
4
|
+
*/
|
|
5
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
6
|
+
const logContextStorage = new AsyncLocalStorage();
|
|
7
|
+
/**
|
|
8
|
+
* Generate a human-readable session ID
|
|
9
|
+
* Format: 2025-12-17-14:30:45-1234 (date-time-4digit)
|
|
10
|
+
*/
|
|
11
|
+
export function generateSessionId() {
|
|
12
|
+
const now = new Date();
|
|
13
|
+
const datePart = now.toISOString().split('T')[0]; // 2025-12-17
|
|
14
|
+
const timePart = now.toTimeString().split(' ')[0]; // 14:30:45
|
|
15
|
+
const randomPart = Math.floor(1000 + Math.random() * 9000).toString(); // 4-digit: 1000-9999
|
|
16
|
+
return `${datePart}-${timePart}-${randomPart}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Start a new session with auto-generated ID and optional auto-logging
|
|
20
|
+
* Depth starts at 1 for new sessions
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* startSession({ reference: 'user_42', logger: myLogger }, () => {
|
|
24
|
+
* // All logs in this block will have the session context
|
|
25
|
+
* logger.info('Processing request');
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
export function startSession(options, fn) {
|
|
29
|
+
const sessionId = generateSessionId();
|
|
30
|
+
return logContextStorage.run({ sessionId, reference: options.reference, depth: 1 }, () => {
|
|
31
|
+
// Auto-log session start if logger provided
|
|
32
|
+
if (options.logger) {
|
|
33
|
+
options.logger.info('Session started', {
|
|
34
|
+
sessionId,
|
|
35
|
+
reference: options.reference,
|
|
36
|
+
startTime: new Date().toISOString()
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return fn();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Start a new async session with auto-generated ID and optional auto-logging
|
|
44
|
+
* Depth starts at 1 for new sessions
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* await startSessionAsync({ reference: 'user_42', logger: myLogger }, async () => {
|
|
48
|
+
* await processRequest();
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
export async function startSessionAsync(options, fn) {
|
|
52
|
+
const sessionId = generateSessionId();
|
|
53
|
+
return logContextStorage.run({ sessionId, reference: options.reference, depth: 1 }, async () => {
|
|
54
|
+
// Auto-log session start if logger provided
|
|
55
|
+
if (options.logger) {
|
|
56
|
+
options.logger.info('Session started', {
|
|
57
|
+
sessionId,
|
|
58
|
+
reference: options.reference,
|
|
59
|
+
startTime: new Date().toISOString()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return await fn();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Run code within a log context
|
|
67
|
+
* All logs created within the callback will include the context
|
|
68
|
+
* Automatically inherits sessionId/reference from parent and increments depth
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* runWithLogContext({ sessionId: 'sess_123', reference: 'user_42' }, () => {
|
|
72
|
+
* logger.info('User action'); // includes sessionId and reference
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
export function runWithLogContext(context, fn) {
|
|
76
|
+
const parentContext = logContextStorage.getStore();
|
|
77
|
+
const parentDepth = parentContext?.depth ?? 0;
|
|
78
|
+
const newContext = {
|
|
79
|
+
// Use provided values or inherit from parent
|
|
80
|
+
sessionId: context.sessionId ?? parentContext?.sessionId,
|
|
81
|
+
reference: context.reference ?? parentContext?.reference,
|
|
82
|
+
// Auto-increment depth
|
|
83
|
+
depth: parentDepth + 1,
|
|
84
|
+
};
|
|
85
|
+
return logContextStorage.run(newContext, fn);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Run async code within a log context
|
|
89
|
+
* Useful for middleware that needs to await the callback
|
|
90
|
+
* Automatically inherits sessionId/reference from parent and increments depth
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* await runWithLogContextAsync({ sessionId: req.sessionID }, async () => {
|
|
94
|
+
* await handleRequest(req, res);
|
|
95
|
+
* });
|
|
96
|
+
*/
|
|
97
|
+
export function runWithLogContextAsync(context, fn) {
|
|
98
|
+
const parentContext = logContextStorage.getStore();
|
|
99
|
+
const parentDepth = parentContext?.depth ?? 0;
|
|
100
|
+
const newContext = {
|
|
101
|
+
sessionId: context.sessionId ?? parentContext?.sessionId,
|
|
102
|
+
reference: context.reference ?? parentContext?.reference,
|
|
103
|
+
depth: parentDepth + 1,
|
|
104
|
+
};
|
|
105
|
+
return logContextStorage.run(newContext, fn);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the current log context (used internally by logger)
|
|
109
|
+
* Returns undefined if not within a context
|
|
110
|
+
*/
|
|
111
|
+
export function getLogContext() {
|
|
112
|
+
return logContextStorage.getStore();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convenience function to run code with just a session ID
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* withSession('sess_123', () => {
|
|
119
|
+
* logger.info('Session started');
|
|
120
|
+
* });
|
|
121
|
+
*/
|
|
122
|
+
export function withSession(sessionId, fn) {
|
|
123
|
+
return runWithLogContext({ sessionId }, fn);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convenience function to run code with session and reference
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* withContext('sess_123', 'user_42', () => {
|
|
130
|
+
* logger.info('User logged in');
|
|
131
|
+
* });
|
|
132
|
+
*/
|
|
133
|
+
export function withContext(sessionId, reference, fn) {
|
|
134
|
+
return runWithLogContext({ sessionId, reference }, fn);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=log-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-context.js","sourceRoot":"","sources":["../../../src/lib/context/log-context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAc,CAAC;AAE9D;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa;IAC/D,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,qBAAqB;IAC5F,OAAO,GAAG,QAAQ,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,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CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core singleton logger for hazo_logs
|
|
3
|
+
* Manages the Winston logger instance and transports
|
|
4
|
+
*/
|
|
5
|
+
import type { HazoLogConfig, LogEntry } from './types.js';
|
|
6
|
+
export declare class HazoLogger {
|
|
7
|
+
private static instance;
|
|
8
|
+
private winstonLogger;
|
|
9
|
+
private config;
|
|
10
|
+
private executionId;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Generate a human-readable execution ID
|
|
14
|
+
* Format: 2025-12-17-14:30:45-1234 (date-time-4digit)
|
|
15
|
+
*/
|
|
16
|
+
private generateExecutionId;
|
|
17
|
+
/**
|
|
18
|
+
* Get the singleton instance of HazoLogger
|
|
19
|
+
* @param configPath - Optional path to config file (only used on first call)
|
|
20
|
+
*/
|
|
21
|
+
static getInstance(configPath?: string): HazoLogger;
|
|
22
|
+
/**
|
|
23
|
+
* Reset the singleton instance (primarily for testing)
|
|
24
|
+
*/
|
|
25
|
+
static reset(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log an entry - called by PackageLogger
|
|
28
|
+
*/
|
|
29
|
+
log(entry: LogEntry): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get current configuration
|
|
32
|
+
*/
|
|
33
|
+
getConfig(): HazoLogConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Get the execution ID (unique per server start)
|
|
36
|
+
*/
|
|
37
|
+
getExecutionId(): string;
|
|
38
|
+
private createWinstonLogger;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=hazo_logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_logger.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAK1D,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2B;IAClD,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAMP;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;OAGG;WACW,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU;IAO1D;;OAEG;WACW,KAAK,IAAI,IAAI;IAO3B;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAKjC;;OAEG;IACI,SAAS,IAAI,aAAa;IAIjC;;OAEG;IACI,cAAc,IAAI,MAAM;IAI/B,OAAO,CAAC,mBAAmB;CAgB5B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core singleton logger for hazo_logs
|
|
3
|
+
* Manages the Winston logger instance and transports
|
|
4
|
+
*/
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
import { loadConfig } from './config_loader.js';
|
|
7
|
+
import { createConsoleTransport } from './transports/console_transport.js';
|
|
8
|
+
import { createFileTransport } from './transports/file_transport.js';
|
|
9
|
+
export class HazoLogger {
|
|
10
|
+
static instance = null;
|
|
11
|
+
winstonLogger;
|
|
12
|
+
config;
|
|
13
|
+
executionId;
|
|
14
|
+
constructor(configPath) {
|
|
15
|
+
this.executionId = this.generateExecutionId();
|
|
16
|
+
this.config = loadConfig(configPath);
|
|
17
|
+
this.winstonLogger = this.createWinstonLogger();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate a human-readable execution ID
|
|
21
|
+
* Format: 2025-12-17-14:30:45-1234 (date-time-4digit)
|
|
22
|
+
*/
|
|
23
|
+
generateExecutionId() {
|
|
24
|
+
const now = new Date();
|
|
25
|
+
const datePart = now.toISOString().split('T')[0]; // 2025-12-17
|
|
26
|
+
const timePart = now.toTimeString().split(' ')[0]; // 14:30:45
|
|
27
|
+
const randomPart = Math.floor(1000 + Math.random() * 9000).toString(); // 4-digit: 1000-9999
|
|
28
|
+
return `${datePart}-${timePart}-${randomPart}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the singleton instance of HazoLogger
|
|
32
|
+
* @param configPath - Optional path to config file (only used on first call)
|
|
33
|
+
*/
|
|
34
|
+
static getInstance(configPath) {
|
|
35
|
+
if (!HazoLogger.instance) {
|
|
36
|
+
HazoLogger.instance = new HazoLogger(configPath);
|
|
37
|
+
}
|
|
38
|
+
return HazoLogger.instance;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reset the singleton instance (primarily for testing)
|
|
42
|
+
*/
|
|
43
|
+
static reset() {
|
|
44
|
+
if (HazoLogger.instance) {
|
|
45
|
+
HazoLogger.instance.winstonLogger.close();
|
|
46
|
+
HazoLogger.instance = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Log an entry - called by PackageLogger
|
|
51
|
+
*/
|
|
52
|
+
log(entry) {
|
|
53
|
+
const { level, message, ...meta } = entry;
|
|
54
|
+
this.winstonLogger.log(level, message, meta);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get current configuration
|
|
58
|
+
*/
|
|
59
|
+
getConfig() {
|
|
60
|
+
return { ...this.config };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the execution ID (unique per server start)
|
|
64
|
+
*/
|
|
65
|
+
getExecutionId() {
|
|
66
|
+
return this.executionId;
|
|
67
|
+
}
|
|
68
|
+
createWinstonLogger() {
|
|
69
|
+
const transports = [];
|
|
70
|
+
if (this.config.enable_console) {
|
|
71
|
+
transports.push(createConsoleTransport(this.config.log_level));
|
|
72
|
+
}
|
|
73
|
+
if (this.config.enable_file) {
|
|
74
|
+
transports.push(createFileTransport(this.config));
|
|
75
|
+
}
|
|
76
|
+
return winston.createLogger({
|
|
77
|
+
level: this.config.log_level,
|
|
78
|
+
transports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AC,YAAY,CAAC;YAC1B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAC5B,UAAU;SACX,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { HazoLogger } from './hazo_logger.js';
|
|
2
|
+
export { PackageLogger, createLogger } from './package_logger.js';
|
|
3
|
+
export { loadConfig } from './config_loader.js';
|
|
4
|
+
export { readLogs, getAvailableLogDates, getUniquePackages } from './log-reader.js';
|
|
5
|
+
export type { Logger, LogLevel, LogData, LogEntry, HazoLogConfig, PackageLoggerOptions, } from './types.js';
|
|
6
|
+
export type { ReadLogsOptions, LogQueryResult } from './log-reader.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpF,YAAY,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { HazoLogger } from './hazo_logger.js';
|
|
2
|
+
export { PackageLogger, createLogger } from './package_logger.js';
|
|
3
|
+
export { loadConfig } from './config_loader.js';
|
|
4
|
+
export { readLogs, getAvailableLogDates, getUniquePackages } from './log-reader.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log Reader Service
|
|
3
|
+
* Reads and parses log files with filtering, sorting, and pagination
|
|
4
|
+
*/
|
|
5
|
+
import type { LogEntry, LogLevel } from './types.js';
|
|
6
|
+
export interface ReadLogsOptions {
|
|
7
|
+
logDirectory?: string;
|
|
8
|
+
date?: string;
|
|
9
|
+
level?: LogLevel[];
|
|
10
|
+
package?: string[];
|
|
11
|
+
executionId?: string[];
|
|
12
|
+
sessionId?: string[];
|
|
13
|
+
reference?: string[];
|
|
14
|
+
search?: string;
|
|
15
|
+
sortBy?: 'timestamp' | 'level' | 'package' | 'executionId' | 'sessionId' | 'reference';
|
|
16
|
+
sortOrder?: 'asc' | 'desc';
|
|
17
|
+
page?: number;
|
|
18
|
+
pageSize?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface LogQueryResult {
|
|
21
|
+
logs: LogEntry[];
|
|
22
|
+
total: number;
|
|
23
|
+
page: number;
|
|
24
|
+
pageSize: number;
|
|
25
|
+
totalPages: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Read logs from file with filtering, sorting, and pagination
|
|
29
|
+
*/
|
|
30
|
+
export declare function readLogs(options?: ReadLogsOptions): Promise<LogQueryResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Get list of available log dates
|
|
33
|
+
*/
|
|
34
|
+
export declare function getAvailableLogDates(logDirectory?: string): Promise<string[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Get unique package names from logs
|
|
37
|
+
*/
|
|
38
|
+
export declare function getUniquePackages(logDirectory?: string, date?: string): Promise<string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Get unique execution IDs from logs
|
|
41
|
+
*/
|
|
42
|
+
export declare function getUniqueExecutionIds(logDirectory?: string, date?: string): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Get unique session IDs from logs
|
|
45
|
+
*/
|
|
46
|
+
export declare function getUniqueSessionIds(logDirectory?: string, date?: string): Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Get unique references from logs
|
|
49
|
+
*/
|
|
50
|
+
export declare function getUniqueReferences(logDirectory?: string, date?: string): Promise<string[]>;
|
|
51
|
+
//# sourceMappingURL=log-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-reader.d.ts","sourceRoot":"","sources":["../../src/lib/log-reader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGrD,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,CAAC;IACvF,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,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