Appearance
Logger
Fingermark Logger abstraction
Overview
Fingermark Logger includes 3 different logger instances that follow the same format. ApexLogger which integrates with Apex Logs, FallbackLogger which is an abstraction of our syntax to the normal console logging functions and NewRelicLogger which integrates with New Relic Browser agent and adds PageAction and then you can see in New Relic Dashboard.
See more: Notion - Logging.
One of the primary use cases for the logger is to setup default fields for all logs (client tags, domain tags etc)
ApexLogger
Usage
js
import { ApexLogger } from '@fingermarkglobal/logger';
window.logger = new ApexLogger({
fields: {
client: 'Restaurant Default',
},
token: process.env.POI_APP_LOGGER_TOKEN,
project: process.env.POI_APP_LOGGER_PROJECT,
endpoint: process.env.POI_APP_LOGGER_ENDPOINT,
level: process.env.POI_APP_LOG_LEVEL,
});NewRelicLogger
Is a implementation of a logging utility that integrates with the New Relic platform. The NewRelicLogger class implements the following functionality:
- Configuration of log levels, additional fields and project values to associate logs with the appropriate context.
- Setting custom attributes for New Relic, such as environment, organization, project, release and serial.
- Logging messages at various levels (debug, info, warn, trace, error) with additional metadata (fields, scopes) and the option to override the project associated with the log.
- Stringifying log messages and adding them as events to the New Relic platform as Page Actions.
The logging levels, additional fields and project values are set during the construction of the NewRelicLogger class. The class provides methods to add log messages at various levels, clear additional fields, update additional fields, and send to New Relic. The logging methods (e.g. debug, info, etc.) all make use of the addLog method to log messages with the appropriate metadata. The processLogs method is used to add logs to New Relic. The init method is used to initialize the logger.
API Keys can be found here: https://www.notion.so/fingermark/New-Relic-Log-Ingest-Keys-8f61e03b3f754e2f8006eb2eb92eb4e0
Initialize
js
import { NewRelicLogger } from '@fingermarkglobal/logger';
import { version } from './package.json';
window.logger = new NewRelicLogger({
fields: {
release: version,
environment: process.env.POI_APP_ENV,
organisation: process.env.POI_APP_LOGGER_CLIENT,
},
project: process.env.POI_APP_LOGGER_PROJECT,
level: process.env.POI_APP_LOG_LEVEL,
apiKey: process.env.POI_APP_LOGGER_NR_API_KEY,
endpoint: process.env.POI_APP_LOGGER_NR_ENDPOINT,
batchNumber: process.env.POI_APP_LOGGER_NR_BATCH_NUMBER,
interval: process.env.POI_APP_LOGGER_NR_INTERVAL,
retries: process.env.POI_APP_LOGGER_NR_RETRIES,
retriesInterval: process.env.POI_APP_LOGGER_NR_RETRIES_INTERVAL,
});Update Aditional fields
js
logger.updateAdditionalFields({ fields: { serial: settings?.serial } });Add Log (ex. info)
js
logger.info(
`Adyen - destructPayment() - payment decrypted payload response: ${JSON.stringify(
payload,
null,
2,
)}`,
);