@typeberry/lib 0.4.1-ac232ea → 0.4.1-b66435f

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/index.cjs CHANGED
@@ -8148,13 +8148,13 @@ class Logger {
8148
8148
  *
8149
8149
  * Changing the options affects all previously created loggers.
8150
8150
  */
8151
- static configureAllFromOptions(options) {
8151
+ static configureAllFromOptions(options, createTransport = ConsoleTransport.create) {
8152
8152
  // find minimal level to optimise logging in case
8153
8153
  // we don't care about low-level logs.
8154
8154
  const minimalLevel = Array.from(options.modules.values()).reduce((level, modLevel) => {
8155
8155
  return level < modLevel ? level : modLevel;
8156
8156
  }, options.defaultLevel);
8157
- const transport = ConsoleTransport.create(minimalLevel, options);
8157
+ const transport = createTransport(minimalLevel, options);
8158
8158
  // set the global config
8159
8159
  GLOBAL_CONFIG.options = options;
8160
8160
  GLOBAL_CONFIG.transport = transport;
@@ -8180,8 +8180,11 @@ class Logger {
8180
8180
  }
8181
8181
  getLevelAndName() {
8182
8182
  if (this.cachedLevelAndName === undefined) {
8183
- const level = findLevel(this.config.options, this.moduleName);
8184
- const shortName = this.moduleName.replace(this.config.options.workingDir, "");
8183
+ // since we pad module name for better alignment, we need to
8184
+ // trim it for the lookup
8185
+ const moduleTrimmed = this.moduleName.trim();
8186
+ const level = findLevel(this.config.options, moduleTrimmed);
8187
+ const shortName = moduleTrimmed.replace(this.config.options.workingDir, "");
8185
8188
  this.cachedLevelAndName = [level, shortName];
8186
8189
  }
8187
8190
  return this.cachedLevelAndName;
@@ -8214,8 +8217,10 @@ class Logger {
8214
8217
 
8215
8218
  var index$m = /*#__PURE__*/Object.freeze({
8216
8219
  __proto__: null,
8220
+ ConsoleTransport: ConsoleTransport,
8217
8221
  get Level () { return Level; },
8218
8222
  Logger: Logger,
8223
+ findLevel: findLevel,
8219
8224
  parseLoggerOptions: parseLoggerOptions
8220
8225
  });
8221
8226
 
package/index.d.ts CHANGED
@@ -7299,6 +7299,20 @@ type Options = {
7299
7299
  workingDir: string;
7300
7300
  modules: Map<string, Level>;
7301
7301
  };
7302
+ /**
7303
+ * Find a configured log level for given module.
7304
+ *
7305
+ * The function will attempt to find the most detailed level for given module
7306
+ * by checking if logging is configured for it's parent modules if it's not for
7307
+ * the specific name.
7308
+ *
7309
+ * E.g. `consensus/voting`
7310
+ *
7311
+ * We can have no level configured for `consensus/voting`, but if there is a `WARN`
7312
+ * level for `consensus`, this function would return `Level.WARN` even though
7313
+ * the default log level might be `Level.LOG`.
7314
+ */
7315
+ declare function findLevel(options: Options, moduleName: string): Level;
7302
7316
  /**
7303
7317
  * A function to parse logger definition (including modules) given as a string.
7304
7318
  *
@@ -7309,6 +7323,45 @@ type Options = {
7309
7323
  */
7310
7324
  declare function parseLoggerOptions(input: string, defaultLevel: Level, workingDir?: string): Options;
7311
7325
 
7326
+ type TransportBuilder = (minLevel: Level, options: Options) => Transport;
7327
+ /**
7328
+ * An interface for the logger `Transport`.
7329
+ */
7330
+ interface Transport {
7331
+ /** INSANE message */
7332
+ insane(levelAndName: readonly [Level, string], _strings: TemplateStringsArray, _data: unknown[]): void;
7333
+ /** TRACE message */
7334
+ trace(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7335
+ /** DEBUG/LOG message */
7336
+ log(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7337
+ /** INFO message */
7338
+ info(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7339
+ /** WARN message */
7340
+ warn(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7341
+ /** ERROR message */
7342
+ error(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7343
+ }
7344
+
7345
+ /** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
7346
+ *
7347
+ * Use the `create` method to instantiate the right instance of a more specialized logger.
7348
+ */
7349
+ declare class ConsoleTransport implements Transport {
7350
+ protected options: Options;
7351
+ /**
7352
+ * Creates a new optimized logger which ignores messages that are below the
7353
+ * `minimalLevel`.
7354
+ */
7355
+ static create(minimalLevel: Level, options: Options): ConsoleTransport;
7356
+ protected constructor(options: Options);
7357
+ insane(_levelAndName: readonly [Level, string], _strings: TemplateStringsArray, _data: unknown[]): void;
7358
+ trace(_levelAndName: readonly [Level, string], _strings: TemplateStringsArray, _data: unknown[]): void;
7359
+ log(_levelAndName: readonly [Level, string], _strings: TemplateStringsArray, _data: unknown[]): void;
7360
+ info(_levelAndName: readonly [Level, string], _strings: TemplateStringsArray, _data: unknown[]): void;
7361
+ warn(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7362
+ error(levelAndName: readonly [Level, string], strings: TemplateStringsArray, data: unknown[]): void;
7363
+ }
7364
+
7312
7365
  /**
7313
7366
  * A logger instance.
7314
7367
  */
@@ -7334,7 +7387,7 @@ declare class Logger {
7334
7387
  *
7335
7388
  * Changing the options affects all previously created loggers.
7336
7389
  */
7337
- static configureAllFromOptions(options: Options): void;
7390
+ static configureAllFromOptions(options: Options, createTransport?: TransportBuilder): void;
7338
7391
  /**
7339
7392
  * Global configuration of all loggers.
7340
7393
  *
@@ -7361,17 +7414,20 @@ declare class Logger {
7361
7414
  error(strings: TemplateStringsArray, ...data: unknown[]): void;
7362
7415
  }
7363
7416
 
7417
+ type index$c_ConsoleTransport = ConsoleTransport;
7418
+ declare const index$c_ConsoleTransport: typeof ConsoleTransport;
7364
7419
  type index$c_Level = Level;
7365
7420
  declare const index$c_Level: typeof Level;
7366
7421
  type index$c_Logger = Logger;
7367
7422
  declare const index$c_Logger: typeof Logger;
7423
+ type index$c_Options = Options;
7424
+ type index$c_Transport = Transport;
7425
+ type index$c_TransportBuilder = TransportBuilder;
7426
+ declare const index$c_findLevel: typeof findLevel;
7368
7427
  declare const index$c_parseLoggerOptions: typeof parseLoggerOptions;
7369
7428
  declare namespace index$c {
7370
- export {
7371
- index$c_Level as Level,
7372
- index$c_Logger as Logger,
7373
- index$c_parseLoggerOptions as parseLoggerOptions,
7374
- };
7429
+ export { index$c_ConsoleTransport as ConsoleTransport, index$c_Level as Level, index$c_Logger as Logger, index$c_findLevel as findLevel, index$c_parseLoggerOptions as parseLoggerOptions };
7430
+ export type { index$c_Options as Options, index$c_Transport as Transport, index$c_TransportBuilder as TransportBuilder };
7375
7431
  }
7376
7432
 
7377
7433
  /** Size of the transfer memo. */
package/index.js CHANGED
@@ -8145,13 +8145,13 @@ class Logger {
8145
8145
  *
8146
8146
  * Changing the options affects all previously created loggers.
8147
8147
  */
8148
- static configureAllFromOptions(options) {
8148
+ static configureAllFromOptions(options, createTransport = ConsoleTransport.create) {
8149
8149
  // find minimal level to optimise logging in case
8150
8150
  // we don't care about low-level logs.
8151
8151
  const minimalLevel = Array.from(options.modules.values()).reduce((level, modLevel) => {
8152
8152
  return level < modLevel ? level : modLevel;
8153
8153
  }, options.defaultLevel);
8154
- const transport = ConsoleTransport.create(minimalLevel, options);
8154
+ const transport = createTransport(minimalLevel, options);
8155
8155
  // set the global config
8156
8156
  GLOBAL_CONFIG.options = options;
8157
8157
  GLOBAL_CONFIG.transport = transport;
@@ -8177,8 +8177,11 @@ class Logger {
8177
8177
  }
8178
8178
  getLevelAndName() {
8179
8179
  if (this.cachedLevelAndName === undefined) {
8180
- const level = findLevel(this.config.options, this.moduleName);
8181
- const shortName = this.moduleName.replace(this.config.options.workingDir, "");
8180
+ // since we pad module name for better alignment, we need to
8181
+ // trim it for the lookup
8182
+ const moduleTrimmed = this.moduleName.trim();
8183
+ const level = findLevel(this.config.options, moduleTrimmed);
8184
+ const shortName = moduleTrimmed.replace(this.config.options.workingDir, "");
8182
8185
  this.cachedLevelAndName = [level, shortName];
8183
8186
  }
8184
8187
  return this.cachedLevelAndName;
@@ -8211,8 +8214,10 @@ class Logger {
8211
8214
 
8212
8215
  var index$m = /*#__PURE__*/Object.freeze({
8213
8216
  __proto__: null,
8217
+ ConsoleTransport: ConsoleTransport,
8214
8218
  get Level () { return Level; },
8215
8219
  Logger: Logger,
8220
+ findLevel: findLevel,
8216
8221
  parseLoggerOptions: parseLoggerOptions
8217
8222
  });
8218
8223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.4.1-ac232ea",
3
+ "version": "0.4.1-b66435f",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",