UNPKG

@freemework/common

Version:

Common library of the Freemework Project.

57 lines 2.04 kB
/** * Base class to define a logger label * * @example * export class MyLoggerLabel extends FLoggerLabel { * public static readonly APP_VERSION = new MyLoggerLabel("app.version", "Describes a version of the current application"); * public static readonly APP_NAME = new MyLoggerLabel("app.name", "Describes a name of the current application"); * public static readonly INPUT_HTTP_METHOD = new MyLoggerLabel("in.http.method", "Describes HTTP method of input request (like a GET, POST, etc.)"); * public static readonly INPUT_HTTP_PATH = new MyLoggerLabel("in.http.path", "Describes HTTP URL path of input request (like a /api/v1/user)"); * public static readonly INPUT_HTTP_STATUS = new MyLoggerLabel("in.http.status", "Describes HTTP status of input request (like 200, 400, etc.)"); * // ... * } * * for(const {name, description} of FLoggerLabel.all) { * console.log(`${name}: ${description}`); * // == stdout == * // app.version: Describes a version of the current application * // app.name: Describes a name of the current application * // ... * } * * executionContext = new FLoggerLabelsExecutionContext(executionContext, * MyLoggerLabel.APP_VERSION.value("1.0.42"), * ) * * logger.info(executionContext, "Some log message"); * // == logger output == * // ... INFO (app.version:1.0.42) Some log message */ export class FLoggerLabel extends Object { name; description; static _all = new Set(); static get all() { return FLoggerLabel._all; } value(labelValue) { return new FLoggerLabelValue(this, labelValue); } toString() { return this.name; } constructor(name, description) { super(); this.name = name; this.description = description; FLoggerLabel._all.add(this); } } export class FLoggerLabelValue { label; value; constructor(label, value) { this.label = label; this.value = value; } get name() { return this.label.name; } } //# sourceMappingURL=f_logger_labels.js.map