summaryrefslogtreecommitdiff
path: root/std/log/mod.ts
diff options
context:
space:
mode:
authorChris Knight <cknight1234@gmail.com>2020-06-12 14:27:41 +0100
committerGitHub <noreply@github.com>2020-06-12 09:27:41 -0400
commit81d09ad01c92a9547cdb388044b3b3ce8b077aca (patch)
treebb269b0e1d4b5332bc7ceffb1efeb6d633adb023 /std/log/mod.ts
parentd0970daacda0b6f6c2077c2f81948536b574bbe9 (diff)
feat(std/log): inline and deferred statement resolution logging (#5192)
Diffstat (limited to 'std/log/mod.ts')
-rw-r--r--std/log/mod.ts89
1 files changed, 79 insertions, 10 deletions
diff --git a/std/log/mod.ts b/std/log/mod.ts
index e596c81ba..f59a84449 100644
--- a/std/log/mod.ts
+++ b/std/log/mod.ts
@@ -72,16 +72,85 @@ export function getLogger(name?: string): Logger {
return result;
}
-export const debug = (msg: string, ...args: unknown[]): void =>
- getLogger("default").debug(msg, ...args);
-export const info = (msg: string, ...args: unknown[]): void =>
- getLogger("default").info(msg, ...args);
-export const warning = (msg: string, ...args: unknown[]): void =>
- getLogger("default").warning(msg, ...args);
-export const error = (msg: string, ...args: unknown[]): void =>
- getLogger("default").error(msg, ...args);
-export const critical = (msg: string, ...args: unknown[]): void =>
- getLogger("default").critical(msg, ...args);
+export function debug<T>(msg: () => T, ...args: unknown[]): T | undefined;
+export function debug<T>(
+ msg: T extends Function ? never : T,
+ ...args: unknown[]
+): T;
+export function debug<T>(
+ msg: (T extends Function ? never : T) | (() => T),
+ ...args: unknown[]
+): T | undefined {
+ // Assist TS compiler with pass-through generic type
+ if (msg instanceof Function) {
+ return getLogger("default").debug(msg, ...args);
+ }
+ return getLogger("default").debug(msg, ...args);
+}
+
+export function info<T>(msg: () => T, ...args: unknown[]): T | undefined;
+export function info<T>(
+ msg: T extends Function ? never : T,
+ ...args: unknown[]
+): T;
+export function info<T>(
+ msg: (T extends Function ? never : T) | (() => T),
+ ...args: unknown[]
+): T | undefined {
+ // Assist TS compiler with pass-through generic type
+ if (msg instanceof Function) {
+ return getLogger("default").info(msg, ...args);
+ }
+ return getLogger("default").info(msg, ...args);
+}
+
+export function warning<T>(msg: () => T, ...args: unknown[]): T | undefined;
+export function warning<T>(
+ msg: T extends Function ? never : T,
+ ...args: unknown[]
+): T;
+export function warning<T>(
+ msg: (T extends Function ? never : T) | (() => T),
+ ...args: unknown[]
+): T | undefined {
+ // Assist TS compiler with pass-through generic type
+ if (msg instanceof Function) {
+ return getLogger("default").warning(msg, ...args);
+ }
+ return getLogger("default").warning(msg, ...args);
+}
+
+export function error<T>(msg: () => T, ...args: unknown[]): T | undefined;
+export function error<T>(
+ msg: T extends Function ? never : T,
+ ...args: unknown[]
+): T;
+export function error<T>(
+ msg: (T extends Function ? never : T) | (() => T),
+ ...args: unknown[]
+): T | undefined {
+ // Assist TS compiler with pass-through generic type
+ if (msg instanceof Function) {
+ return getLogger("default").error(msg, ...args);
+ }
+ return getLogger("default").error(msg, ...args);
+}
+
+export function critical<T>(msg: () => T, ...args: unknown[]): T | undefined;
+export function critical<T>(
+ msg: T extends Function ? never : T,
+ ...args: unknown[]
+): T;
+export function critical<T>(
+ msg: (T extends Function ? never : T) | (() => T),
+ ...args: unknown[]
+): T | undefined {
+ // Assist TS compiler with pass-through generic type
+ if (msg instanceof Function) {
+ return getLogger("default").critical(msg, ...args);
+ }
+ return getLogger("default").critical(msg, ...args);
+}
export async function setup(config: LogConfig): Promise<void> {
state.config = {