Skip to main content

Logger

The Jutro logger provides methods for logging to the browser console with all the typical log levels. The logging mechanism uses loglevel and loglevel-plugin-prefix libraries underneath.

Basic use

  1. Set the logging level for lower environments in .env

    REACT_APP_JUTRO_LOGGER_LEVEL=WARN
  2. Set the logging level for the production environment in .env.production

    REACT_APP_JUTRO_LOGGER_LEVEL=ERROR
  3. Use the logger in your code:

    import { debug } from '@jutro/logger';

    . . .

    debug('So, you have reached my debug logger. Well done!');

Logging levels

The logger comes with the following levels:

  • TRACE (adds a stack trace to the message)
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • SILENT (disables all logging)

You can set levels using strings as above (case-insensitive), or as a numeric index from 0 (Trace) to 5 (Silent)

For more information about logging levels, see loglevel on npmjs.com

All levels except silent have a corresponding function which you can import from @jutro/logger and call in your code.

import { trace, debug, info, warning, error } from '@jutro/logger';

. . .

trace('Tracing now!');
debug('Debugging...');
info('Stay informed with Jutro logging!');
warning("Look, I'm warning you");
error('I am error');

Alternatively, you can import log and call its methods:

import {log} from '@jutro/logger';

...

log.trace('trace message');
log.debug('debug message');
log.info('info message');
log.warning('warn message');
log.error('error message');