Logger Class

Logger allows libraries and apps to report potentially useful information about operations, and it allows apps and users to control how or if the logged information is displayed or collected. See Learning about Logging.

Methods

Name Description
constructor(): Logger    
configureLevels(cfg: LoggerLevelsConfig): void Static Set the log level for multiple categories at once.  
getLevel(category: string): undefined | LogLevel Static Get the minimum logging level for the specified category.  
merge the supplied metadata with all static metadata into one object  
initialize(logError?: LogFunction, logWarning?: LogFunction, logInfo?: LogFunction, logTrace?: LogFunction): void Static Initialize the logger streams.  
initializeToConsole(): void Static Initialize the logger to output to the console.  
isEnabled(category: string, level: LogLevel): boolean Static Check if messages in the specified category should be displayed at this level of severity.  
logError(category: string, message: string, metaData?: LoggingMetaData): void Static Log the specified message to the error stream.  
logException(category: string, err: any, log: LogFunction...): void Static Log the specified exception.  
logInfo(category: string, message: string, metaData?: LoggingMetaData): void Static Log the specified message to the info stream.  
logTrace(category: string, message: string, metaData?: LoggingMetaData): void Static Log the specified message to the trace stream.  
logWarning(category: string, message: string, metaData?: LoggingMetaData): void Static Log the specified message to the warning stream.  
parseLogLevel(str: string): LogLevel Static Interpret a string as the name of a LogLevel  
setLevel(category: string, minLevel: LogLevel): void Static Set the minimum logging level for the specified category.  
setLevelDefault(minLevel: LogLevel): void Static Set the least severe level at which messages should be displayed by default.  
stringify the metadata for a log message by merging the supplied metadata with all static metadata into one object that is then JSON.stringifyed.  
turnOffCategories(): void Static Turns off all category level filters previously defined with setLevel.  
turnOffLevelDefault(): void Static Turns off the least severe level at which messages should be displayed by default.  
validateProps(config: any): void Static Check that the specified object is a valid LoggerLevelsConfig.  

Properties

Name Type Description
_logError Protected Static undefined | LogFunction    
_logInfo Protected Static undefined | LogFunction    
_logTrace Protected Static undefined | LogFunction    
_logWarning Protected Static undefined | LogFunction    
categoryFilter Accessor Static ReadOnly Readonly<{ T }> Maps category names to the least severe level at which messages in that category should be displayed,  
logExceptionCallstacks Static boolean Should the call stack be included when an exception is logged?  
minLevel Accessor Static ReadOnly undefined | LogLevel The least severe level at which messages should be displayed by default.  
onLogLevelChanged Accessor Static ReadOnly BeEvent<() => void> An event raised whenever setLevel or setLevelDefault is called.  

Defined in

Last Updated: 23 November, 2024