AtfLogFormatter
Defined in: packages/lambda-utils/src/logger.ts:82
Extends
Section titled “Extends”LogFormatter
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AtfLogFormatter():
AtfLogFormatter
Returns
Section titled “Returns”AtfLogFormatter
Inherited from
Section titled “Inherited from”LogFormatter.constructor
Methods
Section titled “Methods”formatAttributes()
Section titled “formatAttributes()”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.
Parameters
Section titled “Parameters”attributes
Section titled “attributes”UnformattedAttributes
Unformatted attributes
additionalLogAttributes
Section titled “additionalLogAttributes”LogAttributes
Additional log attributes
Returns
Section titled “Returns”LogItem
Example
Section titled “Example”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 };Overrides
Section titled “Overrides”LogFormatter.formatAttributes
formatError()
Section titled “formatError()”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.
Parameters
Section titled “Parameters”Error
Returns
Section titled “Returns”LogAttributes
Overrides
Section titled “Overrides”LogFormatter.formatError
formatTimestamp()
Section titled “formatTimestamp()”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'.
Parameters
Section titled “Parameters”Date
The date to format
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”LogFormatter.formatTimestamp
getCodeLocation()
Section titled “getCodeLocation()”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.
Parameters
Section titled “Parameters”stack?
Section titled “stack?”string
Returns
Section titled “Returns”string
Overrides
Section titled “Overrides”LogFormatter.getCodeLocation
© 2026 Axis Tech. Powered by axis-tech.co.