-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #439
- Loading branch information
Showing
8 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './components' | ||
export * from './interfaces' | ||
export { LogLevel } from './loggerSystem' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as u from '@virtuoso.dev/urx' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
declare namespace globalThis { | ||
let VIRTUOSO_LOG_LEVEL: LogLevel | undefined | ||
} | ||
|
||
export enum LogLevel { | ||
DEBUG, | ||
INFO, | ||
WARN, | ||
ERROR, | ||
} | ||
export interface LogMessage { | ||
level: LogLevel | ||
message: any | ||
label: string | ||
} | ||
|
||
export type Log = (label: string, message: any, level?: LogLevel) => void | ||
|
||
const CONSOLE_METHOD_MAP = { | ||
[LogLevel.DEBUG]: 'debug', | ||
[LogLevel.INFO]: 'log', | ||
[LogLevel.WARN]: 'warn', | ||
[LogLevel.ERROR]: 'error', | ||
} | ||
|
||
export const loggerSystem = u.system( | ||
() => { | ||
const logLevel = u.statefulStream<LogLevel>(LogLevel.ERROR) | ||
const log = u.statefulStream<Log>((label: string, message: any, level: LogLevel = LogLevel.INFO) => { | ||
const currentLevel = globalThis['VIRTUOSO_LOG_LEVEL'] ?? u.getValue(logLevel) | ||
if (level >= currentLevel) { | ||
// @ts-expect-error we can call console the way we want | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
console[CONSOLE_METHOD_MAP[level]]('%creact-virutoso: %c%s %o', 'color: #0253b3; font-weight: bold', 'color: black', label, message) | ||
} | ||
}) | ||
|
||
return { | ||
log, | ||
logLevel, | ||
} | ||
}, | ||
[], | ||
{ singleton: true } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters