UNPKG

3.67 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { IReconfigurable } from 'pip-services3-commons-node';
3/**
4 * Context information component that provides detail information
5 * about execution context: container or/and process.
6 *
7 * Most often ContextInfo is used by logging and performance counters
8 * to identify source of the collected logs and metrics.
9 *
10 * ### Configuration parameters ###
11 *
12 * - name: the context (container or process) name
13 * - description: human-readable description of the context
14 * - properties: entire section of additional descriptive properties
15 * - ...
16 *
17 * ### Example ###
18 *
19 * let contextInfo = new ContextInfo();
20 * contextInfo.configure(ConfigParams.fromTuples(
21 * "name", "MyMicroservice",
22 * "description", "My first microservice"
23 * ));
24 *
25 * context.name; // Result: "MyMicroservice"
26 * context.contextId; // Possible result: "mylaptop"
27 * context.startTime; // Possible result: 2018-01-01:22:12:23.45Z
28 * context.uptime; // Possible result: 3454345
29 */
30export declare class ContextInfo implements IReconfigurable {
31 private _name;
32 private _description;
33 private _contextId;
34 private _startTime;
35 private _properties;
36 /**
37 * Creates a new instance of this context info.
38 *
39 * @param name (optional) a context name.
40 * @param description (optional) a human-readable description of the context.
41 */
42 constructor(name?: string, description?: string);
43 /**
44 * Configures component by passing configuration parameters.
45 *
46 * @param config configuration parameters to be set.
47 */
48 configure(config: ConfigParams): void;
49 /**
50 * Gets the context name.
51 *
52 * @returns the context name
53 */
54 get name(): string;
55 /**
56 * Sets the context name.
57 *
58 * @param value a new name for the context.
59 */
60 set name(value: string);
61 /**
62 * Gets the human-readable description of the context.
63 *
64 * @returns the human-readable description of the context.
65 */
66 get description(): string;
67 /**
68 * Sets the human-readable description of the context.
69 *
70 * @param value a new human readable description of the context.
71 */
72 set description(value: string);
73 /**
74 * Gets the unique context id.
75 * Usually it is the current host name.
76 *
77 * @returns the unique context id.
78 */
79 get contextId(): string;
80 /**
81 * Sets the unique context id.
82 *
83 * @param value a new unique context id.
84 */
85 set contextId(value: string);
86 /**
87 * Gets the context start time.
88 *
89 * @returns the context start time.
90 */
91 get startTime(): Date;
92 /**
93 * Sets the context start time.
94 *
95 * @param value a new context start time.
96 */
97 set startTime(value: Date);
98 /**
99 * Calculates the context uptime as from the start time.
100 *
101 * @returns number of milliseconds from the context start time.
102 */
103 get uptime(): number;
104 /**
105 * Gets context additional parameters.
106 *
107 * @returns a JSON object with additional context parameters.
108 */
109 get properties(): any;
110 /**
111 * Sets context additional parameters.
112 *
113 * @param properties a JSON object with context additional parameters
114 */
115 set properties(properties: any);
116 /**
117 * Creates a new ContextInfo and sets its configuration parameters.
118 *
119 * @param config configuration parameters for the new ContextInfo.
120 * @returns a newly created ContextInfo
121 */
122 static fromConfig(config: ConfigParams): ContextInfo;
123}