@pnp/logging
Advanced tools
Comparing version 2.0.0-1 to 2.0.0-2
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./src/logging"), exports); | ||
export * from "./src/logging"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnp/logging", | ||
"version": "2.0.0-1", | ||
"version": "2.0.0-2", | ||
"description": "pnp - light-weight, subscribable logging framework", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -7,3 +5,5 @@ * Implementation of LogListener which logs to the console | ||
*/ | ||
class ConsoleListener { | ||
var ConsoleListener = /** @class */ (function () { | ||
function ConsoleListener() { | ||
} | ||
/** | ||
@@ -14,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) { | ||
@@ -29,3 +29,3 @@ case 0 /* Verbose */: | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -36,4 +36,4 @@ * Formats the message | ||
*/ | ||
format(entry) { | ||
const msg = []; | ||
ConsoleListener.prototype.format = function (entry) { | ||
var msg = []; | ||
msg.push("Message: " + entry.message); | ||
@@ -45,9 +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(""); | ||
} | ||
} | ||
exports.ConsoleListener = ConsoleListener; | ||
}; | ||
return ConsoleListener; | ||
}()); | ||
export { ConsoleListener }; | ||
/** | ||
@@ -57,3 +58,3 @@ * Implementation of LogListener which logs to the supplied function | ||
*/ | ||
class FunctionListener { | ||
var FunctionListener = /** @class */ (function () { | ||
/** | ||
@@ -65,3 +66,3 @@ * Creates a new instance of the FunctionListener class | ||
*/ | ||
constructor(method) { | ||
function FunctionListener(method) { | ||
this.method = method; | ||
@@ -74,7 +75,8 @@ } | ||
*/ | ||
log(entry) { | ||
FunctionListener.prototype.log = function (entry) { | ||
this.method(entry); | ||
} | ||
} | ||
exports.FunctionListener = FunctionListener; | ||
}; | ||
return FunctionListener; | ||
}()); | ||
export { FunctionListener }; | ||
//# sourceMappingURL=listeners.js.map |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -7,18 +5,28 @@ * Class used to subscribe ILogListener and log messages throughout an application | ||
*/ | ||
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: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Logger, "instance", { | ||
get: function () { | ||
if (Logger._instance === undefined || Logger._instance === null) { | ||
Logger._instance = new LoggerImpl(); | ||
} | ||
return Logger._instance; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
@@ -29,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 modifiction | ||
*/ | ||
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: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Gets the current subscriber count | ||
*/ | ||
static get count() { | ||
return Logger.instance.count; | ||
} | ||
/** | ||
* Writes the supplied string to the subscribed listeners | ||
@@ -51,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 }); | ||
} | ||
}; | ||
/** | ||
@@ -61,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); | ||
} | ||
}; | ||
/** | ||
@@ -70,5 +88,5 @@ * Logs the supplied entry to the subscribed listeners | ||
*/ | ||
static log(entry) { | ||
Logger.log = function (entry) { | ||
Logger.instance.log(entry); | ||
} | ||
}; | ||
/** | ||
@@ -79,32 +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 }); | ||
} | ||
} | ||
exports.Logger = Logger; | ||
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: true, | ||
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; | ||
}()); | ||
//# sourceMappingURL=logger.js.map |
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
var logger_1 = require("./logger"); | ||
exports.Logger = logger_1.Logger; | ||
var listeners_1 = require("./listeners"); | ||
exports.ConsoleListener = listeners_1.ConsoleListener; | ||
exports.FunctionListener = listeners_1.FunctionListener; | ||
tslib_1.__exportStar(require("./types"), exports); | ||
export { Logger } from "./logger"; | ||
export { ConsoleListener, FunctionListener } from "./listeners"; | ||
export * from "./types"; | ||
//# sourceMappingURL=logging.js.map |
@@ -1,7 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* A set of logging levels | ||
*/ | ||
var LogLevel; | ||
export var LogLevel; | ||
(function (LogLevel) { | ||
@@ -13,3 +11,3 @@ LogLevel[LogLevel["Verbose"] = 0] = "Verbose"; | ||
LogLevel[LogLevel["Off"] = 99] = "Off"; | ||
})(LogLevel = exports.LogLevel || (exports.LogLevel = {})); | ||
})(LogLevel || (LogLevel = {})); | ||
//# sourceMappingURL=types.js.map |
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
14486
354