|
|
|
import debugLogger from 'debug-logger'
|
|
|
|
|
|
|
|
// Enable colours for object inspection.
|
|
|
|
debugLogger.inspectOptions = {
|
|
|
|
colors: true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable all zap logs if DEBUG has not been explicitly set.
|
|
|
|
if (!process.env.DEBUG) {
|
|
|
|
// debugLogger.debug.enable('zap:*')
|
|
|
|
process.env.DEBUG = 'zap:*'
|
|
|
|
}
|
|
|
|
if (!process.env.DEBUG_LEVEL) {
|
|
|
|
process.env.DEBUG_LEVEL = 'info'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method to configure a logger instance with a specific namespace suffix.
|
|
|
|
const logConfig = name => ({
|
|
|
|
levels: {
|
|
|
|
trace: {
|
|
|
|
prefix: '[TRC] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
debug: {
|
|
|
|
prefix: '[DBG] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
log: {
|
|
|
|
prefix: '[LOG] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
info: {
|
|
|
|
prefix: '[INF] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
warn: {
|
|
|
|
prefix: '[WRN] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
prefix: '[ERR] ',
|
|
|
|
namespaceSuffix: `:${name}`
|
|
|
|
},
|
|
|
|
critical: {
|
|
|
|
color: debugLogger.colors.magenta,
|
|
|
|
prefix: '[CRT] ',
|
|
|
|
namespaceSuffix: `:${name}`,
|
|
|
|
level: 6,
|
|
|
|
fd: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create 2 logs for use in the app.
|
|
|
|
export const mainLog = debugLogger.config(logConfig('main'))('zap')
|
|
|
|
export const lndLog = debugLogger.config(logConfig('lnd '))('zap')
|
|
|
|
|
fix(lnd log level): Fix lndLogGetLevel to apply the most-recent log level when none is detected
In some cases, multi-line log output was output at its value for the first line,
but in the trace log in following lines. For example, in this output:
zap:lnd [DBG] 2018-06-17 18:30:35.051 [DBG] CRTR: New channel update applied: (*channeldb.ChannelEdgePolicy)(0xc420e74310)({ +0ms
zap:lnd [DBG] SigBytes: ([]uint8) (len=71 cap=71) { +0ms
zap:lnd [DBG] }, +0ms
zap:lnd [DBG] sig: (*btcec.Signature)(<nil>), +0ms
zap:lnd [DBG] ChannelID: (uint64) 1423834572626526208, +0ms
zap:lnd [DBG] LastUpdate: (time.Time) 2018-06-17 18:30:26 -0500 CDT, +0ms
zap:lnd [DBG] Flags: (lnwire.ChanUpdateFlag) 1, +0ms
zap:lnd [DBG] TimeLockDelta: (uint16) 6, +0ms
zap:lnd [DBG] MinHTLC: (lnwire.MilliSatoshi) 1000 mSAT, +0ms
zap:lnd [DBG] FeeBaseMSat: (lnwire.MilliSatoshi) 1 mSAT, +0ms
zap:lnd [DBG] FeeProportionalMillionths: (lnwire.MilliSatoshi) 10 mSAT, +0ms
zap:lnd [DBG] Node: (*channeldb.LightningNode)(<nil>), +0ms
zap:lnd [DBG] db: (*channeldb.DB)(<nil>) +1ms
zap:lnd [DBG] }) +0ms
zap:lnd [DBG] +0ms
Previously the first line would be marked DBG, while the others were marked TRC.
7 years ago
|
|
|
let lndLogLevel = null // stored most recent log level for continuity
|
|
|
|
export const lndLogGetLevel = msg => {
|
|
|
|
// Define a mapping between log level prefixes and log level names.
|
|
|
|
const levelMap = {
|
|
|
|
TRC: 'trace',
|
|
|
|
DBG: 'debug',
|
|
|
|
INF: 'info',
|
|
|
|
WRN: 'warn',
|
|
|
|
ERR: 'error',
|
|
|
|
CRT: 'critical'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the log line to determine its level.
|
fix(lnd log level): Fix lndLogGetLevel to apply the most-recent log level when none is detected
In some cases, multi-line log output was output at its value for the first line,
but in the trace log in following lines. For example, in this output:
zap:lnd [DBG] 2018-06-17 18:30:35.051 [DBG] CRTR: New channel update applied: (*channeldb.ChannelEdgePolicy)(0xc420e74310)({ +0ms
zap:lnd [DBG] SigBytes: ([]uint8) (len=71 cap=71) { +0ms
zap:lnd [DBG] }, +0ms
zap:lnd [DBG] sig: (*btcec.Signature)(<nil>), +0ms
zap:lnd [DBG] ChannelID: (uint64) 1423834572626526208, +0ms
zap:lnd [DBG] LastUpdate: (time.Time) 2018-06-17 18:30:26 -0500 CDT, +0ms
zap:lnd [DBG] Flags: (lnwire.ChanUpdateFlag) 1, +0ms
zap:lnd [DBG] TimeLockDelta: (uint16) 6, +0ms
zap:lnd [DBG] MinHTLC: (lnwire.MilliSatoshi) 1000 mSAT, +0ms
zap:lnd [DBG] FeeBaseMSat: (lnwire.MilliSatoshi) 1 mSAT, +0ms
zap:lnd [DBG] FeeProportionalMillionths: (lnwire.MilliSatoshi) 10 mSAT, +0ms
zap:lnd [DBG] Node: (*channeldb.LightningNode)(<nil>), +0ms
zap:lnd [DBG] db: (*channeldb.DB)(<nil>) +1ms
zap:lnd [DBG] }) +0ms
zap:lnd [DBG] +0ms
Previously the first line would be marked DBG, while the others were marked TRC.
7 years ago
|
|
|
let level
|
|
|
|
Object.entries(levelMap).forEach(([key, value]) => {
|
|
|
|
if (msg.includes(`[${key}]`)) {
|
|
|
|
level = value
|
|
|
|
}
|
|
|
|
})
|
fix(lnd log level): Fix lndLogGetLevel to apply the most-recent log level when none is detected
In some cases, multi-line log output was output at its value for the first line,
but in the trace log in following lines. For example, in this output:
zap:lnd [DBG] 2018-06-17 18:30:35.051 [DBG] CRTR: New channel update applied: (*channeldb.ChannelEdgePolicy)(0xc420e74310)({ +0ms
zap:lnd [DBG] SigBytes: ([]uint8) (len=71 cap=71) { +0ms
zap:lnd [DBG] }, +0ms
zap:lnd [DBG] sig: (*btcec.Signature)(<nil>), +0ms
zap:lnd [DBG] ChannelID: (uint64) 1423834572626526208, +0ms
zap:lnd [DBG] LastUpdate: (time.Time) 2018-06-17 18:30:26 -0500 CDT, +0ms
zap:lnd [DBG] Flags: (lnwire.ChanUpdateFlag) 1, +0ms
zap:lnd [DBG] TimeLockDelta: (uint16) 6, +0ms
zap:lnd [DBG] MinHTLC: (lnwire.MilliSatoshi) 1000 mSAT, +0ms
zap:lnd [DBG] FeeBaseMSat: (lnwire.MilliSatoshi) 1 mSAT, +0ms
zap:lnd [DBG] FeeProportionalMillionths: (lnwire.MilliSatoshi) 10 mSAT, +0ms
zap:lnd [DBG] Node: (*channeldb.LightningNode)(<nil>), +0ms
zap:lnd [DBG] db: (*channeldb.DB)(<nil>) +1ms
zap:lnd [DBG] }) +0ms
zap:lnd [DBG] +0ms
Previously the first line would be marked DBG, while the others were marked TRC.
7 years ago
|
|
|
if (level) {
|
|
|
|
lndLogLevel = level
|
|
|
|
return level
|
|
|
|
}
|
|
|
|
// We set the default level to trace.
|
|
|
|
// The only log lines that don't include a level prefix are a part of trace entries
|
|
|
|
return lndLogLevel || 'trace'
|
|
|
|
}
|