Skip to content

Commit f92ebd3

Browse files
authored
docs: update next/nuxt docs (#7290)
1 parent 227781e commit f92ebd3

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

docs/content/4.sdk/2.getting-started/4.logger.md

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Logger
22

3-
The Logger provides a logging utility for Alokai Storefront projects. It allows you to log messages at various levels and ability to provide additional context.
3+
The Logger provides a logging utility for Alokai Storefront projects. It allows you to log messages at various levels and ability to provide additional context.
44

55
It is created to provide a unified way of logging messages across the project along with providing additional data out of the box.
66

@@ -14,7 +14,7 @@ In order to install the Logger, you need to update following packages to at leas
1414
* `@vue-storefront/sdk` to `3.3.0`
1515
* `@vue-storefront/nuxt` to `6.2.0`
1616
* `@vue-storefront/next` to `4.3.0`
17-
17+
1818
After updating the packages, you need to provide the Logger module to the SDK config.
1919

2020
::tabs{:titles='["Next.js", "Nuxt"]' class="mt-8"}
@@ -53,28 +53,18 @@ export default defineSdkConfig(({ buildModule, loggerModule, middlewareModule, g
5353
5454
The default configuration is already provided, but you can customize it by providing the following options:
5555
56-
* `level` - the minimum level of the message to be logged. The default value is `info`.
56+
* `level` - the minimum level of the message to be logged. The default value is `info`. Possible values are:
57+
* `emergency`
58+
* `alert`
59+
* `critical`
60+
* `error`
61+
* `warning`
62+
* `notice`
63+
* `info`
64+
* `debug`
5765
* `includeStackTrace` - a boolean value that determines if the stack trace should be included in the log message. The default value is `true`.
5866
* `handler` - a custom handler that will be called when the message is logged.
5967
60-
```ts
61-
type LoggerModuleConfig = Partial<{
62-
level: LogLevel;
63-
includeStackTrace: boolean;
64-
handler: LoggerInterface;
65-
[key: string]: any;
66-
}>;
67-
type LogLevel =
68-
| "emergency"
69-
| "alert"
70-
| "critical"
71-
| "error"
72-
| "warning"
73-
| "notice"
74-
| "info"
75-
| "debug";
76-
```
77-
7868
To provide the configuration for the Logger, you need to update the SDK config with the Logger module configuration by providing an object with options to the `buildModule` function, e.g.:
7969
```ts
8070
// ...
@@ -92,25 +82,6 @@ Then you can provide your own custom handler for the Logger. The handler must im
9282
Keep in mind that if you provide a custom handler, it will override the built-in logging functions and the other options passed to the Logger configuration will be ignored.
9383
::
9484
95-
```ts
96-
/**
97-
* Common interface for a logger.
98-
*/
99-
type LogData = unknown;
100-
type Metadata = Record<string, unknown>;
101-
102-
interface LoggerInterface {
103-
emergency(logData: LogData, metadata?: Metadata): void;
104-
alert(logData: LogData, metadata?: Metadata): void;
105-
critical(logData: LogData, metadata?: Metadata): void;
106-
error(logData: LogData, metadata?: Metadata): void;
107-
warning(logData: LogData, metadata?: Metadata): void;
108-
notice(logData: LogData, metadata?: Metadata): void;
109-
info(logData: LogData, metadata?: Metadata): void;
110-
debug(logData: LogData, metadata?: Metadata): void;
111-
}
112-
```
113-
11485
## Usage
11586
11687
You can use the Logger in the same way as you would use any other SDK modules:
@@ -160,3 +131,38 @@ useSdk().logger.info('Example log');
160131
::
161132
162133
Now instead of using `console.log` you can use the Logger to log messages at different levels.
134+
135+
## Type
136+
137+
```ts
138+
type LogData = unknown;
139+
type Metadata = Record<string, unknown>;
140+
type LogLevel =
141+
| "emergency"
142+
| "alert"
143+
| "critical"
144+
| "error"
145+
| "warning"
146+
| "notice"
147+
| "info"
148+
| "debug";
149+
150+
interface LoggerInterface {
151+
emergency(logData: LogData, metadata?: Metadata): void;
152+
alert(logData: LogData, metadata?: Metadata): void;
153+
critical(logData: LogData, metadata?: Metadata): void;
154+
error(logData: LogData, metadata?: Metadata): void;
155+
warning(logData: LogData, metadata?: Metadata): void;
156+
notice(logData: LogData, metadata?: Metadata): void;
157+
info(logData: LogData, metadata?: Metadata): void;
158+
debug(logData: LogData, metadata?: Metadata): void;
159+
}
160+
161+
type LoggerModuleConfig = Partial<{
162+
level: LogLevel;
163+
includeStackTrace: boolean;
164+
handler: LoggerInterface;
165+
[key: string]: any;
166+
}>;
167+
168+
```

0 commit comments

Comments
 (0)