@oino-ts/common 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,7 @@ var OINOLogLevel;
29
29
  class OINOLog {
30
30
  static _instance;
31
31
  _logLevels = { "||": OINOLogLevel.warning };
32
+ _defaultLogLevel = OINOLogLevel.warning;
32
33
  /**
33
34
  * Abstract logging method to implement the actual logging operation.
34
35
  *
@@ -38,6 +39,7 @@ class OINOLog {
38
39
  constructor(logLevel = OINOLogLevel.warning) {
39
40
  // console.log("OINOLog.constructor: logLevel=" + logLevel)
40
41
  this._logLevels["||"] = logLevel;
42
+ this._defaultLogLevel = logLevel;
41
43
  }
42
44
  /**
43
45
  * Abstract logging method to implement the actual logging operation.
@@ -159,6 +161,48 @@ class OINOLog {
159
161
  static debug(domain, channel, method, message, data) {
160
162
  OINOLog._log(OINOLogLevel.debug, "DEBUG", domain, channel, method, message, data);
161
163
  }
164
+ /**
165
+ * Get current log levels as an array of objects with domain, channel, method and level.
166
+ *
167
+ */
168
+ static exportLogLevels() {
169
+ let result = [];
170
+ if (OINOLog._instance) {
171
+ for (const key in OINOLog._instance._logLevels) {
172
+ const level = OINOLog._instance._logLevels[key];
173
+ if (level) {
174
+ const parts = key.split("|");
175
+ result.push({
176
+ domain: parts[0],
177
+ channel: parts[1],
178
+ method: parts[2],
179
+ level: level
180
+ });
181
+ }
182
+ }
183
+ }
184
+ return result;
185
+ }
186
+ /**
187
+ * Import log levels from an array of objects with domain, channel, method and level.
188
+ *
189
+ * @param logLevels array of log level objects
190
+ *
191
+ */
192
+ static importLogLevels(logLevels) {
193
+ if (OINOLog._instance) {
194
+ OINOLog._instance._logLevels = { "||": OINOLog._instance._defaultLogLevel }; // reset to default log level
195
+ for (const logLevel of logLevels) {
196
+ const domain = logLevel.domain || "";
197
+ const channel = logLevel.channel || "";
198
+ const method = logLevel.method || "";
199
+ const level = logLevel.level;
200
+ if (level && OINOLogLevel[level]) {
201
+ OINOLog._instance._logLevels[domain + "|" + channel + "|" + method] = level;
202
+ }
203
+ }
204
+ }
205
+ }
162
206
  }
163
207
  exports.OINOLog = OINOLog;
164
208
  /**
@@ -26,6 +26,7 @@ export var OINOLogLevel;
26
26
  export class OINOLog {
27
27
  static _instance;
28
28
  _logLevels = { "||": OINOLogLevel.warning };
29
+ _defaultLogLevel = OINOLogLevel.warning;
29
30
  /**
30
31
  * Abstract logging method to implement the actual logging operation.
31
32
  *
@@ -35,6 +36,7 @@ export class OINOLog {
35
36
  constructor(logLevel = OINOLogLevel.warning) {
36
37
  // console.log("OINOLog.constructor: logLevel=" + logLevel)
37
38
  this._logLevels["||"] = logLevel;
39
+ this._defaultLogLevel = logLevel;
38
40
  }
39
41
  /**
40
42
  * Abstract logging method to implement the actual logging operation.
@@ -156,6 +158,48 @@ export class OINOLog {
156
158
  static debug(domain, channel, method, message, data) {
157
159
  OINOLog._log(OINOLogLevel.debug, "DEBUG", domain, channel, method, message, data);
158
160
  }
161
+ /**
162
+ * Get current log levels as an array of objects with domain, channel, method and level.
163
+ *
164
+ */
165
+ static exportLogLevels() {
166
+ let result = [];
167
+ if (OINOLog._instance) {
168
+ for (const key in OINOLog._instance._logLevels) {
169
+ const level = OINOLog._instance._logLevels[key];
170
+ if (level) {
171
+ const parts = key.split("|");
172
+ result.push({
173
+ domain: parts[0],
174
+ channel: parts[1],
175
+ method: parts[2],
176
+ level: level
177
+ });
178
+ }
179
+ }
180
+ }
181
+ return result;
182
+ }
183
+ /**
184
+ * Import log levels from an array of objects with domain, channel, method and level.
185
+ *
186
+ * @param logLevels array of log level objects
187
+ *
188
+ */
189
+ static importLogLevels(logLevels) {
190
+ if (OINOLog._instance) {
191
+ OINOLog._instance._logLevels = { "||": OINOLog._instance._defaultLogLevel }; // reset to default log level
192
+ for (const logLevel of logLevels) {
193
+ const domain = logLevel.domain || "";
194
+ const channel = logLevel.channel || "";
195
+ const method = logLevel.method || "";
196
+ const level = logLevel.level;
197
+ if (level && OINOLogLevel[level]) {
198
+ OINOLog._instance._logLevels[domain + "|" + channel + "|" + method] = level;
199
+ }
200
+ }
201
+ }
202
+ }
159
203
  }
