@dzeio/logger
Advanced tools
Comparing version
@@ -9,2 +9,8 @@ # Changelog | ||
## [3.1.0] - 2023-06-28 | ||
### Added | ||
- Support for ESM | ||
## [2.0.4] - 2021-02-08 | ||
@@ -11,0 +17,0 @@ |
@@ -1,4 +0,7 @@ | ||
/// <reference types="node" /> | ||
import { theme } from '../typing/types'; | ||
export default class Logger implements Console { | ||
/** | ||
* The possible themes | ||
*/ | ||
type theme = undefined | 'light' | 'dark' | ||
declare class Logger implements Console { | ||
prefix: string; | ||
@@ -32,3 +35,3 @@ /** | ||
*/ | ||
Console: console.ConsoleConstructor; | ||
Console: any; | ||
/** | ||
@@ -237,2 +240,4 @@ * The messages queue | ||
*/ | ||
export declare const logger: Logger; | ||
declare const logger: Logger; | ||
export { Logger as default, logger }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/Logger.ts | ||
var Logger_exports = {}; | ||
__export(Logger_exports, { | ||
default: () => Logger, | ||
logger: () => logger | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.logger = void 0; | ||
const ansi_colors_1 = __importStar(require("ansi-colors")); | ||
class Logger { | ||
module.exports = __toCommonJS(Logger_exports); | ||
var import_ansi_colors = __toESM(require("ansi-colors")); | ||
var _Logger = class _Logger { | ||
/** | ||
* Construct a new Logger | ||
* @param prefix the prefix shown | ||
*/ | ||
constructor(prefix = "Logger") { | ||
this.prefix = prefix; | ||
// NodeJS console (will be undefined on ) | ||
/** | ||
* Construct a new Logger | ||
* @param prefix the prefix shown | ||
* NODEJS ONLY | ||
* It will be undefined in Browser context | ||
*/ | ||
constructor(prefix = 'Logger') { | ||
this.prefix = prefix; | ||
// NodeJS console (will be undefined on ) | ||
/** | ||
* NODEJS ONLY | ||
* It will be undefined in Browser context | ||
*/ | ||
// @ts-ignore | ||
this.Console = console.Console; | ||
/** | ||
* The messages queue | ||
*/ | ||
this.queue = []; | ||
/** | ||
* If true message won't be shown to console | ||
* (`urgent` message will still show) | ||
*/ | ||
this.blocked = false; | ||
/** | ||
* `count` function object value | ||
*/ | ||
this.countCount = {}; | ||
/** | ||
* `time` function object value | ||
*/ | ||
this.timeCount = {}; | ||
Logger.loggers.push(this); | ||
// If Firefox disable colors | ||
// @ts-ignore | ||
if (typeof InstallTrigger !== 'undefined') { | ||
ansi_colors_1.default.enabled = false; | ||
} | ||
} | ||
// @ts-ignore | ||
this.Console = console.Console; | ||
/** | ||
* STATIC FUNCTIONS | ||
* The messages queue | ||
*/ | ||
this.queue = []; | ||
/** | ||
* Choose if every loggers should be blocked or not | ||
* @param value | ||
* If true message won't be shown to console | ||
* (`urgent` message will still show) | ||
*/ | ||
static isBlocked(value) { | ||
for (const lgr of this.loggers) { | ||
lgr.blocked = value; | ||
if (!value) { | ||
lgr.processQueue(); | ||
} | ||
} | ||
} | ||
this.blocked = false; | ||
/** | ||
* Force a specific theme to be used | ||
* | ||
* (if undefined it will try to detect it) | ||
* | ||
* @param themeChosen The theme chosen to be overriden | ||
* `count` function object value | ||
*/ | ||
static forceTheme(themeChosen) { | ||
this.theme = themeChosen; | ||
} | ||
this.countCount = {}; | ||
/** | ||
* INSTANCE FUNCTIONS | ||
* `time` function object value | ||
*/ | ||
/** | ||
* return nothing if `condition` is `true`, log `data` if it is not | ||
* @param condition The value tested for being truthy | ||
* @param data The message to pass if `condition` is false | ||
*/ | ||
assert(condition, ...data) { | ||
if (!condition) { | ||
return this.error('Assertion failed:', ...data); | ||
} | ||
this.timeCount = {}; | ||
_Logger.loggers.push(this); | ||
if (typeof InstallTrigger !== "undefined") { | ||
import_ansi_colors.default.enabled = false; | ||
} | ||
/** | ||
* Clear the console/terminal | ||
*/ | ||
clear() { | ||
console.clear(); | ||
} | ||
/** | ||
* STATIC FUNCTIONS | ||
*/ | ||
/** | ||
* Choose if every loggers should be blocked or not | ||
* @param value | ||
*/ | ||
static isBlocked(value) { | ||
for (const lgr of this.loggers) { | ||
lgr.blocked = value; | ||
if (!value) { | ||
lgr.processQueue(); | ||
} | ||
} | ||
/** | ||
* log the number of times `count` has been called | ||
* @param label Display label, default to `default` | ||
*/ | ||
count(label = 'default') { | ||
if (!Object.prototype.hasOwnProperty.call(this.countCount, label)) { | ||
this.countCount[label] = 0; | ||
} | ||
this.log(`${label}:`, ++this.countCount[label]); | ||
} | ||
/** | ||
* Force a specific theme to be used | ||
* | ||
* (if undefined it will try to detect it) | ||
* | ||
* @param themeChosen The theme chosen to be overriden | ||
*/ | ||
static forceTheme(themeChosen) { | ||
this.theme = themeChosen; | ||
} | ||
/** | ||
* INSTANCE FUNCTIONS | ||
*/ | ||
/** | ||
* return nothing if `condition` is `true`, log `data` if it is not | ||
* @param condition The value tested for being truthy | ||
* @param data The message to pass if `condition` is false | ||
*/ | ||
assert(condition, ...data) { | ||
if (!condition) { | ||
return this.error("Assertion failed:", ...data); | ||
} | ||
/** | ||
* Reset the count started with `count` function | ||
* @param label Display label, default to `default` | ||
*/ | ||
countReset(label = 'default') { | ||
delete this.countCount[label]; | ||
} | ||
/** | ||
* Clear the console/terminal | ||
*/ | ||
clear() { | ||
console.clear(); | ||
} | ||
/** | ||
* log the number of times `count` has been called | ||
* @param label Display label, default to `default` | ||
*/ | ||
count(label = "default") { | ||
if (!Object.prototype.hasOwnProperty.call(this.countCount, label)) { | ||
this.countCount[label] = 0; | ||
} | ||
/** | ||
* log as debug the `data` | ||
* (On browser like Chrome in the devtool you have to enable it beforehand) | ||
* @param data the data to log | ||
*/ | ||
debug(...data) { | ||
this.process('debug', data); | ||
this.log(`${label}:`, ++this.countCount[label]); | ||
} | ||
/** | ||
* Reset the count started with `count` function | ||
* @param label Display label, default to `default` | ||
*/ | ||
countReset(label = "default") { | ||
delete this.countCount[label]; | ||
} | ||
/** | ||
* log as debug the `data` | ||
* (On browser like Chrome in the devtool you have to enable it beforehand) | ||
* @param data the data to log | ||
*/ | ||
debug(...data) { | ||
this.process("debug", data); | ||
} | ||
/** | ||
* NOTE: Method not fully implemented | ||
* | ||
* print a full object to the logger | ||
* @param item Object to log | ||
* @param options (NodeJS only) option for the display | ||
*/ | ||
dir(item, options) { | ||
if (typeof item !== "object") { | ||
return this.log(item); | ||
} | ||
/** | ||
* NOTE: Method not fully implemented | ||
* | ||
* print a full object to the logger | ||
* @param item Object to log | ||
* @param options (NodeJS only) option for the display | ||
*/ | ||
dir(item, options) { | ||
if (typeof item !== 'object') { | ||
return this.log(item); | ||
} | ||
this.log('Method not fully implemented'); | ||
if (typeof window !== 'undefined') { | ||
console.dir(item); | ||
return; | ||
} | ||
console.dir(item, options); | ||
this.log("Method not fully implemented"); | ||
if (typeof window !== "undefined") { | ||
console.dir(item); | ||
return; | ||
} | ||
/** | ||
* Alias for `log` function | ||
* @param data data to log | ||
*/ | ||
dirxml(...data) { | ||
this.process('dirxml', data); | ||
console.dir(item, options); | ||
} | ||
/** | ||
* Alias for `log` function | ||
* @param data data to log | ||
*/ | ||
dirxml(...data) { | ||
this.process("dirxml", data); | ||
} | ||
/** | ||
* print to stderr on NodeJS, print with red coloring on browsers | ||
* @param data data to log | ||
*/ | ||
error(...data) { | ||
this.process("error", data); | ||
} | ||
/** | ||
* Alias to `error` function | ||
* @param data data to log | ||
*/ | ||
exception(...data) { | ||
this.error(...data); | ||
} | ||
/** | ||
* NodeJS -> Increase the indentation of future logs with `label` as header | ||
* | ||
* Browser -> Group futures logs | ||
* @param label labels to use as header | ||
*/ | ||
group(...label) { | ||
console.group(...label); | ||
} | ||
/** | ||
* Alias of `group` function | ||
* @param label label to use as header | ||
*/ | ||
groupCollapsed(...label) { | ||
this.group(...label); | ||
} | ||
/** | ||
* End the current group started with the `group` function | ||
*/ | ||
groupEnd() { | ||
console.groupEnd(); | ||
} | ||
/** | ||
* Log to console as Info | ||
* (Only Chrome else it is an alias of `log`) | ||
* @param data data to log | ||
*/ | ||
info(...data) { | ||
this.process("info", data); | ||
} | ||
/** | ||
* Log to console | ||
* @param data data to log | ||
*/ | ||
log(...data) { | ||
this.process("log", data); | ||
} | ||
/** | ||
* make a new profile in browsers or in NodeJS with `--inspect` flag | ||
* @param name Profile name | ||
*/ | ||
profile(name) { | ||
if (console.profile) { | ||
console.profile(name); | ||
} else { | ||
throw new Error("profile don't exist in the current contexte"); | ||
} | ||
/** | ||
* print to stderr on NodeJS, print with red coloring on browsers | ||
* @param data data to log | ||
*/ | ||
error(...data) { | ||
this.process('error', data); | ||
} | ||
/** | ||
* end the current running profile | ||
* @param name Profile name | ||
*/ | ||
profileEnd(name) { | ||
console.profileEnd(name); | ||
} | ||
/** | ||
* Print a Table to the console | ||
* @param tabularData Table data | ||
* @param properties Table properties | ||
*/ | ||
table(tabularData, properties) { | ||
console.table(tabularData, properties); | ||
} | ||
/** | ||
* Start a timer | ||
* @param label Timer label | ||
*/ | ||
time(label = "default") { | ||
if (!Object.prototype.hasOwnProperty.call(this.timeCount, label)) { | ||
this.timeCount[label] = /* @__PURE__ */ new Date(); | ||
return; | ||
} | ||
/** | ||
* Alias to `error` function | ||
* @param data data to log | ||
*/ | ||
exception(...data) { | ||
this.error(...data); | ||
this.warn(`Timer '${label}' already exists.`); | ||
} | ||
/** | ||
* End a timer | ||
* @param label Timer label | ||
*/ | ||
timeEnd(label = "default") { | ||
const diff = (/* @__PURE__ */ new Date()).getTime() - this.timeCount[label].getTime(); | ||
this.log(`${label}: ${diff}ms - Timer ended`); | ||
delete this.timeCount[label]; | ||
} | ||
/** | ||
* Log to the console with timer before it | ||
* @param label Timer label | ||
* @param data data to log next to the timer | ||
*/ | ||
timeLog(label = "default", ...data) { | ||
if (!this.timeCount[label]) { | ||
this.warn(`Timer '${label}' does not exist`); | ||
return; | ||
} | ||
/** | ||
* NodeJS -> Increase the indentation of future logs with `label` as header | ||
* | ||
* Browser -> Group futures logs | ||
* @param label labels to use as header | ||
*/ | ||
group(...label) { | ||
console.group(...label); | ||
const diff = (/* @__PURE__ */ new Date()).getTime() - this.timeCount[label].getTime(); | ||
this.log(`${label}: ${diff}ms`, ...data); | ||
} | ||
/** | ||
* Browsers only, Add maker in the browser's Performance or Waterfall tool | ||
* @param label Label to use | ||
*/ | ||
timeStamp(label) { | ||
console.timeStamp(label); | ||
} | ||
/** | ||
* Print a stack trace to console | ||
* @param data data to trace | ||
*/ | ||
trace(...data) { | ||
this.process("trace", data); | ||
} | ||
/** | ||
* Warn in the console | ||
* (in NodeJS context it is an alias to the `error` function) | ||
* @param data data to log | ||
*/ | ||
warn(...data) { | ||
this.process("warn", data); | ||
} | ||
/** | ||
* Log to the console but skiping `isBlocked` check | ||
* @param data data to log | ||
*/ | ||
urgent(...data) { | ||
console.log(...this.formatMessage(data)); | ||
} | ||
/** | ||
* Precoess a message sent by one of the public functions | ||
* @param type logType | ||
* @param message message to log | ||
*/ | ||
process(type, message) { | ||
this.queue.push({ type, msg: this.formatMessage(message) }); | ||
this.processQueue(); | ||
} | ||
/** | ||
* Format a message for the console | ||
* @param message message to format | ||
*/ | ||
formatMessage(message) { | ||
const prefix = this.prefix; | ||
const prefixLen = prefix.length; | ||
if (_Logger.prefixLen < prefixLen) { | ||
_Logger.prefixLen = prefixLen; | ||
} | ||
/** | ||
* Alias of `group` function | ||
* @param label label to use as header | ||
*/ | ||
groupCollapsed(...label) { | ||
this.group(...label); | ||
const spacers = ["", ""]; | ||
if (_Logger.prefixLen > prefixLen) { | ||
const diff = _Logger.prefixLen - prefixLen; | ||
const diff2 = diff / 2; | ||
spacers[0] = this.buildSpace(diff2 - (diff % 2 !== 0 ? 1 : 0)); | ||
spacers[1] = this.buildSpace(diff2); | ||
} | ||
/** | ||
* End the current group started with the `group` function | ||
*/ | ||
groupEnd() { | ||
console.groupEnd(); | ||
const res = [ | ||
`${this.blackOrWhite("[ ")}${spacers[0]}${(0, import_ansi_colors.blue)(prefix)}${spacers[1]}${this.blackOrWhite(" ]")}:` | ||
]; | ||
if (_Logger.timestamp) { | ||
const now = /* @__PURE__ */ new Date(); | ||
const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}`; | ||
const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}`; | ||
const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}`; | ||
res.unshift(`${this.blackOrWhite("<")}${(0, import_ansi_colors.yellow)(h)}:${(0, import_ansi_colors.yellow)(m)}:${(0, import_ansi_colors.yellow)(s)}${this.blackOrWhite(">")}`); | ||
} | ||
/** | ||
* Log to console as Info | ||
* (Only Chrome else it is an alias of `log`) | ||
* @param data data to log | ||
*/ | ||
info(...data) { | ||
this.process('info', data); | ||
} | ||
/** | ||
* Log to console | ||
* @param data data to log | ||
*/ | ||
log(...data) { | ||
this.process('log', data); | ||
} | ||
/** | ||
* make a new profile in browsers or in NodeJS with `--inspect` flag | ||
* @param name Profile name | ||
*/ | ||
profile(name) { | ||
// @ts-ignore | ||
if (console.profile) { | ||
// @ts-ignore | ||
console.profile(name); | ||
return res.concat( | ||
message.map((el) => { | ||
if (typeof el === "object") { | ||
return el; | ||
} | ||
else { | ||
throw new Error('profile don\'t exist in the current contexte'); | ||
if (el === void 0) { | ||
return (0, import_ansi_colors.yellow)("undefined"); | ||
} | ||
} | ||
/** | ||
* end the current running profile | ||
* @param name Profile name | ||
*/ | ||
profileEnd(name) { | ||
// @ts-ignore | ||
console.profileEnd(name); | ||
} | ||
/** | ||
* Print a Table to the console | ||
* @param tabularData Table data | ||
* @param properties Table properties | ||
*/ | ||
table(tabularData, properties) { | ||
console.table(tabularData, properties); | ||
} | ||
/** | ||
* Start a timer | ||
* @param label Timer label | ||
*/ | ||
time(label = 'default') { | ||
if (!Object.prototype.hasOwnProperty.call(this.timeCount, label)) { | ||
this.timeCount[label] = new Date(); | ||
return; | ||
if (el === null) { | ||
return (0, import_ansi_colors.yellow)("null"); | ||
} | ||
this.warn(`Timer '${label}' already exists.`); | ||
return typeof el !== "string" ? (0, import_ansi_colors.yellow)(el.toString()) : (0, import_ansi_colors.green)(el); | ||
}) | ||
); | ||
} | ||
/** | ||
* Process Waiting queue | ||
*/ | ||
processQueue() { | ||
while (this.queue.length > 0 && !this.blocked) { | ||
const item = this.queue.shift(); | ||
if (!item) { | ||
continue; | ||
} | ||
if (item.type === "trace") { | ||
console.log(item.msg.shift()); | ||
} | ||
console[item.type](...item.msg); | ||
} | ||
/** | ||
* End a timer | ||
* @param label Timer label | ||
*/ | ||
timeEnd(label = 'default') { | ||
const diff = (new Date()).getTime() - this.timeCount[label].getTime(); | ||
this.log(`${label}: ${diff}ms - Timer ended`); | ||
delete this.timeCount[label]; | ||
} | ||
/** | ||
* Build a new string of `count` spaces | ||
* @param count number of spaces to add | ||
*/ | ||
buildSpace(count) { | ||
return "".padStart(count, " "); | ||
} | ||
/** | ||
* Color the text in black or white depending on `theme` variable or detection | ||
* @param text the text to color | ||
*/ | ||
blackOrWhite(text) { | ||
if (!_Logger.theme && typeof window !== "undefined" || _Logger.theme === "light") { | ||
return (0, import_ansi_colors.black)(text); | ||
} | ||
/** | ||
* Log to the console with timer before it | ||
* @param label Timer label | ||
* @param data data to log next to the timer | ||
*/ | ||
timeLog(label = 'default', ...data) { | ||
if (!this.timeCount[label]) { | ||
this.warn(`Timer '${label}' does not exist`); | ||
return; | ||
} | ||
const diff = (new Date()).getTime() - this.timeCount[label].getTime(); | ||
this.log(`${label}: ${diff}ms`, ...data); | ||
} | ||
/** | ||
* Browsers only, Add maker in the browser's Performance or Waterfall tool | ||
* @param label Label to use | ||
*/ | ||
timeStamp(label) { | ||
console.timeStamp(label); | ||
} | ||
/** | ||
* Print a stack trace to console | ||
* @param data data to trace | ||
*/ | ||
trace(...data) { | ||
this.process('trace', data); | ||
} | ||
/** | ||
* Warn in the console | ||
* (in NodeJS context it is an alias to the `error` function) | ||
* @param data data to log | ||
*/ | ||
warn(...data) { | ||
this.process('warn', data); | ||
} | ||
/** | ||
* Log to the console but skiping `isBlocked` check | ||
* @param data data to log | ||
*/ | ||
urgent(...data) { | ||
console.log(...this.formatMessage(data)); | ||
} | ||
/** | ||
* Precoess a message sent by one of the public functions | ||
* @param type logType | ||
* @param message message to log | ||
*/ | ||
process(type, message) { | ||
this.queue.push({ type, msg: this.formatMessage(message) }); | ||
this.processQueue(); | ||
} | ||
/** | ||
* Format a message for the console | ||
* @param message message to format | ||
*/ | ||
formatMessage(message) { | ||
const prefix = this.prefix; | ||
const prefixLen = prefix.length; | ||
if (Logger.prefixLen < prefixLen) { | ||
Logger.prefixLen = prefixLen; | ||
} | ||
const spacers = ['', '']; | ||
if (Logger.prefixLen > prefixLen) { | ||
const diff = Logger.prefixLen - prefixLen; | ||
const diff2 = diff / 2; | ||
spacers[0] = this.buildSpace(diff2 - (diff % 2 !== 0 ? 1 : 0)); | ||
spacers[1] = this.buildSpace(diff2); | ||
} | ||
const res = [ | ||
`${this.blackOrWhite('[ ')}${spacers[0]}${(0, ansi_colors_1.blue)(prefix)}${spacers[1]}${this.blackOrWhite(' ]')}:` | ||
]; | ||
if (Logger.timestamp) { | ||
const now = new Date(); | ||
const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}`; | ||
const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}`; | ||
const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}`; | ||
res.unshift(`${this.blackOrWhite('<')}${(0, ansi_colors_1.yellow)(h)}:${(0, ansi_colors_1.yellow)(m)}:${(0, ansi_colors_1.yellow)(s)}${this.blackOrWhite('>')}`); | ||
} | ||
return res.concat(message.map((el) => { | ||
if (typeof el === 'object') { | ||
return el; | ||
} | ||
if (el === undefined) { | ||
return (0, ansi_colors_1.yellow)('undefined'); | ||
} | ||
if (el === null) { | ||
return (0, ansi_colors_1.yellow)('null'); | ||
} | ||
return typeof el !== 'string' ? (0, ansi_colors_1.yellow)(el.toString()) : (0, ansi_colors_1.green)(el); | ||
})); | ||
} | ||
/** | ||
* Process Waiting queue | ||
*/ | ||
processQueue() { | ||
while (this.queue.length > 0 && !this.blocked) { | ||
const item = this.queue.shift(); | ||
if (!item) { | ||
continue; | ||
} | ||
if (item.type === 'trace') { | ||
console.log(item.msg.shift()); | ||
} | ||
console[item.type](...item.msg); | ||
} | ||
} | ||
/** | ||
* Build a new string of `count` spaces | ||
* @param count number of spaces to add | ||
*/ | ||
buildSpace(count) { | ||
return ''.padStart(count, ' '); | ||
} | ||
/** | ||
* Color the text in black or white depending on `theme` variable or detection | ||
* @param text the text to color | ||
*/ | ||
blackOrWhite(text) { | ||
if ((!Logger.theme && typeof window !== 'undefined') || Logger.theme === 'light') { | ||
return (0, ansi_colors_1.black)(text); | ||
} | ||
return (0, ansi_colors_1.white)(text); | ||
} | ||
} | ||
exports.default = Logger; | ||
return (0, import_ansi_colors.white)(text); | ||
} | ||
}; | ||
/** | ||
* The maximun prefix length | ||
*/ | ||
Logger.prefixLen = 0; | ||
_Logger.prefixLen = 0; | ||
/** | ||
@@ -393,7 +402,7 @@ * Current theme in use | ||
*/ | ||
Logger.theme = undefined; | ||
_Logger.theme = void 0; | ||
/** | ||
* List of loggers currently in use | ||
*/ | ||
Logger.loggers = []; | ||
_Logger.loggers = []; | ||
/** | ||
@@ -405,6 +414,8 @@ *Define if you want a timestamp with your logs | ||
*/ | ||
Logger.timestamp = false; | ||
/** | ||
* Export a default Logger | ||
*/ | ||
exports.logger = new Logger(); | ||
_Logger.timestamp = false; | ||
var Logger = _Logger; | ||
var logger = new Logger(); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
logger | ||
}); |
{ | ||
"name": "@dzeio/logger", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "My Personnal Logger", | ||
@@ -13,3 +13,17 @@ "repository": { | ||
"main": "./dist/Logger.js", | ||
"module": "./dist/Logger.mjs", | ||
"types": "./dist/Logger.d.ts", | ||
"browser": "./dist/Logger.global.js", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/Logger.d.ts", | ||
"default": "./dist/Logger.js" | ||
}, | ||
"import": { | ||
"default": "./dist/Logger.mjs", | ||
"types": "./dist/Logger.d.mts" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
@@ -22,10 +36,9 @@ "ansi-colors": "^4.1.1" | ||
"eslint": "^7.4.0", | ||
"parcel": "1.12.3", | ||
"typescript": "^4.0.3" | ||
"tsup": "^7.1.0" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "npm run build", | ||
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc", | ||
"build": "tsup ./src/Logger.ts --format cjs,esm --dts --clean && tsup ./src/Logger.ts --format iife --global-name Logger --sourcemap", | ||
"test": "ts-node test" | ||
} | ||
} |
@@ -0,0 +0,0 @@ # @dzeio/logger |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
89661
154.13%4
-20%10
42.86%1710
159.48%1
Infinity%