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:
- Navigate to CloudWatch in the AWS console
- On the left hand side menu select the 'Log groups' option
- 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) - 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)
- Individual log messages can be viewed inside each log stream (most recent will be at the bottom by default)
- The log messages can be queried/filtered as needed (read about how best to use filter patterns here)
