summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelog.md4
-rw-r--r--lib/pure/logging.nim10
2 files changed, 11 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index abe69a086..efad01515 100644
--- a/changelog.md
+++ b/changelog.md
@@ -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
diff --git a/lib/pure/logging.nim b/lib/pure/logging.nim
index 2637fdf9d..2e79cd3ca 100644
--- a/lib/pure/logging.nim
+++ b/lib/pure/logging.nim
@@ -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>`_.
     ##