Skip to content

AtfLogFormatter

Open in ChatGPTOpen in Claude

Defined in: packages/lambda-utils/src/logger.ts:82

  • LogFormatter

new AtfLogFormatter(): AtfLogFormatter

AtfLogFormatter

LogFormatter.constructor

formatAttributes(attributes, additionalLogAttributes): LogItem

Defined in: packages/lambda-utils/src/logger.ts:83

Format key-value pairs of log attributes.

You should implement this method in a subclass to define the structure of the log item and instantiate a new LogItem object with the formatted attributes.

Note that when implementing this method, you should avoid mutating the attributes and additionalLogAttributes objects directly. Instead, create a new object with the desired structure and return it.

If mutation is necessary, you can create a structuredClone of the object to avoid side effects.

UnformattedAttributes

Unformatted attributes

LogAttributes

Additional log attributes

LogItem

import { LogFormatter, LogItem } from '@aws-lambda-powertools/logger';
import type {
LogAttributes,
UnformattedAttributes,
} from '@aws-lambda-powertools/logger/types';
class MyCompanyLogFormatter extends LogFormatter {
public formatAttributes(
attributes: UnformattedAttributes,
additionalLogAttributes: LogAttributes
): LogItem {
const baseAttributes = {
message: attributes.message,
service: attributes.serviceName,
environment: attributes.environment,
awsRegion: attributes.awsRegion,
correlationIds: {
awsRequestId: attributes.lambdaContext?.awsRequestId,
xRayTraceId: attributes.xRayTraceId,
},
lambdaFunction: {
name: attributes.lambdaContext?.functionName,
arn: attributes.lambdaContext?.invokedFunctionArn,
memoryLimitInMB: attributes.lambdaContext?.memoryLimitInMB,
version: attributes.lambdaContext?.functionVersion,
coldStart: attributes.lambdaContext?.coldStart,
},
logLevel: attributes.logLevel,
timestamp: this.formatTimestamp(attributes.timestamp), // You can extend this function
logger: {
sampleRateValue: attributes.sampleRateValue,
},
};
const logItem = new LogItem({ attributes: baseAttributes });
// add any attributes not explicitly defined
logItem.addAttributes(additionalLogAttributes);
return logItem;
}
}
export { MyCompanyLogFormatter };

LogFormatter.formatAttributes


formatError(error): LogAttributes

Defined in: packages/lambda-utils/src/logger.ts:113

Phase 3G — error formatting with a bundled code location.

name and location are unmasked: a code identifier and a bundled file:line:col are not PII and are the fields you click through on. message and stack may carry caller-supplied PII, so both are masked with the same rules as every other log value.

Error

LogAttributes

LogFormatter.formatError


formatTimestamp(now): string

Defined in: node_modules/.pnpm/@aws-lambda-powertools+logger@2.34.0_@middy+core@7.7.0/node_modules/@aws-lambda-powertools/logger/lib/esm/formatter/LogFormatter.d.ts:107

Format a date into an ISO 8601 string with the configured timezone.

The timezone is read from the TZ environment variable, if present. Otherwise, the timezone defaults to ':UTC'.

Date

The date to format

string

LogFormatter.formatTimestamp


getCodeLocation(stack?): string

Defined in: packages/lambda-utils/src/logger.ts:128

Parse the first file:line:col frame out of an error stack. Returns "" for an empty/undefined stack or an unparseable one. Only the basename is kept (the bundled file), matching the standalone axis-tech-be-lib-logger behaviour adapted to Powertools v2.

string

string

LogFormatter.getCodeLocation

© 2026 Axis Tech. Powered by axis-tech.co.