@trifrost/core
Version:
Blazingly fast, runtime-agnostic server framework for modern edge and node environments
60 lines (59 loc) • 1.8 kB
JavaScript
/* eslint-disable no-console */
import { deepFreeze } from '@valkyriestudios/utils/deep';
import { createScrambler, OMIT_PRESETS } from '../../../utils/Scrambler';
export class JsonExporter {
/**
* Scrambler based on omit pattern provided
*/
/**
* Sink for the json entries, if not defined will be console
*/
constructor(options) {
/* Configure scrambler */
this.
checks: Array.isArray(options?.omit) ? deepFreeze([...options.omit]) : OMIT_PRESETS.default,
});
/* Configure sink if passed */
if (typeof options?.sink === 'function')
this.
}
init(global_attrs) {
this.
}
async pushLog(log) {
const entry = this.
message: log.message,
});
/* Add time */
entry.time = log.time.toISOString();
/* Add level */
entry.level = log.level;
/* Add trace id */
if (log.trace_id)
entry.trace_id = log.trace_id;
/* Add span id */
if (log.span_id)
entry.span_id = log.span_id;
/* Add context */
if (log.ctx)
entry.ctx = this.
/* Add data */
if (log.data)
entry.data = this.
/* Add global attributes */
if (this.
entry.global = this.
if (this.
this.
}
else {
console[log.level](JSON.stringify(entry));
}
}
async flush() {
/* No-Op for Json console exporter */
}
}