Fix logging tiny bug (#14910)
* Fix logging tiny bug * Update changelog.md Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com> * Update changelog.md Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com> * Update changelog.md Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com> * https://github.com/nim-lang/Nim/pull/14910#discussion_r450012032 Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>
This commit is contained in:
parent
af27e6bdea
commit
21b3ca636f
2 changed files with 11 additions and 3 deletions
|
|
@ -124,6 +124,10 @@
|
||||||
- deprecations: `os.existsDir` => `dirExists`, `os.existsFile` => `fileExists`
|
- deprecations: `os.existsDir` => `dirExists`, `os.existsFile` => `fileExists`
|
||||||
|
|
||||||
- Add `jsre` module, [Regular Expressions for the JavaScript target.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
- Add `jsre` module, [Regular Expressions for the JavaScript target.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
||||||
|
- Made `maxLines` argument `Positive` in `logging.newRollingFileLogger`,
|
||||||
|
because negative values will result in a new file being created for each logged line which doesn't make sense.
|
||||||
|
- Changed `log` in `logging` to use proper log level on JavaScript target,
|
||||||
|
eg. `debug` uses `console.debug`, `info` uses `console.info`, `warn` uses `console.warn`, etc.
|
||||||
|
|
||||||
|
|
||||||
## Language changes
|
## Language changes
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,12 @@ method log*(logger: ConsoleLogger, level: Level, args: varargs[string, `$`]) =
|
||||||
let ln = substituteLog(logger.fmtStr, level, args)
|
let ln = substituteLog(logger.fmtStr, level, args)
|
||||||
when defined(js):
|
when defined(js):
|
||||||
let cln: cstring = ln
|
let cln: cstring = ln
|
||||||
{.emit: "console.log(`cln`);".}
|
case level
|
||||||
|
of lvlDebug: {.emit: "console.debug(`cln`);".}
|
||||||
|
of lvlInfo: {.emit: "console.info(`cln`);".}
|
||||||
|
of lvlWarn: {.emit: "console.warn(`cln`);".}
|
||||||
|
of lvlError: {.emit: "console.error(`cln`);".}
|
||||||
|
else: {.emit: "console.log(`cln`);".}
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
var handle = stdout
|
var handle = stdout
|
||||||
|
|
@ -504,7 +509,6 @@ when not defined(js):
|
||||||
# ------
|
# ------
|
||||||
|
|
||||||
proc countLogLines(logger: RollingFileLogger): int =
|
proc countLogLines(logger: RollingFileLogger): int =
|
||||||
result = 0
|
|
||||||
let fp = open(logger.baseName, fmRead)
|
let fp = open(logger.baseName, fmRead)
|
||||||
for line in fp.lines():
|
for line in fp.lines():
|
||||||
result.inc()
|
result.inc()
|
||||||
|
|
@ -531,7 +535,7 @@ when not defined(js):
|
||||||
mode: FileMode = fmReadWrite,
|
mode: FileMode = fmReadWrite,
|
||||||
levelThreshold = lvlAll,
|
levelThreshold = lvlAll,
|
||||||
fmtStr = defaultFmtStr,
|
fmtStr = defaultFmtStr,
|
||||||
maxLines = 1000,
|
maxLines: Positive = 1000,
|
||||||
bufSize: int = -1): RollingFileLogger =
|
bufSize: int = -1): RollingFileLogger =
|
||||||
## Creates a new `RollingFileLogger<#RollingFileLogger>`_.
|
## Creates a new `RollingFileLogger<#RollingFileLogger>`_.
|
||||||
##
|
##
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue