Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions .changeset/export-logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"astro": patch
---

Fixes a bug where users couldn't properly type the logger functions at runtime. Now users can import `AstroRuntimeLogger`.
Comment thread
ArmandPhilippot marked this conversation as resolved.
Outdated

35 changes: 21 additions & 14 deletions packages/astro/src/types/public/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ export interface AstroGlobal<
};
}

/**
* A type containing functions for logging messages.
*
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#logger)
*/
export interface AstroRuntimeLogger {
/**
* Logs a message with `info` level.
*/
info: (msg: string) => void;
/**
* Logs a message with `warn` level.
*/
warn: (msg: string) => void;
/**
* Logs a message with `error` level.
*/
error: (msg: string) => void;
}

/**
* The `APIContext` is the object made available to endpoints and middleware.
* It is a subset of the `Astro` global object available in pages.
Expand Down Expand Up @@ -579,20 +599,7 @@ export interface APIContext<
/**
* It exposes utilities for logging messages.
*/
logger: {
/**
* Logs a message with `info` level.
*/
info: (msg: string) => void;
/**
* Logs a message with `warn` level.
*/
warn: (msg: string) => void;
/**
* Logs a message with `error` level.
*/
error: (msg: string) => void;
};
logger: AstroRuntimeLogger;

/**
* The route currently rendered. It's stripped of the `srcDir` and the `pages` folder, and it doesn't contain the extension.
Expand Down
Loading