Stairs/web/static/assets/ts/log.ts

79 lines
1.4 KiB
TypeScript
Raw Normal View History

export enum LogLevel
{
None,
Fatal,
Error,
Warning,
Info,
Verbose
}
export class Log
{
public static Level = LogLevel.Verbose;
public static fatal(context: string, message: any): void
{
if (this.Level >= LogLevel.Fatal)
this.log(context, message);
}
public static error(context: string, message: any): void
{
if (this.Level >= LogLevel.Error)
this.log(context, message);
}
public static warning(context: string, message: any): void
{
if (this.Level >= LogLevel.Warning)
this.log(context, message);
}
public static info(context: string, message: any): void
{
if (this.Level >= LogLevel.Info)
this.log(context, message);
}
public static verbose(context: string, message: any): void
{
if (this.Level >= LogLevel.Verbose)
this.log(context, message);
}
private static log(context: string, message: any): void
{
switch (typeof(message))
{
case 'undefined':
console.log(context + ': undefined');
break;
case 'boolean':
case 'number':
case 'string':
case 'symbol':
console.log(context + ': ' + message);
break;
default:
if (message === null)
console.log(context + ': null');
else
{
console.log(context + ': (object)');
console.log(message);
}
break;
}
}
}