Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Console Logger

AWS Amplify writes console logs through Logger. You can use Logger in your apps for the same purpose.

Installation

Import Logger:

1import { Logger } from 'aws-amplify';

Working with the API

You can call logger for different console message modes:

1const logger = new Logger('foo');
2
3logger.info('info bar');
4logger.debug('debug bar');
5logger.warn('warn bar');
6logger.error('error bar');

When handling an error:

1try {
2 // ...
3} catch(e) {
4 logger.error('error happened', e);
5}

Setting Logging Levels

You can set a log level when you create your logger instance:

1const logger = new Logger('foo', 'INFO');
2
3logger.debug('callback data', data); // this will not write the message

Global logger configuration will override your logger instance's configuration:

1Amplify.Logger.LOG_LEVEL = 'DEBUG';
2
3const logger = new Logger('foo', 'INFO');
4
5logger.debug('callback data', data); // this will write the message since the global log level is 'DEBUG'

During web development, you can set global log level in browser console log:

1window.LOG_LEVEL = 'DEBUG';

Supported log levels:

  • ERROR
  • WARN
  • INFO
  • DEBUG
  • VERBOSE