This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Elm logger with support for log levels and colored console output
version 1.0.1
license BSD 3-Clause
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.1
Committed At 2017-01-22 12:24:18 UTC
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1




This package provides a generic logger with log levels. Logs will only be printed if the log level matches or exceeds the minimum log level in the Configuration.

The package's concept is that some other module in the implementation scope of the app implements convenience functions wrapping a Config and Levels into single functions. See the following template for an example:

module MyUtils

import Logger

loggerConfig : Logger.Config
loggerConfig =
    Logger.defaultConfig Logger.Info

log : String -> a -> a
log =
    Logger.log loggerConfig Logger.Debug

logVerbose : String -> a -> a
logVerbose =
    Logger.log loggerConfig Logger.Verbose

The value loggerConfig should be created using Logger.defaultConfig with the minimum log level. By changing the minimum log level in a central module you can silence any logs in code that fall below that level. The above template implementation allows you to replace calls to Debug.log with MyUtils.log.

Please have a look at the example app.

Advanced: color coded console logs

You can provide a custom ExternalLoggingFunction via customConfig allowing you to replace the default configuration that uses Debug.log for printing the messages.

Screenshot of a console log using elm-logger

The example implementation prints nicely colored code logs to the browser's console.

When using the native example implementation in your project, ensure to update the name of the native function _iosphere$elm_logger$Native_Logger in Logger.js to match the name of your organization and app. If you get a runtime error reading something like ReferenceError: Can't find variable: _org$appname$Native_Logger you will need to update the Logger.js to reference that name.

You will also need to enable native module's for your elm project by including the following value in your elm-package.json:

    "native-modules": true,