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:
Juan Carlos
2020-07-06 05:00:25 -03:00
committed by GitHub
parent af27e6bdea
commit 21b3ca636f
2 changed files with 11 additions and 3 deletions

View File

@@ -124,6 +124,10 @@
- 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)
- 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

View File

@@ -364,7 +364,12 @@ method log*(logger: ConsoleLogger, level: Level, args: varargs[string, `$`]) =
let ln = substituteLog(logger.fmtStr, level, args)
when defined(js):
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:
try:
var handle = stdout
@@ -504,7 +509,6 @@ when not defined(js):
# ------
proc countLogLines(logger: RollingFileLogger): int =
result = 0
let fp = open(logger.baseName, fmRead)
for line in fp.lines():
result.inc()
@@ -531,7 +535,7 @@ when not defined(js):
mode: FileMode = fmReadWrite,
levelThreshold = lvlAll,
fmtStr = defaultFmtStr,
maxLines = 1000,
maxLines: Positive = 1000,
bufSize: int = -1): RollingFileLogger =
## Creates a new `RollingFileLogger<#RollingFileLogger>`_.
##