Skip to content

Commit

Permalink
feat: bump @aws-lambda-powertools/logger@v2 (#71)
Browse files Browse the repository at this point in the history
* feat: bump @aws-lambda-powertools/[email protected]

* feat: allow wider v2 version

---------

Co-authored-by: Victor Korzunin <[email protected]>
  • Loading branch information
godu and floydspace authored Oct 31, 2024
1 parent af642d3 commit b223139
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-dolphins-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-aws/powertools-logger": minor
---

bump @aws-lambda-powertools/logger to v2
4 changes: 2 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const commonPeerDeps = ["effect@>=3.0.0 <4.0.0"];
new TypeScriptLibProject({
parent: project,
name: "powertools-logger",
devDeps: ["@aws-lambda-powertools/commons@1.9.0"],
devDeps: ["@aws-lambda-powertools/commons@2.0.0"],
peerDeps: [
...commonPeerDeps,
"@aws-lambda-powertools/logger@>=1.9.0", // lower versions are not supported, raise an issue if you need it
"@aws-lambda-powertools/logger@>=2.0.0", // lower versions are not supported, raise an issue if you need it
],
});

Expand Down
4 changes: 2 additions & 2 deletions packages/powertools-logger/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/powertools-logger/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 24 additions & 16 deletions packages/powertools-logger/src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* @since 1.0.0
*/
import { Logger } from "@aws-lambda-powertools/logger";
import type { Logger } from "@aws-lambda-powertools/logger";
import type {
LogAttributes,
LogItemExtraInput,
LogItemMessage,
LogLevelThresholds,
} from "@aws-lambda-powertools/logger/lib/types";
} from "@aws-lambda-powertools/logger/types";
import {
Cause,
Effect,
Expand All @@ -23,6 +22,27 @@ import {
import { LoggerInstance, LoggerInstanceLayer } from "./LoggerInstance";
import { DefaultLoggerOptionsLayer } from "./LoggerOptions";

const LogLevelThreshold = {
TRACE: 6,
DEBUG: 8,
INFO: 12,
WARN: 16,
ERROR: 20,
CRITICAL: 24,
SILENT: 28,
} as const;

const MappedLogLevel = {
[LogLevel.All.label]: LogLevelThreshold.TRACE,
[LogLevel.Trace.label]: LogLevelThreshold.TRACE,
[LogLevel.Debug.label]: LogLevelThreshold.DEBUG,
[LogLevel.Info.label]: LogLevelThreshold.INFO,
[LogLevel.Warning.label]: LogLevelThreshold.WARN,
[LogLevel.Error.label]: LogLevelThreshold.ERROR,
[LogLevel.Fatal.label]: LogLevelThreshold.CRITICAL,
[LogLevel.None.label]: LogLevelThreshold.SILENT,
} as const;

const logExtraInput = FiberRef.unsafeMake<LogItemExtraInput>([]);

const processLog = (effect: (message: string) => Effect.Effect<void>) => {
Expand Down Expand Up @@ -109,27 +129,15 @@ const makeLoggerInstance = (logger: Logger) => {
});

const unsafeLogger = logger as unknown as {
logLevelThresholds: LogLevelThresholds;
processLogItem: (
logLevel: number,
input: LogItemMessage,
extraInput: LogItemExtraInput,
) => void;
};

const mappedLogLevel = {
[LogLevel.All.label]: "DEBUG" as const,
[LogLevel.Debug.label]: "DEBUG" as const,
[LogLevel.Trace.label]: "DEBUG" as const,
[LogLevel.Info.label]: "INFO" as const,
[LogLevel.Warning.label]: "WARN" as const,
[LogLevel.Error.label]: "ERROR" as const,
[LogLevel.Fatal.label]: "CRITICAL" as const,
[LogLevel.None.label]: "SILENT" as const,
};

unsafeLogger.processLogItem(
unsafeLogger.logLevelThresholds[mappedLogLevel[options.logLevel.label]],
MappedLogLevel[options.logLevel.label],
!Array.isArray(options.message)
? options.message
: options.message.length === 1 // since v3.5 the message is always an array
Expand Down
2 changes: 1 addition & 1 deletion packages/powertools-logger/src/LoggerOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @since 1.0.0
*/
import type { ConstructorOptions } from "@aws-lambda-powertools/logger/lib/types";
import type { ConstructorOptions } from "@aws-lambda-powertools/logger/types";
import * as Context from "effect/Context";
import * as Layer from "effect/Layer";

Expand Down
23 changes: 14 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b223139

Please sign in to comment.