Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update next/nuxt docs #7290

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 46 additions & 40 deletions docs/content/4.sdk/2.getting-started/4.logger.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Logger

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.
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.

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

Expand All @@ -14,7 +14,7 @@ In order to install the Logger, you need to update following packages to at leas
* `@vue-storefront/sdk` to `3.3.0`
* `@vue-storefront/nuxt` to `6.2.0`
* `@vue-storefront/next` to `4.3.0`

After updating the packages, you need to provide the Logger module to the SDK config.

::tabs{:titles='["Next.js", "Nuxt"]' class="mt-8"}
Expand Down Expand Up @@ -53,28 +53,18 @@ export default defineSdkConfig(({ buildModule, loggerModule, middlewareModule, g

The default configuration is already provided, but you can customize it by providing the following options:

* `level` - the minimum level of the message to be logged. The default value is `info`.
* `level` - the minimum level of the message to be logged. The default value is `info`. Possible values are:
* `emergency`
* `alert`
* `critical`
* `error`
* `warning`
* `notice`
* `info`
* `debug`
* `includeStackTrace` - a boolean value that determines if the stack trace should be included in the log message. The default value is `true`.
* `handler` - a custom handler that will be called when the message is logged.

```ts
type LoggerModuleConfig = Partial<{
level: LogLevel;
includeStackTrace: boolean;
handler: LoggerInterface;
[key: string]: any;
}>;
type LogLevel =
| "emergency"
| "alert"
| "critical"
| "error"
| "warning"
| "notice"
| "info"
| "debug";
```

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.:
```ts
// ...
Expand All @@ -92,25 +82,6 @@ Then you can provide your own custom handler for the Logger. The handler must im
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.
::

```ts
/**
* Common interface for a logger.
*/
type LogData = unknown;
type Metadata = Record<string, unknown>;

interface LoggerInterface {
emergency(logData: LogData, metadata?: Metadata): void;
alert(logData: LogData, metadata?: Metadata): void;
critical(logData: LogData, metadata?: Metadata): void;
error(logData: LogData, metadata?: Metadata): void;
warning(logData: LogData, metadata?: Metadata): void;
notice(logData: LogData, metadata?: Metadata): void;
info(logData: LogData, metadata?: Metadata): void;
debug(logData: LogData, metadata?: Metadata): void;
}
```

## Usage

You can use the Logger in the same way as you would use any other SDK modules:
Expand Down Expand Up @@ -160,3 +131,38 @@ useSdk().logger.info('Example log');
::

Now instead of using `console.log` you can use the Logger to log messages at different levels.

## Type

```ts
type LogData = unknown;
type Metadata = Record<string, unknown>;
type LogLevel =
| "emergency"
| "alert"
| "critical"
| "error"
| "warning"
| "notice"
| "info"
| "debug";

interface LoggerInterface {
emergency(logData: LogData, metadata?: Metadata): void;
alert(logData: LogData, metadata?: Metadata): void;
critical(logData: LogData, metadata?: Metadata): void;
error(logData: LogData, metadata?: Metadata): void;
warning(logData: LogData, metadata?: Metadata): void;
notice(logData: LogData, metadata?: Metadata): void;
info(logData: LogData, metadata?: Metadata): void;
debug(logData: LogData, metadata?: Metadata): void;
}

type LoggerModuleConfig = Partial<{
level: LogLevel;
includeStackTrace: boolean;
handler: LoggerInterface;
[key: string]: any;
}>;

```
Loading