##// END OF EJS Templates
Added tag v1.4.0 for changeset 1a8a956a013f
Added tag v1.4.0 for changeset 1a8a956a013f

File last commit:

r148:cd81c631015f v1.4.0-rc6 default
r157:f563f4b24ce3 default
Show More
TraceSource.ts
147 lines | 3.7 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / log / TraceSource.ts
cin
changed the project structure
r49 import { Observable } from "../Observable";
cin
minor refactoring of TraceSource, code linting
r53 import { Registry } from "./Registry";
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 import { TraceEventData } from "./TraceEventData";
cin
corrected code to support ts strict mode...
r115 import { EventProvider } from "../EventProvider";
cin
changed the project structure
r49
export const DebugLevel = 400;
export const LogLevel = 300;
export const WarnLevel = 200;
export const ErrorLevel = 100;
export const SilentLevel = 0;
cin
minor refactoring of TraceSource, code linting
r53 export interface TraceEvent {
cin
changed the project structure
r49 readonly source: TraceSource;
readonly level: number;
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 readonly message: any;
cin
changed the project structure
r49
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 readonly args?: any[];
cin
fixed "singleton" activation type handling in container configuration...
r65 }
cin
changed the project structure
r49 export class TraceSource {
cin
minor refactoring of TraceSource, code linting
r53 readonly id: any;
cin
changed the project structure
r49
cin
corrected code to support ts strict mode...
r115 level = 0;
cin
changed the project structure
r49
cin
minor refactoring of TraceSource, code linting
r53 readonly events: Observable<TraceEvent>;
cin
changed the project structure
r49
cin
corrected code to support ts strict mode...
r115 private readonly _provider: EventProvider<TraceEvent>;
cin
changed the project structure
r49
cin
corrected code to support ts strict mode...
r115 constructor(id?: any) {
cin
changed the project structure
r49
this.id = id || new Object();
cin
corrected code to support ts strict mode...
r115 this._provider = new EventProvider();
this.events = this._provider.getObservable();
cin
changed the project structure
r49 }
cin
corrected code to support ts strict mode...
r115 protected emit(level: number, message: any, args: any[]) {
this._provider.post(new TraceEventData(this, level, message, args));
cin
changed the project structure
r49 }
isDebugEnabled() {
return this.level >= DebugLevel;
}
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 debug(data: any): void;
debug(msg: string, ...args: any[]): void;
cin
changed the project structure
r49 debug(msg: string, ...args: any[]) {
if (this.isEnabled(DebugLevel))
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this.emit(DebugLevel, msg, args);
cin
changed the project structure
r49 }
isLogEnabled() {
return this.level >= LogLevel;
}
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 log(data: any): void;
log(msg: string, ...args: any[]): void;
cin
changed the project structure
r49 log(msg: string, ...args: any[]) {
if (this.isEnabled(LogLevel))
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this.emit(LogLevel, msg, args);
cin
changed the project structure
r49 }
isWarnEnabled() {
return this.level >= WarnLevel;
}
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 warn(data: any): void;
warn(msg: string, ...args: any[]): void;
cin
changed the project structure
r49 warn(msg: string, ...args: any[]) {
if (this.isEnabled(WarnLevel))
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this.emit(WarnLevel, msg, args);
cin
changed the project structure
r49 }
/**
* returns true if errors will be recorded.
*/
isErrorEnabled() {
return this.level >= ErrorLevel;
}
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 /** Traces a error
* @param data The object which will be passed to the underlying listeners
*/
error(data: any): void;
cin
changed the project structure
r49 /**
* Traces a error.
cin
minor refactoring of TraceSource, code linting
r53 *
cin
changed the project structure
r49 * @param msg the message.
* @param args parameters which will be substituted in the message.
*/
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 error(msg: string, ...args: any[]): void;
cin
changed the project structure
r49 error(msg: string, ...args: any[]) {
if (this.isEnabled(ErrorLevel))
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this.emit(ErrorLevel, msg, args);
cin
changed the project structure
r49 }
/**
* Checks whether the specified level is enabled for this
* trace source.
cin
minor refactoring of TraceSource, code linting
r53 *
cin
changed the project structure
r49 * @param level the trace level which should be checked.
*/
isEnabled(level: number) {
return (this.level >= level);
}
/**
* Traces a raw event, passing data as it is to the underlying listeners
cin
minor refactoring of TraceSource, code linting
r53 *
cin
changed the project structure
r49 * @param level the level of the event
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 * @param msg the data of the event, can be a simple string or any object.
cin
changed the project structure
r49 */
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 traceEvent(level: number, msg: any, ...args: any[]) {
cin
changed the project structure
r49 if (this.isEnabled(level))
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this.emit(level, msg, args);
cin
changed the project structure
r49 }
/**
* Register the specified handler to be called for every new and already
* created trace source.
cin
minor refactoring of TraceSource, code linting
r53 *
cin
changed the project structure
r49 * @param handler the handler which will be called for each trace source
*/
static on(handler: (source: TraceSource) => void) {
return Registry.instance.on(handler);
}
/**
* Creates or returns already created trace source for the specified id.
cin
minor refactoring of TraceSource, code linting
r53 *
cin
changed the project structure
r49 * @param id the id for the trace source
*/
static get(id: any) {
cin
Fixed circular dependency TraceSource<->Registry
r148 if (!Registry.instance.has(id)) {
const trace = new TraceSource(id);
Registry.instance.add(id, trace);
return trace;
} else {
return Registry.instance.get(id);
}
cin
changed the project structure
r49 }
}