logsdx
Version:
log streaming with dx on the ðŸ§
243 lines (204 loc) • 7.87 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkQBEC4U26cjs = require('./chunk-QBEC4U26.cjs');
var _chunkBNOJIPVJcjs = require('./chunk-BNOJIPVJ.cjs');
var _chunkMA4X2JPVcjs = require('./chunk-MA4X2JPV.cjs');
var _chunkNS2VVDW7cjs = require('./chunk-NS2VVDW7.cjs');
require('./chunk-Q46SBW3R.cjs');
require('./chunk-Q7SFCCGT.cjs');
// src/parsers/regex/rules.ts
var logParserRules = [
// Language markers
{
match: /^\[json\]/i,
extract: () => ({ lang: "json" })
},
{
match: /^\[sql\]/i,
extract: () => ({ lang: "sql" })
},
{
match: /^\[lang:(\w+)\]/i,
extract: (_line, match) => ({ lang: _optionalChain([match, 'access', _ => _[1], 'optionalAccess', _2 => _2.toLowerCase, 'call', _3 => _3()]) })
},
// Log levels with various formats
{
match: /\[(ERROR|ERR|FATAL|CRITICAL)\]/i,
extract: () => ({ level: "error" })
},
{
match: /\[(WARN|WARNING|ATTENTION)\]/i,
extract: () => ({ level: "warn" })
},
{
match: /\[(INFO|INFORMATION)\]/i,
extract: () => ({ level: "info" })
},
{
match: /\[(DEBUG|TRACE|VERBOSE)\]/i,
extract: () => ({ level: "debug" })
},
{
match: /\[(SUCCESS|SUCCEEDED|COMPLETED)\]/i,
extract: () => ({ level: "success" })
},
// Common log formats
{
match: /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s+\[(\w+)\]\s+(.*)$/,
extract: (_line, match) => ({
timestamp: match[1],
level: _optionalChain([match, 'access', _4 => _4[2], 'optionalAccess', _5 => _5.toLowerCase, 'call', _6 => _6()]),
message: match[3]
})
},
{
match: /^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s+\[(\w+)\]\s+(.*)$/,
extract: (_line, match) => ({
timestamp: match[1],
level: _optionalChain([match, 'access', _7 => _7[2], 'optionalAccess', _8 => _8.toLowerCase, 'call', _9 => _9()]),
message: match[3]
})
},
{
match: /^\[(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\]\s+\[(\w+)\]\s+(.*)$/,
extract: (_line, match) => ({
timestamp: match[1],
level: _optionalChain([match, 'access', _10 => _10[2], 'optionalAccess', _11 => _11.toLowerCase, 'call', _12 => _12()]),
message: match[3]
})
},
// Simple level detection (fallback)
{
match: /\b(ERROR|ERR|FATAL|CRITICAL)\b/i,
extract: () => ({ level: "error" })
},
{
match: /\b(WARN|WARNING|ATTENTION)\b/i,
extract: () => ({ level: "warn" })
},
{
match: /\b(INFO|INFORMATION)\b/i,
extract: () => ({ level: "info" })
},
{
match: /\b(DEBUG|TRACE|VERBOSE)\b/i,
extract: () => ({ level: "debug" })
},
{
match: /\b(SUCCESS|SUCCEEDED|COMPLETED)\b/i,
extract: () => ({ level: "success" })
}
];
// src/parsers/regex/index.ts
var regexBasedParser = _chunkQBEC4U26cjs.createRegexLineParser.call(void 0, logParserRules);
// src/parsers/custom.ts
function createCustomParser(options) {
if (options.validate && !options.validate()) {
throw new Error(`Invalid configuration for parser '${options.name}'`);
}
const parser = (line) => {
if (options.canParse && !options.canParse(line)) {
return void 0;
}
return options.parse(line);
};
parser.name = options.name;
parser.description = options.description || `Custom parser: ${options.name}`;
return parser;
}
function createParserFactory(options) {
return async () => {
return createCustomParser(options);
};
}
function mapLogLevel(level) {
const levelMap = {
// Standard levels
debug: "debug",
info: "info",
warn: "warn",
warning: "warn",
error: "error",
err: "error",
success: "success",
trace: "trace",
// Common variations
fatal: "error",
critical: "error",
notice: "info",
verbose: "debug",
silly: "debug",
// Status-based levels
fail: "error",
failed: "error",
failure: "error",
pending: "warn",
in_progress: "info",
completed: "success"
};
const normalizedLevel = level.toLowerCase().trim();
return levelMap[normalizedLevel] || "info";
}
function createCsvLogParser() {
return createParserFactory({
name: "csv-logs",
description: "Parser for CSV-formatted logs",
canParse: (line) => line.startsWith("CSV_LOG:"),
parse: (line) => {
const csvContent = line.substring(8);
const parts = csvContent.split(",");
if (parts.length < 3) {
return void 0;
}
const timestamp = _optionalChain([parts, 'access', _13 => _13[0], 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()]) || "";
const level = mapLogLevel(_optionalChain([parts, 'access', _16 => _16[1], 'optionalAccess', _17 => _17.trim, 'call', _18 => _18()]) || "");
const message = _optionalChain([parts, 'access', _19 => _19[2], 'optionalAccess', _20 => _20.trim, 'call', _21 => _21()]) || "";
const result = {
timestamp,
level,
message,
format: "csv"
};
for (let i = 3; i < parts.length; i++) {
const part = parts[i];
if (part) {
const [key, value] = part.split("=");
if (key && value) {
result[key.trim()] = value.trim();
}
}
}
return result;
}
});
}
function createAppLogParser() {
return createParserFactory({
name: "app-logs",
description: "Parser for application-specific logs",
canParse: (line) => line.startsWith("[APP]"),
parse: (line) => {
const appLogRegex = /^\[APP\]\s+(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s+\[(\w+)\]\s+(.*)$/;
const appLogMatch = line.match(appLogRegex);
if (appLogMatch && appLogMatch[1] && appLogMatch[2] && appLogMatch[3]) {
return {
timestamp: appLogMatch[1],
level: mapLogLevel(appLogMatch[2]),
message: appLogMatch[3],
service: "app"
};
}
const errorRegex = /^\[APP\]\s+ERROR\s+(.*?):\s+(.*)$/;
const errorMatch = line.match(errorRegex);
if (errorMatch && errorMatch[1] && errorMatch[2]) {
return {
level: "error",
message: `${errorMatch[1]}: ${errorMatch[2]}`,
service: "app"
};
}
return void 0;
}
});
}
exports.DEFAULT_JSON_RULES_DEFAULT = _chunkQBEC4U26cjs.DEFAULT_JSON_RULES; exports.LogEnhancer = _chunkBNOJIPVJcjs.LogEnhancer; exports.asci = _chunkNS2VVDW7cjs.asci_exports; exports.createAppLogParser = createAppLogParser; exports.createCsvLogParser = createCsvLogParser; exports.createCustomParser = createCustomParser; exports.createParserFactory = createParserFactory; exports.createRegexLineParser = _chunkQBEC4U26cjs.createRegexLineParser; exports.defaultLineParser = _chunkQBEC4U26cjs.defaultLineParser; exports.getParser = _chunkQBEC4U26cjs.getParser; exports.getParserForOptions = _chunkQBEC4U26cjs.getParserForOptions; exports.getRegisteredParsers = _chunkQBEC4U26cjs.getRegisteredParsers; exports.loadJsonRules = _chunkQBEC4U26cjs.loadJsonRules; exports.logParserRules = logParserRules; exports.logger = _chunkMA4X2JPVcjs.logger; exports.mapLogLevel = mapLogLevel; exports.program = _chunkQBEC4U26cjs.program; exports.registerParser = _chunkQBEC4U26cjs.registerParser; exports.shouldRender = _chunkQBEC4U26cjs.shouldRender;
//# sourceMappingURL=index.cjs.map