Skip to content

Commit e6d5d8e

Browse files
authored
chore: add more verbose logger bootstrap error message (#7314)
1 parent 01524a1 commit e6d5d8e

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

.changeset/red-days-exercise.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@vue-storefront/middleware": patch
3+
---
4+
5+
** [CHANGED] **
6+
7+
- added more verbose message with a troubleshooting guide in case that the `getLogger` method was not able to retrieve the logger instance.
8+
9+
** [FIXED] **
10+
11+
- changed `level` property to `verbosity` in the `LoggerConfig` interface.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { LoggerFactory, LoggerType } from "@vue-storefront/logger";
2+
3+
import { injectMetadata, lockLogger } from "./injectMetadata";
4+
5+
/**
6+
* This logger is used as a fallback logger in case of any error during the
7+
* initialization of the logger. It is used to log the error and provide a
8+
* default logger for the application. It should not be used as a primary
9+
* logger.
10+
*/
11+
const fallbackLogger = injectMetadata(
12+
lockLogger(LoggerFactory.create(LoggerType.ConsolaGcp)),
13+
() => ({
14+
alokai: {
15+
context: "middleware",
16+
},
17+
})
18+
);
19+
20+
export { fallbackLogger };

packages/middleware/src/logger/getLogger.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LoggerInterface } from "@vue-storefront/logger";
22
import type { AlokaiContainer, ResponseWithAlokaiLocals } from "../types";
3+
import { fallbackLogger } from "./fallbackLogger";
34

45
type ContextSubset = { res: ResponseWithAlokaiLocals };
56
type LoggerSource = AlokaiContainer | ResponseWithAlokaiLocals | ContextSubset;
@@ -19,8 +20,23 @@ function findLogger(source: LoggerSource): LoggerInterface {
1920

2021
export function getLogger(source: LoggerSource): LoggerInterface {
2122
const logger = findLogger(source);
23+
2224
if (!logger) {
23-
throw new Error("Logger instance could not be determined");
25+
fallbackLogger.alert("Logger instance could not be resolved", {
26+
troubleshooting: {
27+
message:
28+
"This issue is likely caused by a version mismatch in the middleware stack. Note: Logger functionality was introduced in version 5.1.0 of the middleware package. For more details, refer to https://docs.alokai.com/middleware/guides/logging.",
29+
steps: [
30+
"Update all middleware packages to the latest compatible version to ensure logger compatibility.",
31+
"Ensure API client packages are also updated, as they rely on compatible middleware versions.",
32+
"Update unified API packages to the latest version to maintain compatibility with the updated middleware packages.",
33+
],
34+
},
35+
});
36+
37+
throw new Error(
38+
"Logger instance could not be determined. In most cases, this is due to a versions missmatch in the middleware stack."
39+
);
2440
}
2541
return logger;
2642
}

packages/middleware/src/types/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export type LogVerbosity =
2323
*/
2424
export interface LoggerOptions {
2525
/**
26-
* The log level aligned with RFC5424.
26+
* The log verbosity level aligned with RFC5424.
2727
*/
28-
level?: LogVerbosity;
28+
verbosity?: LogVerbosity;
2929

3030
/**
3131
* Whether to include the stack trace in the log message.

0 commit comments

Comments
 (0)