Skip to content

Backend logging ​

Implementing logging ​

To implement logging on the backend, the internal luna-logger package should be used. The logger package itself can be found in the luna/packages/logger/ directory.

Different log levels are available (Log, Info, Debug, Warn, Error etc) and the logger can be called by specifying the level and any associated log messages/objects:

import { Logger } from '@bhag-business-platform/luna-logger';

Logger.Debug(JSON.stringify(objectToLog));
...
const errorMsg = 'This is an error!';
Logger.Error(errorMsg);

Logs are then viewable in AWS CloudWatch

AWS CloudWatch ​

To view logs in AWS CloudWatch:

  1. Navigate to CloudWatch in the AWS console
  2. On the left hand side menu select the 'Log groups' option
  3. Select or search for the relevant log group (e.g the log group for the email queue handler lambda is /aws/lambda/polaris-emails-queue-handler-function)
  4. Scroll down to see the log streams available to view for that log group (most recent will be at the top)
    • Alternatively - click the "Search log group" button in the top right to search through all log streams (you may want to make use of time range filters when searching this way)
  5. Individual log messages can be viewed inside each log stream (most recent will be at the bottom by default)
  6. The log messages can be queried/filtered as needed (read about how best to use filter patterns here)

Made with ❤️ by the Luna team