UNPKG

6.42 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { IReferenceable } from 'pip-services3-commons-node';
3import { IReferences } from 'pip-services3-commons-node';
4import { IReconfigurable } from 'pip-services3-commons-node';
5import { ILogger } from './ILogger';
6import { LogLevel } from './LogLevel';
7/**
8 * Abstract logger that captures and formats log messages.
9 * Child classes take the captured messages and write them to their specific destinations.
10 *
11 * ### Configuration parameters ###
12 *
13 * Parameters to pass to the [[configure]] method for component configuration:
14 *
15 * - level: maximum log level to capture
16 * - source: source (context) name
17 *
18 * ### References ###
19 *
20 * - <code>\*:context-info:\*:\*:1.0</code> (optional) [[ContextInfo]] to detect the context id and specify counters source
21 *
22 * @see [[ILogger]]
23 */
24export declare abstract class Logger implements ILogger, IReconfigurable, IReferenceable {
25 protected _level: LogLevel;
26 protected _source: string;
27 /**
28 * Creates a new instance of the logger.
29 */
30 protected constructor();
31 /**
32 * Configures component by passing configuration parameters.
33 *
34 * @param config configuration parameters to be set.
35 */
36 configure(config: ConfigParams): void;
37 /**
38 * Sets references to dependent components.
39 *
40 * @param references references to locate the component dependencies.
41 */
42 setReferences(references: IReferences): void;
43 /**
44 * Gets the maximum log level.
45 * Messages with higher log level are filtered out.
46 *
47 * @returns the maximum log level.
48 */
49 getLevel(): LogLevel;
50 /**
51 * Set the maximum log level.
52 *
53 * @param value a new maximum log level.
54 */
55 setLevel(value: LogLevel): void;
56 /**
57 * Gets the source (context) name.
58 *
59 * @returns the source (context) name.
60 */
61 getSource(): string;
62 /**
63 * Sets the source (context) name.
64 *
65 * @param value a new source (context) name.
66 */
67 setSource(value: string): void;
68 /**
69 * Writes a log message to the logger destination.
70 *
71 * @param level a log level.
72 * @param correlationId (optional) transaction id to trace execution through call chain.
73 * @param error an error object associated with this message.
74 * @param message a human-readable message to log.
75 */
76 protected abstract write(level: LogLevel, correlationId: string, error: Error, message: string): void;
77 /**
78 * Formats the log message and writes it to the logger destination.
79 *
80 * @param level a log level.
81 * @param correlationId (optional) transaction id to trace execution through call chain.
82 * @param error an error object associated with this message.
83 * @param message a human-readable message to log.
84 * @param args arguments to parameterize the message.
85 */
86 protected formatAndWrite(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void;
87 /**
88 * Logs a message at specified log level.
89 *
90 * @param level a log level.
91 * @param correlationId (optional) transaction id to trace execution through call chain.
92 * @param error an error object associated with this message.
93 * @param message a human-readable message to log.
94 * @param args arguments to parameterize the message.
95 */
96 log(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void;
97 /**
98 * Logs fatal (unrecoverable) message that caused the process to crash.
99 *
100 * @param correlationId (optional) transaction id to trace execution through call chain.
101 * @param error an error object associated with this message.
102 * @param message a human-readable message to log.
103 * @param args arguments to parameterize the message.
104 */
105 fatal(correlationId: string, error: Error, message: string, ...args: any[]): void;
106 /**
107 * Logs recoverable application error.
108 *
109 * @param correlationId (optional) transaction id to trace execution through call chain.
110 * @param error an error object associated with this message.
111 * @param message a human-readable message to log.
112 * @param args arguments to parameterize the message.
113 */
114 error(correlationId: string, error: Error, message: string, ...args: any[]): void;
115 /**
116 * Logs a warning that may or may not have a negative impact.
117 *
118 * @param correlationId (optional) transaction id to trace execution through call chain.
119 * @param message a human-readable message to log.
120 * @param args arguments to parameterize the message.
121 */
122 warn(correlationId: string, message: string, ...args: any[]): void;
123 /**
124 * Logs an important information message
125 *
126 * @param correlationId (optional) transaction id to trace execution through call chain.
127 * @param message a human-readable message to log.
128 * @param args arguments to parameterize the message.
129 */
130 info(correlationId: string, message: string, ...args: any[]): void;
131 /**
132 * Logs a high-level debug information for troubleshooting.
133 *
134 * @param correlationId (optional) transaction id to trace execution through call chain.
135 * @param message a human-readable message to log.
136 * @param args arguments to parameterize the message.
137 */
138 debug(correlationId: string, message: string, ...args: any[]): void;
139 /**
140 * Logs a low-level debug information for troubleshooting.
141 *
142 * @param correlationId (optional) transaction id to trace execution through call chain.
143 * @param message a human-readable message to log.
144 * @param args arguments to parameterize the message.
145 */
146 trace(correlationId: string, message: string, ...args: any[]): void;
147 /**
148 * Composes an human-readable error description
149 *
150 * @param error an error to format.
151 * @returns a human-reable error description.
152 */
153 protected composeError(error: Error): string;
154}