@putkoff/abstract-logger 0.0.62 → 0.0.65

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.
@@ -1 +1 @@
1
- export { logEvent as getLogString } from './main/index.js';
1
+ export { logEvent as getLogString, setLogs } from './main/index.js';
@@ -1,3 +1,4 @@
1
1
  export * from './loggerModes.js';
2
2
  export * from './loggerBenchRecorder.js';
3
3
  export * from './loggerBench.js';
4
+ export * from './logger.js';
@@ -0,0 +1,12 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export interface LogOptions {
3
+ scope?: string;
4
+ timestamp?: boolean;
5
+ }
6
+ export declare function log(level: LogLevel, message: string, opts?: LogOptions): void;
7
+ export declare const logger: {
8
+ debug(msg: string, opts?: LogOptions): void;
9
+ info(msg: string, opts?: LogOptions): void;
10
+ warn(msg: string, opts?: LogOptions): void;
11
+ error(msg: string, opts?: LogOptions): void;
12
+ };
package/dist/esm/index.js CHANGED
@@ -15030,6 +15030,38 @@ function recordLatency(ns) {
15030
15030
  stats.latency.counts[i]++;
15031
15031
  }
15032
15032
  /* ---------------------------------- */
15033
+ /* Mode control (LOCKED) */
15034
+ /* ---------------------------------- */
15035
+ function setLogMode(next) {
15036
+ mode = next;
15037
+ }
15038
+ function getLogMode() {
15039
+ return mode;
15040
+ }
15041
+ /* ---------------------------------- */
15042
+ /* Stats */
15043
+ /* ---------------------------------- */
15044
+ function getLogStats() {
15045
+ return {
15046
+ calls: stats.calls,
15047
+ avgNs: stats.calls === 0
15048
+ ? 0
15049
+ : Number(stats.totalNs / BigInt(stats.calls)),
15050
+ byMode: stats.byMode,
15051
+ byType: stats.byType,
15052
+ byFunction: stats.byFunction,
15053
+ latency: stats.latency,
15054
+ };
15055
+ }
15056
+ function resetLogStats() {
15057
+ stats.calls = 0;
15058
+ stats.totalNs = 0n;
15059
+ stats.byMode = {};
15060
+ stats.byType = {};
15061
+ stats.byFunction = {};
15062
+ stats.latency.counts.fill(0);
15063
+ }
15064
+ /* ---------------------------------- */
15033
15065
  /* Unified logging entry point */
15034
15066
  /* ---------------------------------- */
15035
15067
  function logEvent(props) {
@@ -15055,14 +15087,56 @@ function logEvent(props) {
15055
15087
  stats.totalNs += elapsed;
15056
15088
  recordLatency(elapsed);
15057
15089
  }
15090
+ function setLogs(mode = null, interval = false, window_ms = null) {
15091
+ const modes = [
15092
+ LogMode.FULL,
15093
+ LogMode.CONSOLE,
15094
+ LogMode.COUNT,
15095
+ LogMode.OFF,
15096
+ ];
15097
+ if (window_ms != false) {
15098
+ if (window_ms === true || window_ms == null) {
15099
+ window_ms = 30000;
15100
+ }
15101
+ }
15102
+ if (interval != true) {
15103
+ mode = mode || 3;
15104
+ setLogMode(modes[mode]);
15105
+ resetLogStats();
15106
+ }
15107
+ else {
15108
+ let i = 0;
15109
+ setInterval(() => {
15110
+ window_ms || (window_ms = 30000);
15111
+ recordBenchSnapshot(window_ms);
15112
+ resetLogStats();
15113
+ setLogMode(modes[++i % modes.length]);
15114
+ }, window_ms);
15115
+ }
15116
+ }
15058
15117
 
15059
15118
  const LOG_DIR = process.env.LOG_BENCH_DIR ??
15060
15119
  path.resolve(process.cwd(), "log-bench");
15061
- path.join(LOG_DIR, "bench.ndjson");
15120
+ const FILE = path.join(LOG_DIR, "bench.ndjson");
15062
15121
  fs.mkdirSync(LOG_DIR, { recursive: true });
15122
+ function recordBenchSnapshot(windowMs) {
15123
+ const stats = getLogStats();
15124
+ const record = {
15125
+ ts: new Date().toISOString(),
15126
+ windowMs,
15127
+ mode: getLogMode(),
15128
+ calls: stats.calls,
15129
+ avgNs: stats.avgNs,
15130
+ byMode: stats.byMode,
15131
+ byType: stats.byType,
15132
+ byFunction: stats.byFunction,
15133
+ latency: stats.latency,
15134
+ };
15135
+ fs.appendFileSync(FILE, JSON.stringify(record) + "\n");
15136
+ }
15063
15137
 
15064
15138
  var createLogger$2 = winston.createLogger;
15065
15139
  var format$3 = winston.format;
15066
15140
  var transports$1 = winston.transports;
15067
- export { COLS, IS_BROWSER, IS_NODE, activityEmojiMap, createLogger$2 as createLogger, debugLogConfig, extractFile, format$3 as format, formatLogLine, getCallerInfo, getFinalLine, getLogConfig, logEvent as getLogString, getNodeLogger, logger, padLeft, padRight, parseList, resolveLogger, resolveValue, serializeDetails, shouldCondense, shouldShowDetails, transports$1 as transports };
15141
+ export { COLS, IS_BROWSER, IS_NODE, activityEmojiMap, createLogger$2 as createLogger, debugLogConfig, extractFile, format$3 as format, formatLogLine, getCallerInfo, getFinalLine, getLogConfig, logEvent as getLogString, getNodeLogger, logger, padLeft, padRight, parseList, resolveLogger, resolveValue, serializeDetails, setLogs, shouldCondense, shouldShowDetails, transports$1 as transports };
15068
15142
  //# sourceMappingURL=index.js.map