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

Page updated Apr 30, 2024

Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. New project should use Amplify Gen 2. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade. Switch to the latest Gen 2 docs →

コンソールロガー

AWS Amplify はコンソールロガーを通じてコンソールログを書き込みます。アプリケーションで同じ目的のためにコンソールロガーを使用できます。

インストール

Logger をインポートします:

import { ConsoleLogger } from 'aws-amplify/utils';

API を使用する

異なるコンソールメッセージモード用にロガーを呼び出すことができます:

const logger = new ConsoleLogger('foo');
logger.info('info bar');
logger.debug('debug bar');
logger.warn('warn bar');
logger.error('error bar');

エラーを処理する場合:

try {
// ...
} catch(e) {
logger.error('error happened', e);
}

ロギングレベルの設定

ロガーインスタンスを作成するときにログレベルを設定できます:

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

グローバルロガー構成はロガーインスタンスの構成を上書きします:

ConsoleLogger.LOG_LEVEL = 'DEBUG';
const logger = new ConsoleLogger('foo', 'INFO');
logger.debug('callback data', data); // this will write the message since the global log level is 'DEBUG'

Web 開発中は、ブラウザコンソールログでグローバルログレベルを設定できます:

window.LOG_LEVEL = 'DEBUG';

サポートされているログレベル:

  • ERROR
  • WARN
  • INFO
  • DEBUG
  • VERBOSE