Where to find AWS Amplify Logger logs

Viewed 6039

Im currently working on a WebApp created with AWS Amplify, where I have to implement logging. Based on the AWS Amplify Docs there is a built in Logger function, which i tried to implement, but cant seem to find it anywhere in my AWS console.

Does anybody know where to find the logs?

2 Answers

Hi all, I see this is an older question and just thought I would provide an answer to assist with anyone who is directed here (with similar questions, specifically in regards to the Amplify utility - Logger) The question appears to be referring more towards logging for historical reasons as opposed to the Logger which logs to the console window and the answer is probably not what the questioner requires, however the question itself could bring a number of people here looking for answers on how to use the Amplify Logger or where to find its output. If so I hope this helps.

Amplify Logger

The simple answer to the question

Where to find AWS Amplify Logger logs

is that Amplify Logger outputs content directly to your web browser console window.

More Details

The Amplify Logger utility logs content to the browser console. While developing your app you can set the global log level of your browser console by typing the following (into your console) or you can set it directly in your code:

window.LOG_LEVEL = 'INFO';

You have several log levels you can choose from including DEBUG, INFO, WARN, ERROR and VERBOSE.

When you call Logger from your code:

logger.info(`user has signed in with ${username}`);

and have set the appropriate log level, you should see the output (in your console):

[INFO] 20:09.950 YourLoggerName - user has signed in with johndoe@example.com

And just for completeness, this is how to use Amplify Logger in an App:

import { Logger } from 'aws-amplify';

const logger = new Logger('YourLoggerName');

const exampleSignIn = () => {
    const { username, password } = inputs;
    logger.info(`user signing in with ${username}`);
    Auth.signIn(username, password)
        .then(user => signInSuccess(user))
        .catch(err => signInError(err));
}

const signInError = (err) => {
    logger.error('error signing in', err); 
    // more code
}  

There are a few more options and ways to use it, as described in the documentation linked in the question, such as setting logging levels etc.

Here is that link again:

https://docs.amplify.aws/lib/utilities/logger/q/platform/js

There is this solution: https://github.com/aws-amplify/amplify-js/pull/8309

Even though this pull request was merged and some people claim to have it working. I personally ran into permission trouble and this "feature" isn't named anywhere in the docs of the amplify.aws website.

Related