@pnp/logging
Advanced tools
Comparing version 2.9.0 to 3.0.0-v3nightly.20210902
export * from "./logger.js"; | ||
export * from "./listeners.js"; | ||
export * from "./behaviors/pnp-logging.js"; | ||
//# sourceMappingURL=index.d.ts.map |
export * from "./logger.js"; | ||
export * from "./listeners.js"; | ||
export * from "./behaviors/pnp-logging.js"; | ||
//# sourceMappingURL=index.js.map |
import { ILogEntry, ILogListener } from "./logger.js"; | ||
export declare function ConsoleListener(prefix?: string, colors?: IConsoleListenerColors): ILogListener; | ||
/** | ||
* Text color options for use in the ConsoleListener | ||
* All values can be specified as known names, hex values, rgb, or rgba values | ||
*/ | ||
export interface IConsoleListenerColors { | ||
/** Default text color for all logging levels unless they're specified */ | ||
color?: string; | ||
/** Text color to use for messages with LogLevel.Verbose */ | ||
verboseColor?: string; | ||
/** Text color to use for messages with LogLevel.Info */ | ||
infoColor?: string; | ||
/** Text color to use for messages with LogLevel.Warning */ | ||
warningColor?: string; | ||
/** Text color to use for messages with LogLevel.Error */ | ||
errorColor?: string; | ||
} | ||
/** | ||
* Implementation of LogListener which logs to the console | ||
* | ||
*/ | ||
export declare class ConsoleListener implements ILogListener { | ||
export declare class _ConsoleListener implements ILogListener { | ||
private _prefix; | ||
private _colors; | ||
/** | ||
* Makes a new one | ||
* | ||
* @param prefix Optional text to include at the start of all messages (useful for filtering) | ||
* @param colors Optional text color settings | ||
*/ | ||
constructor(_prefix?: string, _colors?: IConsoleListenerColors); | ||
/** | ||
* Any associated data that a given logging listener may choose to log or ignore | ||
@@ -20,2 +46,3 @@ * | ||
} | ||
export declare function FunctionListener(impl: (entry: ILogEntry) => void): ILogListener; | ||
/** | ||
@@ -25,3 +52,3 @@ * Implementation of LogListener which logs to the supplied function | ||
*/ | ||
export declare class FunctionListener implements ILogListener { | ||
export declare class _FunctionListener implements ILogListener { | ||
private method; | ||
@@ -28,0 +55,0 @@ /** |
@@ -0,1 +1,4 @@ | ||
export function ConsoleListener(prefix, colors) { | ||
return new _ConsoleListener(prefix, colors); | ||
} | ||
/** | ||
@@ -5,4 +8,14 @@ * Implementation of LogListener which logs to the console | ||
*/ | ||
var ConsoleListener = /** @class */ (function () { | ||
function ConsoleListener() { | ||
export class _ConsoleListener { | ||
_prefix; | ||
_colors; | ||
/** | ||
* Makes a new one | ||
* | ||
* @param prefix Optional text to include at the start of all messages (useful for filtering) | ||
* @param colors Optional text color settings | ||
*/ | ||
constructor(_prefix = "", _colors = {}) { | ||
this._prefix = _prefix; | ||
this._colors = _colors; | ||
} | ||
@@ -14,17 +27,39 @@ /** | ||
*/ | ||
ConsoleListener.prototype.log = function (entry) { | ||
var msg = this.format(entry); | ||
log(entry) { | ||
const msg = this.format(entry); | ||
switch (entry.level) { | ||
case 0 /* Verbose */: | ||
if (typeof this._colors.verboseColor !== "undefined") { | ||
console.log(`%c${msg}`, `color:${this._colors.verboseColor}`); | ||
} | ||
else { | ||
console.log(msg); | ||
} | ||
break; | ||
case 1 /* Info */: | ||
console.log(msg); | ||
if (typeof this._colors.infoColor !== "undefined") { | ||
console.log(`%c${msg}`, `color:${this._colors.infoColor}`); | ||
} | ||
else { | ||
console.log(msg); | ||
} | ||
break; | ||
case 2 /* Warning */: | ||
console.warn(msg); | ||
if (typeof this._colors.warningColor !== "undefined") { | ||
console.warn(`%c${msg}`, `color:${this._colors.warningColor}`); | ||
} | ||
else { | ||
console.warn(msg); | ||
} | ||
break; | ||
case 3 /* Error */: | ||
console.error(msg); | ||
if (typeof this._colors.errorColor !== "undefined") { | ||
console.error(`%c${msg}`, `color:${this._colors.errorColor}`); | ||
} | ||
else { | ||
console.error(msg); | ||
} | ||
break; | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -35,6 +70,9 @@ * Formats the message | ||
*/ | ||
ConsoleListener.prototype.format = function (entry) { | ||
var msg = []; | ||
msg.push("Message: " + entry.message); | ||
format(entry) { | ||
const msg = []; | ||
if (this._prefix.length > 0) { | ||
msg.push(`${this._prefix} - `); | ||
} | ||
if (entry.data !== undefined) { | ||
msg.push("Message: " + entry.message); | ||
try { | ||
@@ -44,10 +82,14 @@ msg.push(" Data: " + JSON.stringify(entry.data)); | ||
catch (e) { | ||
msg.push(" Data: Error in stringify of supplied data " + e); | ||
msg.push(` Data: Error in stringify of supplied data ${e}`); | ||
} | ||
} | ||
else { | ||
msg.push(entry.message); | ||
} | ||
return msg.join(""); | ||
}; | ||
return ConsoleListener; | ||
}()); | ||
export { ConsoleListener }; | ||
} | ||
} | ||
export function FunctionListener(impl) { | ||
return new _FunctionListener(impl); | ||
} | ||
/** | ||
@@ -57,3 +99,4 @@ * Implementation of LogListener which logs to the supplied function | ||
*/ | ||
var FunctionListener = /** @class */ (function () { | ||
export class _FunctionListener { | ||
method; | ||
/** | ||
@@ -65,3 +108,3 @@ * Creates a new instance of the FunctionListener class | ||
*/ | ||
function FunctionListener(method) { | ||
constructor(method) { | ||
this.method = method; | ||
@@ -74,8 +117,6 @@ } | ||
*/ | ||
FunctionListener.prototype.log = function (entry) { | ||
log(entry) { | ||
this.method(entry); | ||
}; | ||
return FunctionListener; | ||
}()); | ||
export { FunctionListener }; | ||
} | ||
} | ||
//# sourceMappingURL=listeners.js.map |
137
logger.js
@@ -5,28 +5,19 @@ /** | ||
*/ | ||
var Logger = /** @class */ (function () { | ||
function Logger() { | ||
export class Logger { | ||
static _instance; | ||
/** | ||
* Gets or sets the active log level to apply for log filtering | ||
*/ | ||
static get activeLogLevel() { | ||
return Logger.instance.activeLogLevel; | ||
} | ||
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 | ||
}); | ||
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; | ||
} | ||
/** | ||
@@ -37,26 +28,18 @@ * Adds ILogListener instances to the set of subscribed listeners | ||
*/ | ||
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); }); | ||
}; | ||
static subscribe(...listeners) { | ||
listeners.forEach(listener => Logger.instance.subscribe(listener)); | ||
} | ||
/** | ||
* Clears the subscribers collection, returning the collection before modification | ||
*/ | ||
Logger.clearSubscribers = function () { | ||
static clearSubscribers() { | ||
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 | ||
@@ -67,6 +50,5 @@ * | ||
*/ | ||
Logger.write = function (message, level) { | ||
if (level === void 0) { level = 1 /* Info */; } | ||
static write(message, level = 1 /* Info */) { | ||
Logger.instance.log({ level: level, message: message }); | ||
}; | ||
} | ||
/** | ||
@@ -78,6 +60,5 @@ * Writes the supplied string to the subscribed listeners | ||
*/ | ||
Logger.writeJSON = function (json, level) { | ||
if (level === void 0) { level = 1 /* Info */; } | ||
static writeJSON(json, level = 1 /* Info */) { | ||
this.write(JSON.stringify(json), level); | ||
}; | ||
} | ||
/** | ||
@@ -88,5 +69,5 @@ * Logs the supplied entry to the subscribed listeners | ||
*/ | ||
Logger.log = function (entry) { | ||
static log(entry) { | ||
Logger.instance.log(entry); | ||
}; | ||
} | ||
/** | ||
@@ -97,41 +78,33 @@ * Logs an error object to the subscribed listeners | ||
*/ | ||
Logger.error = function (err) { | ||
static error(err) { | ||
Logger.instance.log({ data: err, level: 3 /* Error */, message: err.message }); | ||
}; | ||
return Logger; | ||
}()); | ||
export { Logger }; | ||
var LoggerImpl = /** @class */ (function () { | ||
function LoggerImpl(activeLogLevel, subscribers) { | ||
if (activeLogLevel === void 0) { activeLogLevel = 2 /* Warning */; } | ||
if (subscribers === void 0) { subscribers = []; } | ||
} | ||
} | ||
class LoggerImpl { | ||
activeLogLevel; | ||
subscribers; | ||
constructor(activeLogLevel = 2 /* Warning */, subscribers = []) { | ||
this.activeLogLevel = activeLogLevel; | ||
this.subscribers = subscribers; | ||
} | ||
LoggerImpl.prototype.subscribe = function (listener) { | ||
subscribe(listener) { | ||
this.subscribers.push(listener); | ||
}; | ||
LoggerImpl.prototype.clearSubscribers = function () { | ||
var s = this.subscribers.slice(0); | ||
} | ||
clearSubscribers() { | ||
const s = this.subscribers.slice(0); | ||
this.subscribers.length = 0; | ||
return s; | ||
}; | ||
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 }); | ||
}; | ||
LoggerImpl.prototype.log = function (entry) { | ||
} | ||
get count() { | ||
return this.subscribers.length; | ||
} | ||
write(message, level = 1 /* Info */) { | ||
this.log({ level, message }); | ||
} | ||
log(entry) { | ||
if (entry !== undefined && this.activeLogLevel <= entry.level) { | ||
this.subscribers.map(function (subscriber) { return subscriber.log(entry); }); | ||
this.subscribers.map(subscriber => subscriber.log(entry)); | ||
} | ||
}; | ||
return LoggerImpl; | ||
}()); | ||
} | ||
} | ||
/** | ||
@@ -138,0 +111,0 @@ * A set of logging levels |
{ | ||
"name": "@pnp/logging", | ||
"version": "2.9.0", | ||
"description": "pnp - light-weight, subscribable logging framework", | ||
"main": "./index.js", | ||
"typings": "./index", | ||
"dependencies": { | ||
"tslib": "2.3.0" | ||
}, | ||
"author": { | ||
"name": "Microsoft and other contributors" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnp/pnpjs/issues" | ||
}, | ||
"homepage": "https://github.com/pnp/pnpjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git:github.com/pnp/pnpjs" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://github.com/sponsors/patrick-rodgers/" | ||
}, | ||
"type": "module" | ||
"name": "@pnp/logging", | ||
"version": "3.0.0-v3nightly.20210902", | ||
"description": "pnp - light-weight, subscribable logging framework", | ||
"main": "./index.js", | ||
"typings": "./index", | ||
"dependencies": { | ||
"tslib": "2.1.0" | ||
}, | ||
"author": { | ||
"name": "Microsoft and other contributors" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnp/pnpjs/issues" | ||
}, | ||
"homepage": "https://github.com/pnp/pnpjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git:github.com/pnp/pnpjs" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://github.com/sponsors/patrick-rodgers/" | ||
}, | ||
"type": "module" | ||
} |
@@ -11,3 +11,3 @@ ![SharePoint Patterns and Practices](https://devofficecdn.azureedge.net/media/Default/PnP/sppnp.png) | ||
This code is managed within the [main pnp repo](https://github.com/pnp/pnp), please report issues and submit pull requests there. | ||
This code is managed within the [main pnp repo](https://github.com/pnp/pnpjs), please report issues and submit pull requests there. | ||
@@ -14,0 +14,0 @@ Please see the public site for [package documentation](https://pnp.github.io/pnpjs/). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
23966
19
406
1
+ Addedtslib@2.1.0(transitive)
- Removedtslib@2.3.0(transitive)
Updatedtslib@2.1.0