Standard libraries that lift up your code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.1 KiB

/**
* Base type for logging levels.
*/
enum LoggingLevel {
Silent = 0,
Success = 1,
Error = 2,
Warning = 3,
Info = 4,
Debug = 5,
Verbose = 6,
}
/**
* Returns true if the given element is a logging level.
* @param something
* @return boolean
*/
const isLoggingLevel = (something: unknown): something is LoggingLevel => {
return [
LoggingLevel.Silent,
LoggingLevel.Success,
LoggingLevel.Error,
LoggingLevel.Warning,
LoggingLevel.Info,
LoggingLevel.Debug,
LoggingLevel.Verbose,
].includes(something as any)
}
/**
* Base type for a message written to the log.
*/
interface LogMessage {
level: LoggingLevel,
date: Date,
output: any,
callerName: string,
}
/**
* Returns true if the given object is a log message.
* @param something
* @return boolean
*/
const isLogMessage = (something: unknown): something is LogMessage => {
return isLoggingLevel((something as any)?.level) && (something as any)?.date instanceof Date
}
export { LoggingLevel, LogMessage, isLoggingLevel, isLogMessage }