New QueueLogger logging implementation.
This commit is contained in:
parent
0a49618ab3
commit
30c5720ab8
@ -1,13 +1,15 @@
|
|||||||
import nre, terminal, strtabs, tables, unicode
|
import std/[nre, terminal, strtabs, tables, unicode]
|
||||||
import strutils except toUpper, toLower
|
import strutils except toUpper, toLower
|
||||||
|
|
||||||
import ./cliutils/config
|
import ./cliutils/config
|
||||||
import ./cliutils/daemonize
|
import ./cliutils/daemonize
|
||||||
import ./cliutils/procutil
|
import ./cliutils/procutil
|
||||||
|
import ./cliutils/queue_logger
|
||||||
|
|
||||||
export config
|
export config
|
||||||
export daemonize
|
export daemonize
|
||||||
export procutil
|
export procutil
|
||||||
|
export queue_logger
|
||||||
|
|
||||||
type
|
type
|
||||||
TermColor = ForegroundColor or BackgroundColor
|
TermColor = ForegroundColor or BackgroundColor
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.8.2"
|
version = "0.9.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Helper functions for writing command line interfaces."
|
description = "Helper functions for writing command line interfaces."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
25
cliutils/queue_logger.nim
Normal file
25
cliutils/queue_logger.nim
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import std/[logging]
|
||||||
|
|
||||||
|
type
|
||||||
|
QueuedLogMessage* = tuple[lvl: Level, msg: string]
|
||||||
|
|
||||||
|
QueueLogger* = ref object of Logger
|
||||||
|
queue: seq[QueuedLogMessage]
|
||||||
|
|
||||||
|
proc newQueueLogger*(
|
||||||
|
levelThreshold = lvlAll,
|
||||||
|
fmtStr = logging.defaultFmtStr): QueueLogger =
|
||||||
|
|
||||||
|
new result
|
||||||
|
result.fmtStr = fmtStr
|
||||||
|
result.levelThreshold = levelThreshold
|
||||||
|
result.queue = newSeq[QueuedLogMessage]()
|
||||||
|
|
||||||
|
method log*(logger: QueueLogger, level: Level, args: varargs[string, `$`]) =
|
||||||
|
if level >= logger.levelThreshold:
|
||||||
|
logger.queue.add((level, substituteLog(logger.fmtStr, level, args)))
|
||||||
|
|
||||||
|
proc clearQueue*(logger: QueueLogger) =
|
||||||
|
logger.queue = newSeq[QueuedLogMessage]()
|
||||||
|
|
||||||
|
func messages*(logger: QueueLogger): seq[QueuedLogMessage] = logger.queue
|
Loading…
x
Reference in New Issue
Block a user