Skip to content

Module to provide better Node.js console logging capabilities for MagicMirror²

License

Notifications You must be signed in to change notification settings

shbatm/MMM-Logging

Repository files navigation

MMM-Logging

This is a module for the MagicMirror².

This module extends the Node.js console logging capabilities of the MagicMirror² project through a modern built-in logger implementation, including adding timestamps and stack traces.

By default, this module will intercept and format ALL console log messages from the MagicMirror instance once it is loaded.

Examples

Before MMM-Logging

0|mm  | Starting MagicMirror: v2.6.0-dev
0|mm  | Loading config ...
0|mm  | Loading module helpers ...
0|mm  | Initializing new module helper ...
0|mm  | Module helper loaded: MMM-Logging
0|mm  | No helper found for module: alert.

After MMM-Logging

Example 1

Note: You can find more detailed information on debugging your MagicMirror here: Module Debugging. If you also want the Electron renderer (web browser) console logs to be printed to the standard console (or PM2 logs), change the following line to the very top of ~/MagicMirror/run-start.sh

export ELECTRON_ENABLE_LOGGING=true

Installing the module

To install the module, assuming you have MagicMirror installed with the default configuration:

cd ~/MagicMirror/modules
git clone https://github.com/shbatm/MMM-Logging

Updating the module

cd ~/MagicMirror/modules/MMM-Logging
git pull

Configuration

To use this module, add the following configuration block to the TOP of the modules array in the config/config.js file:

Minimal configuration

        {
            module: 'MMM-Logging',
            config: {
                // Module functions out of the box with nothing set here.
                // See below for configurable options.
            }
        },

Configuration options

The module supports various configuration options to customize the logging format and behavior.

Module specific options

Option Description
useColor Optional Whether or not to use colored console output.
Type: bool Default true.
overwriteConsoleMethods Optional Whether or not to overwrite the default Node.JS console methods. If true any console.log, console.error, etc. function calls in any module will be formatted. If false, only the module's internal logger will be formatted. In most cases for MagicMirror, if you're using this module, you want true
Type: bool Default true.
overwriteBrowserMethods Optional Whether or not to overwrite the default web browser console methods. If true any console.log, console.error, etc. function calls in the DevTools console in any module will be formatted. If false, only the module's internal logger will be formatted.
Type: bool Default false--usually the DevTools console is good enough for tracing errors.
echoModuleNotifications Optional If set any module notifications sent on the front-end will be printed on the Node.JS console log. Can be set to 'notification' to just send the notifications, or 'payload' to include the payloads as well.
Type: string Default 'notification'.
echoErrors Optional If true, any errors in the web browser (front-end) will be printed on the Node.JS console log.
Type: bool Default true.
ignoreModules Optional Option to ignore notifications sent from certain modules. Defaults to ignoring clock, calendar and newsfeed since these send a lot of nuisance notifications.
format Optional Custom format string for log messages. Supports placeholders: {{timestamp}}, {{title}}, {{message}}, {{folder}}, {{file}}, {{line}}, {{method}}.
Type: string Default "{{timestamp}} <{{title}}> {{message}} ({{folder}}/{{file}}:{{line}} {{method}})".

Default configuration

    {
        useColor: true,
        format: "{{timestamp}} <{{title}}> {{message}} ({{folder}}/{{file}}:{{line}} {{method}})",
        overwriteConsoleMethods: true,
        overwriteBrowserMethods: false,
        echoModuleNotifications: "notification",
        echoErrors: true,
        dateformat: "yyyy-mm-dd'T'HH:MM:ss",
        ignoreModules: ["calendar", "newsfeed", "clock"]
    },

Contributing

If you find any problems, bugs or have questions, please open a GitHub issue in this repository.

Pull requests are of course also very welcome 🙂

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Developer commands

  • npm install - Install development dependencies.
  • node --run lint - Run linting and formatter checks.
  • node --run lint:fix - Fix linting and formatter issues.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Module to provide better Node.js console logging capabilities for MagicMirror²

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •