generated from uwu/neptune-template
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LastFM - Fix playback check issue & improve logging
- Loading branch information
Showing
12 changed files
with
852 additions
and
59 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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
import { actions } from "@neptune"; | ||
import { Message, Severity } from "neptune-types/tidal"; | ||
|
||
type LoggerFunc = (...data: any[]) => void; | ||
type MessengerFunc = (messageInfo: Message) => void; | ||
|
||
type Logger<T extends LoggerFunc = LoggerFunc> = { | ||
(...data: Parameters<T>): undefined; | ||
withContext(context: string): (...data: Parameters<T>) => undefined; | ||
}; | ||
type Messenger = { | ||
(message: unknown): undefined; | ||
withContext(context: string): (message: unknown) => undefined; | ||
}; | ||
|
||
export const Tracer = (source: string) => { | ||
const createLogger = <T extends LoggerFunc>(logger: T): Logger<T> => { | ||
const _logger = (...data: Parameters<T>) => { | ||
logger(source, ...data); | ||
return undefined; | ||
}; | ||
_logger.withContext = | ||
(context: string) => | ||
(...data: Parameters<T>) => { | ||
logger(context, ...data); | ||
return undefined; | ||
}; | ||
return _logger; | ||
}; | ||
|
||
const log = createLogger(console.log); | ||
const warn = createLogger(console.warn); | ||
const err = createLogger(console.error); | ||
|
||
const createMessager = (logger: Logger, messager: MessengerFunc, severity: Severity): Messenger => { | ||
const _messager = (message: unknown) => { | ||
logger(message); | ||
messager({ message: `${source} - ${message}`, category: "OTHER", severity }); | ||
return undefined; | ||
}; | ||
_messager.withContext = (context: string) => { | ||
const loggerWithContext = logger.withContext(context); | ||
return (message: unknown) => { | ||
loggerWithContext(message); | ||
if (message instanceof Error) message = message.message; | ||
messager({ message: `${source}.${context} - ${message}`, category: "OTHER", severity }); | ||
return undefined; | ||
}; | ||
}; | ||
return _messager; | ||
}; | ||
|
||
return { | ||
log, | ||
warn, | ||
err, | ||
msg: { | ||
log: createMessager(log, actions.message.messageInfo, "INFO"), | ||
warn: createMessager(warn, actions.message.messageWarn, "WARN"), | ||
err: createMessager(err, actions.message.messageError, "ERROR"), | ||
}, | ||
}; | ||
}; | ||
export const libTrace = Tracer("[lib]"); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.