160
204
  /**
161
205
  * Logging implementation based on console.log.
@@ -20,6 +20,7 @@ export declare enum OINOLogLevel {
20
20
  export declare abstract class OINOLog {
21
21
  protected static _instance: OINOLog;
22
22
  protected _logLevels: Record<string, OINOLogLevel>;
23
+ protected _defaultLogLevel: OINOLogLevel;
23
24
  /**
24
25
  * Abstract logging method to implement the actual logging operation.
25
26
  *
@@ -127,6 +128,18 @@ export declare abstract class OINOLog {
127
128
  *
128
129
  */
129
130
  static debug(domain: string, channel: string, method: string, message: string, data?: any): void;
131
+ /**
132
+ * Get current log levels as an array of objects with domain, channel, method and level.
133
+ *
134
+ */
135
+ static exportLogLevels(): any[];
136
+ /**
137
+ * Import log levels from an array of objects with domain, channel, method and level.
138
+ *
139
+ * @param logLevels array of log level objects
140
+ *
141
+ */
142
+ static importLogLevels(logLevels: any[]): void;
130
143
  }
131
144
  /**
132
145
  * Logging implementation based on console.log.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/common",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "OINO TS package for common classes.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  },
21
21
  "devDependencies": {
22
- "@oino-ts/types": "0.8.1"
22
+ "@oino-ts/types": "0.8.2"
23
23
  },
24
24
  "files": [
25
25
  "src/*.ts",
package/src/OINOLog.ts CHANGED
@@ -29,6 +29,7 @@ export abstract class OINOLog {
29
29
  protected static _instance:OINOLog
30
30
 
31
31
  protected _logLevels:Record<string, OINOLogLevel> = { "||": OINOLogLevel.warning }
32
+ protected _defaultLogLevel:OINOLogLevel = OINOLogLevel.warning
32
33
 
33
34
  /**
34
35
  * Abstract logging method to implement the actual logging operation.
@@ -39,6 +40,7 @@ export abstract class OINOLog {
39
40
  constructor (logLevel:OINOLogLevel = OINOLogLevel.warning) {
40
41
  // console.log("OINOLog.constructor: logLevel=" + logLevel)
41
42
  this._logLevels["||"] = logLevel
43
+ this._defaultLogLevel = logLevel
42
44
  }
43
45
 
44
46
 
@@ -182,6 +184,51 @@ export abstract class OINOLog {
182
184
  static debug(domain:string, channel:string, method:string, message:string, data?:any) {
183
185
  OINOLog._log(OINOLogLevel.debug, "DEBUG", domain, channel, method, message, data)
184
186
  }
187
+
188
+ /**
189
+ * Get current log levels as an array of objects with domain, channel, method and level.
190
+ *
191
+ */
192
+ static exportLogLevels():any[] {
193
+ let result:any = []
194
+ if (OINOLog._instance) {
195
+ for (const key in OINOLog._instance._logLevels) {
196
+ const level = OINOLog._instance._logLevels[key]
197
+ if (level) {
198
+ const parts = key.split("|")
199
+ result.push({
200
+ domain: parts[0],
201
+ channel: parts[1],
202
+ method: parts[2],
203
+ level: level
204
+ })
205
+ }
206
+ }
207
+ }
208
+ return result
209
+ }
210
+
211
+
212
+ /**
213
+ * Import log levels from an array of objects with domain, channel, method and level.
214
+ *
215
+ * @param logLevels array of log level objects
216
+ *
217
+ */
218
+ static importLogLevels(logLevels:any[]):void {
219
+ if (OINOLog._instance) {
220
+ OINOLog._instance._logLevels = {"||": OINOLog._instance._defaultLogLevel} // reset to default log level
221
+ for (const logLevel of logLevels) {
222
+ const domain = logLevel.domain || ""
223
+ const channel = logLevel.channel || ""
224
+ const method = logLevel.method || ""
225
+ const level = logLevel.level
226
+ if (level && OINOLogLevel[level]) {
227
+ OINOLog._instance._logLevels[domain + "|" + channel + "|" + method] = level
228
+ }
229
+ }
230
+ }
231
+ }
185
232
  }
186
233
 
187
234
  /**