Compare commits

...

1 Commits

Author SHA1 Message Date
Julien Fontanet
175c689933 WiP: feat(log): new extremely versbose level trace 2024-11-22 17:23:28 +01:00
6 changed files with 8 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import { createLogger } from '@xen-orchestra/log'
const log = createLogger('my-module')
log.trace('extremely verbose log')
log.debug('only useful for debugging')
log.info('this information is relevant to the user')
log.warn('something went wrong but did not prevent current action')

View File

@@ -25,6 +25,7 @@ import { createLogger } from '@xen-orchestra/log'
const log = createLogger('my-module')
log.trace('extremely verbose log')
log.debug('only useful for debugging')
log.info('this information is relevant to the user')
log.warn('something went wrong but did not prevent current action')

View File

@@ -1,6 +1,6 @@
'use strict'
const { resolve } = require('./levels.js')
const { LEVELS, resolve } = require('./levels.js')
const compileGlobPattern = require('./_compileGlobPattern.js')
function compileFilter(filter) {
@@ -14,7 +14,7 @@ function compileFilter(filter) {
}
if (type === 'string') {
const re = compileGlobPattern(filter)
return log => re.test(log.namespace)
return log => log.level >= LEVELS.DEBUG && re.test(log.namespace)
}
if (Array.isArray(filter)) {

View File

@@ -19,7 +19,7 @@ if (!(symbol in global)) {
const level = resolve(env.LOG_LEVEL, LEVELS.WARN)
global[symbol] = function conditionalTransport(log) {
if (log.level >= level || matchDebug(log.namespace)) {
if (log.level >= level || (log.level >= LEVELS.DEBUG && matchDebug(log.namespace))) {
transport(log)
}
}

View File

@@ -9,6 +9,7 @@ LEVELS.ERROR = 50 // fatal for current action
LEVELS.WARN = 40 // something went wrong but it's not fatal
LEVELS.INFO = 30 // detail on unusual but normal operation
LEVELS.DEBUG = 20
LEVELS.TRACE = 10 // extremely verbose logs
const NAMES = Object.create(null)
exports.NAMES = NAMES

View File

@@ -2,7 +2,7 @@
const { LEVELS, NAMES } = require('../levels')
const { DEBUG, ERROR, FATAL, INFO, WARN } = LEVELS
const { DEBUG, ERROR, FATAL, INFO, TRACE, WARN } = LEVELS
let formatLevel, formatNamespace
if (process.stdout !== undefined && process.stdout.isTTY && process.stderr !== undefined && process.stderr.isTTY) {
@@ -13,6 +13,7 @@ if (process.stdout !== undefined && process.stdout.isTTY && process.stderr !== u
[ERROR]: '1;31',
[FATAL]: '1;31',
[INFO]: '1',
[TRACE]: '2',
[WARN]: '1;33',
}
formatLevel = level => {