UNPKG

4.31 kBTypeScriptView Raw
1/**
2 * An interface used to define a writer used by trace to print (log).
3 */
4export interface TraceWriter {
5 write(message: any, category: string, type?: number): void;
6}
7
8/**
9 * An interface used to trace information about specific event.
10 */
11export interface TraceEventListener {
12 filter: string;
13 on(object: Object, name: string, data?: any): void;
14}
15
16/**
17 * An interface used to for handling trace error
18 */
19export interface TraceErrorHandler {
20 handlerError(error: Error): any;
21}
22
23export namespace Trace {
24 /**
25 * Enables the trace module.
26 */
27 export function enable(): void;
28
29 /**
30 * Disables the trace module.
31 */
32 export function disable(): void;
33
34 /**
35 * A function that returns whether the tracer is enabled and there is a point in writing messages.
36 * Check this to avoid writing complex string templates.
37 * Send error messages even if tracing is disabled.
38 */
39 export function isEnabled(): boolean;
40
41 /**
42 * Adds a TraceWriter instance to the trace module.
43 * @param writer The TraceWriter instance to add.
44 */
45 export function addWriter(writer: TraceWriter): void;
46
47 /**
48 * Removes a TraceWriter instance from the trace module.
49 * @param writer The TraceWriter instance to remove.
50 */
51 export function removeWriter(writer: TraceWriter): void;
52
53 /**
54 * Clears all the writers from the trace module.
55 */
56 export function clearWriters(): void;
57
58 /**
59 * Sets the categories the module will trace.
60 * @param categories The comma-separated list of categories. If not specified all messages from all categories will be traced.
61 */
62 export function setCategories(categories: string): void;
63
64 /**
65 * Adds categories to existing categories the module will trace.
66 * @param categories The comma-separated list of categories. If not specified all messages from all categories will be traced.
67 */
68 export function addCategories(categories: string): void;
69
70 /**
71 * Check if category is already set in trace module.
72 * @param category The category to check.
73 */
74 export function isCategorySet(category: string): boolean;
75
76 /**
77 * Writes a message using the available writers.
78 * @param message The message to be written.
79 * @param category The category of the message.
80 * @param type Optional, the type of the message - info, warning, error.
81 */
82 export function write(message: any, category: string, type?: number): void;
83
84 /**
85 * Notifies all the attached listeners for an event that has occurred in the sender object.
86 * @param object The Object instance that raised the event.
87 * @param name The name of the raised event.
88 * @param data An optional parameter that passes the data associated with the event.
89 */
90 export function notifyEvent(object: Object, name: string, data?: any): void;
91
92 export function addEventListener(listener: TraceEventListener): void;
93
94 export function removeEventListener(listener: TraceEventListener): void;
95
96 export module messageType {
97 export const log = 0;
98 export const info = 1;
99 export const warn = 2;
100 export const error = 3;
101 }
102
103 /**
104 * all predefined categories.
105 */
106 export module categories {
107 export const VisualTreeEvents = 'VisualTreeEvents';
108 export const Layout = 'Layout';
109 export const Style = 'Style';
110 export const ViewHierarchy = 'ViewHierarchy';
111 export const NativeLifecycle = 'NativeLifecycle';
112 export const Debug = 'Debug';
113 export const Navigation = 'Navigation';
114 export const Test = 'Test';
115 export const Binding = 'Binding';
116 export const BindingError = 'BindingError';
117 export const Error = 'Error';
118 export const Animation = 'Animation';
119 export const Transition = 'Transition';
120 export const Livesync = 'Livesync';
121 export const ModuleNameResolver = 'ModuleNameResolver';
122
123 export const separator = ',';
124 export const All: string;
125
126 export function concat(...args: any): string;
127 }
128
129 class ConsoleWriter implements TraceWriter {
130 public write(message: any, category: string, type?: number): void;
131 }
132
133 export class DefaultErrorHandler implements TraceErrorHandler {
134 handlerError(error: any): void;
135 }
136
137 export function getErrorHandler(): TraceErrorHandler;
138
139 export function setErrorHandler(handler: TraceErrorHandler): void;
140
141 /**
142 * Passes an error to the registered ErrorHandler
143 * @param error The error to be handled.
144 */
145 export function error(error: string | Error): void;
146}