@pnp/logging
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -5,3 +5,5 @@ /** | ||
*/ | ||
export class ConsoleListener { | ||
var ConsoleListener = /** @class */ (function () { | ||
function ConsoleListener() { | ||
} | ||
/** | ||
@@ -12,4 +14,4 @@ * Any associated data that a given logging listener may choose to log or ignore | ||
*/ | ||
log(entry) { | ||
const msg = this.format(entry); | ||
ConsoleListener.prototype.log = function (entry) { | ||
var msg = this.format(entry); | ||
switch (entry.level) { | ||
@@ -27,3 +29,3 @@ case 0 /* Verbose */: | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -34,4 +36,4 @@ * Formats the message | ||
*/ | ||
format(entry) { | ||
const msg = []; | ||
ConsoleListener.prototype.format = function (entry) { | ||
var msg = []; | ||
msg.push("Message: " + entry.message); | ||
@@ -43,8 +45,10 @@ if (entry.data !== undefined) { | ||
catch (e) { | ||
msg.push(` Data: Error in stringify of supplied data ${e}`); | ||
msg.push(" Data: Error in stringify of supplied data " + e); | ||
} | ||
} | ||
return msg.join(""); | ||
} | ||
} | ||
}; | ||
return ConsoleListener; | ||
}()); | ||
export { ConsoleListener }; | ||
/** | ||
@@ -54,3 +58,3 @@ * Implementation of LogListener which logs to the supplied function | ||
*/ | ||
export class FunctionListener { | ||
var FunctionListener = /** @class */ (function () { | ||
/** | ||
@@ -62,3 +66,3 @@ * Creates a new instance of the FunctionListener class | ||
*/ | ||
constructor(method) { | ||
function FunctionListener(method) { | ||
this.method = method; | ||
@@ -71,6 +75,8 @@ } | ||
*/ | ||
log(entry) { | ||
FunctionListener.prototype.log = function (entry) { | ||
this.method(entry); | ||
} | ||
} | ||
}; | ||
return FunctionListener; | ||
}()); | ||
export { FunctionListener }; | ||
//# sourceMappingURL=listeners.js.map |
132
logger.js
@@ -5,18 +5,28 @@ /** | ||
*/ | ||
export class Logger { | ||
/** | ||
* Gets or sets the active log level to apply for log filtering | ||
*/ | ||
static get activeLogLevel() { | ||
return Logger.instance.activeLogLevel; | ||
var Logger = /** @class */ (function () { | ||
function Logger() { | ||
} | ||
static set activeLogLevel(value) { | ||
Logger.instance.activeLogLevel = value; | ||
} | ||
static get instance() { | ||
if (Logger._instance === undefined || Logger._instance === null) { | ||
Logger._instance = new LoggerImpl(); | ||
} | ||
return Logger._instance; | ||
} | ||
Object.defineProperty(Logger, "activeLogLevel", { | ||
/** | ||
* Gets or sets the active log level to apply for log filtering | ||
*/ | ||
get: function () { | ||
return Logger.instance.activeLogLevel; | ||
}, | ||
set: function (value) { | ||
Logger.instance.activeLogLevel = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Logger, "instance", { | ||
get: function () { | ||
if (Logger._instance === undefined || Logger._instance === null) { | ||
Logger._instance = new LoggerImpl(); | ||
} | ||
return Logger._instance; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
@@ -27,18 +37,26 @@ * Adds ILogListener instances to the set of subscribed listeners | ||
*/ | ||
static subscribe(...listeners) { | ||
listeners.forEach(listener => Logger.instance.subscribe(listener)); | ||
} | ||
Logger.subscribe = function () { | ||
var listeners = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
listeners[_i] = arguments[_i]; | ||
} | ||
listeners.forEach(function (listener) { return Logger.instance.subscribe(listener); }); | ||
}; | ||
/** | ||
* Clears the subscribers collection, returning the collection before modification | ||
*/ | ||
static clearSubscribers() { | ||
Logger.clearSubscribers = function () { | ||
return Logger.instance.clearSubscribers(); | ||
} | ||
}; | ||
Object.defineProperty(Logger, "count", { | ||
/** | ||
* Gets the current subscriber count | ||
*/ | ||
get: function () { | ||
return Logger.instance.count; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Gets the current subscriber count | ||
*/ | ||
static get count() { | ||
return Logger.instance.count; | ||
} | ||
/** | ||
* Writes the supplied string to the subscribed listeners | ||
@@ -49,5 +67,6 @@ * | ||
*/ | ||
static write(message, level = 1 /* Info */) { | ||
Logger.write = function (message, level) { | ||
if (level === void 0) { level = 1 /* Info */; } | ||
Logger.instance.log({ level: level, message: message }); | ||
} | ||
}; | ||
/** | ||
@@ -59,5 +78,6 @@ * Writes the supplied string to the subscribed listeners | ||
*/ | ||
static writeJSON(json, level = 1 /* Info */) { | ||
Logger.writeJSON = function (json, level) { | ||
if (level === void 0) { level = 1 /* Info */; } | ||
this.write(JSON.stringify(json), level); | ||
} | ||
}; | ||
/** | ||
@@ -68,5 +88,5 @@ * Logs the supplied entry to the subscribed listeners | ||
*/ | ||
static log(entry) { | ||
Logger.log = function (entry) { | ||
Logger.instance.log(entry); | ||
} | ||
}; | ||
/** | ||
@@ -77,31 +97,41 @@ * Logs an error object to the subscribed listeners | ||
*/ | ||
static error(err) { | ||
Logger.error = function (err) { | ||
Logger.instance.log({ data: err, level: 3 /* Error */, message: err.message }); | ||
} | ||
} | ||
class LoggerImpl { | ||
constructor(activeLogLevel = 2 /* Warning */, subscribers = []) { | ||
}; | ||
return Logger; | ||
}()); | ||
export { Logger }; | ||
var LoggerImpl = /** @class */ (function () { | ||
function LoggerImpl(activeLogLevel, subscribers) { | ||
if (activeLogLevel === void 0) { activeLogLevel = 2 /* Warning */; } | ||
if (subscribers === void 0) { subscribers = []; } | ||
this.activeLogLevel = activeLogLevel; | ||
this.subscribers = subscribers; | ||
} | ||
subscribe(listener) { | ||
LoggerImpl.prototype.subscribe = function (listener) { | ||
this.subscribers.push(listener); | ||
} | ||
clearSubscribers() { | ||
const s = this.subscribers.slice(0); | ||
}; | ||
LoggerImpl.prototype.clearSubscribers = function () { | ||
var s = this.subscribers.slice(0); | ||
this.subscribers.length = 0; | ||
return s; | ||
} | ||
get count() { | ||
return this.subscribers.length; | ||
} | ||
write(message, level = 1 /* Info */) { | ||
}; | ||
Object.defineProperty(LoggerImpl.prototype, "count", { | ||
get: function () { | ||
return this.subscribers.length; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
LoggerImpl.prototype.write = function (message, level) { | ||
if (level === void 0) { level = 1 /* Info */; } | ||
this.log({ level: level, message: message }); | ||
} | ||
log(entry) { | ||
}; | ||
LoggerImpl.prototype.log = function (entry) { | ||
if (entry !== undefined && this.activeLogLevel <= entry.level) { | ||
this.subscribers.map(subscriber => subscriber.log(entry)); | ||
this.subscribers.map(function (subscriber) { return subscriber.log(entry); }); | ||
} | ||
} | ||
} | ||
}; | ||
return LoggerImpl; | ||
}()); | ||
/** | ||
@@ -108,0 +138,0 @@ * A set of logging levels |
{ | ||
"name": "@pnp/logging", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "pnp - light-weight, subscribable logging framework", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19846
350