@pandacss/logger 0.0.0-dev-20230131074332 → 0.0.0-dev-20230203163304
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.
- package/dist/index.d.ts +39 -49
- package/dist/index.js +113 -139
- package/dist/index.mjs +112 -139
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,69 +1,59 @@
|
|
|
1
1
|
import colors from 'kleur';
|
|
2
2
|
export { default as colors } from 'kleur';
|
|
3
3
|
|
|
4
|
-
declare const
|
|
4
|
+
declare const logLevels: {
|
|
5
5
|
debug: {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
weight: number;
|
|
7
|
+
color: colors.Color;
|
|
8
8
|
};
|
|
9
9
|
info: {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
weight: number;
|
|
11
|
+
color: colors.Color;
|
|
12
12
|
};
|
|
13
13
|
warn: {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
weight: number;
|
|
15
|
+
color: colors.Color;
|
|
16
16
|
};
|
|
17
17
|
error: {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
weight: number;
|
|
19
|
+
color: colors.Color;
|
|
20
20
|
};
|
|
21
21
|
silent: {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
weight: number;
|
|
23
|
+
color: colors.Color;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
type LogLevel = keyof typeof
|
|
26
|
+
type LogLevel = keyof typeof logLevels;
|
|
27
|
+
declare const quote: (...str: string[]) => string;
|
|
27
28
|
type Config = {
|
|
28
29
|
level?: LogLevel;
|
|
29
|
-
|
|
30
|
-
only?: string[];
|
|
31
|
-
except?: string[];
|
|
30
|
+
filter?: string;
|
|
32
31
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
declare const createLogger: (conf?: Config) => {
|
|
33
|
+
level: "debug" | "info" | "warn" | "error" | "silent";
|
|
34
|
+
box: (content: string, title?: string) => string;
|
|
35
|
+
warn: (type: string, data: any) => void;
|
|
36
|
+
info: (type: string, data: any) => void;
|
|
37
|
+
debug: (type: string, data: any) => void;
|
|
38
|
+
error: (type: string, data: any) => void;
|
|
39
|
+
log: (data: string) => void;
|
|
40
|
+
time: {
|
|
41
|
+
info: (msg: string) => () => void;
|
|
42
|
+
debug: (msg: string) => () => void;
|
|
43
|
+
};
|
|
41
44
|
};
|
|
42
|
-
declare
|
|
43
|
-
level:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
private isValid;
|
|
54
|
-
private stdout;
|
|
55
|
-
warn(...args: any[]): any;
|
|
56
|
-
info(...args: any[]): any;
|
|
57
|
-
debug(...args: any[]): any;
|
|
58
|
-
error(...args: any[]): any;
|
|
59
|
-
log(...args: any[]): void;
|
|
60
|
-
get time(): {
|
|
61
|
-
info: (msg: string, ...args: any[]) => () => void;
|
|
62
|
-
debug: (msg: string, ...args: any[]) => () => void;
|
|
45
|
+
declare const logger: {
|
|
46
|
+
level: "debug" | "info" | "warn" | "error" | "silent";
|
|
47
|
+
box: (content: string, title?: string) => string;
|
|
48
|
+
warn: (type: string, data: any) => void;
|
|
49
|
+
info: (type: string, data: any) => void;
|
|
50
|
+
debug: (type: string, data: any) => void;
|
|
51
|
+
error: (type: string, data: any) => void;
|
|
52
|
+
log: (data: string) => void;
|
|
53
|
+
time: {
|
|
54
|
+
info: (msg: string) => () => void;
|
|
55
|
+
debug: (msg: string) => () => void;
|
|
63
56
|
};
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
declare const logger: Logger;
|
|
67
|
-
declare function quote(...str: string[]): string;
|
|
57
|
+
};
|
|
68
58
|
|
|
69
|
-
export { Config, LogLevel, logger, quote };
|
|
59
|
+
export { Config, LogLevel, createLogger, logger, quote };
|
package/dist/index.js
CHANGED
|
@@ -365,6 +365,7 @@ var require_ansi_align = __commonJS({
|
|
|
365
365
|
var src_exports = {};
|
|
366
366
|
__export(src_exports, {
|
|
367
367
|
colors: () => import_kleur.default,
|
|
368
|
+
createLogger: () => createLogger,
|
|
368
369
|
logger: () => logger,
|
|
369
370
|
quote: () => quote
|
|
370
371
|
});
|
|
@@ -1586,6 +1587,7 @@ function boxen(text, options) {
|
|
|
1586
1587
|
|
|
1587
1588
|
// src/index.ts
|
|
1588
1589
|
var import_kleur = __toESM(require("kleur"));
|
|
1590
|
+
var import_lil_fp = require("lil-fp");
|
|
1589
1591
|
|
|
1590
1592
|
// ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
|
|
1591
1593
|
function escapeStringRegexp(string) {
|
|
@@ -1674,152 +1676,124 @@ function isMatch(inputs, patterns, options) {
|
|
|
1674
1676
|
}
|
|
1675
1677
|
|
|
1676
1678
|
// src/index.ts
|
|
1677
|
-
var
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
res[key] = obj[key];
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
return res;
|
|
1687
|
-
}
|
|
1688
|
-
var levelsMap = {
|
|
1689
|
-
debug: { w: 0, c: import_kleur.default.magenta },
|
|
1690
|
-
info: { w: 1, c: import_kleur.default.blue },
|
|
1691
|
-
warn: { w: 2, c: import_kleur.default.yellow },
|
|
1692
|
-
error: { w: 3, c: import_kleur.default.red },
|
|
1693
|
-
silent: { w: 4, c: import_kleur.default.white }
|
|
1679
|
+
var logLevels = {
|
|
1680
|
+
debug: { weight: 0, color: import_kleur.default.magenta },
|
|
1681
|
+
info: { weight: 1, color: import_kleur.default.blue },
|
|
1682
|
+
warn: { weight: 2, color: import_kleur.default.yellow },
|
|
1683
|
+
error: { weight: 3, color: import_kleur.default.red },
|
|
1684
|
+
silent: { weight: 4, color: import_kleur.default.white }
|
|
1694
1685
|
};
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
this.except = conf.except;
|
|
1713
|
-
}
|
|
1714
|
-
this.defaults = conf.defaults || {};
|
|
1715
|
-
this.parsers = { err: this.parseErr };
|
|
1716
|
-
}
|
|
1717
|
-
addParser(key, parser) {
|
|
1718
|
-
this.parsers[key] = parser;
|
|
1719
|
-
}
|
|
1720
|
-
getEntry(level, args) {
|
|
1721
|
-
const data = typeof args[0] == "object" ? args.shift() : {};
|
|
1722
|
-
let msg = import_util.default.format(...args);
|
|
1723
|
-
const pid = process.pid != 1 ? process.pid : null;
|
|
1724
|
-
for (const key in this.parsers) {
|
|
1725
|
-
if (key in data) {
|
|
1726
|
-
Object.assign(data, this.parsers[key](data));
|
|
1686
|
+
var createEntry = (level, type, data) => {
|
|
1687
|
+
const msg = data instanceof Error ? import_kleur.default.red(data.message) : data;
|
|
1688
|
+
return { type, level, msg };
|
|
1689
|
+
};
|
|
1690
|
+
var formatEntry = (entry) => (0, import_lil_fp.pipe)(
|
|
1691
|
+
{ entry },
|
|
1692
|
+
import_lil_fp.Obj.assign(({ entry: entry2 }) => ({
|
|
1693
|
+
uword: entry2.type ? import_kleur.default.gray(`[${entry2.type}]`) : ""
|
|
1694
|
+
})),
|
|
1695
|
+
(0, import_lil_fp.match)(
|
|
1696
|
+
(0, import_lil_fp.when)(
|
|
1697
|
+
({ entry: entry2 }) => entry2.level != null,
|
|
1698
|
+
({ entry: entry2, uword }) => {
|
|
1699
|
+
const { msg, level } = entry2;
|
|
1700
|
+
const color = logLevels[level].color;
|
|
1701
|
+
const label = import_kleur.default.bold(color(`${level}`));
|
|
1702
|
+
return { label: [`\u{1F43C}`, label, uword].filter(Boolean).join(" "), msg };
|
|
1727
1703
|
}
|
|
1704
|
+
),
|
|
1705
|
+
(0, import_lil_fp.otherwise)(({ entry: entry2, uword }) => {
|
|
1706
|
+
const { msg } = entry2;
|
|
1707
|
+
return { label: uword ?? "", msg };
|
|
1708
|
+
})
|
|
1709
|
+
)
|
|
1710
|
+
);
|
|
1711
|
+
var box = (content, title) => boxen(content, {
|
|
1712
|
+
padding: { left: 3, right: 3, top: 1, bottom: 1 },
|
|
1713
|
+
borderColor: "magenta",
|
|
1714
|
+
borderStyle: "round",
|
|
1715
|
+
title,
|
|
1716
|
+
titleAlignment: "center"
|
|
1717
|
+
});
|
|
1718
|
+
var quote = (...str) => import_kleur.default.cyan(`\`${str.join("")}\``);
|
|
1719
|
+
var matches = (filters, value) => filters.some((search) => isMatch(value, search));
|
|
1720
|
+
var createLogger = (conf = {}) => {
|
|
1721
|
+
let level = conf.level ?? "info";
|
|
1722
|
+
const { stdout, timing } = (0, import_lil_fp.pipe)(
|
|
1723
|
+
conf,
|
|
1724
|
+
({ filter }) => ({
|
|
1725
|
+
getLevel: () => filter ? "debug" : level,
|
|
1726
|
+
filter: filter !== "*" ? filter?.split(/[\s,]+/) ?? [] : []
|
|
1727
|
+
}),
|
|
1728
|
+
import_lil_fp.Obj.assignTo("config"),
|
|
1729
|
+
import_lil_fp.Obj.assign(({ config }) => ({
|
|
1730
|
+
isValid(level2, type) {
|
|
1731
|
+
const badLevel = logLevels[config.getLevel()].weight > logLevels[level2].weight;
|
|
1732
|
+
const badType = config.filter.length > 0 && !matches(config.filter, type);
|
|
1733
|
+
return !(badType || badLevel);
|
|
1734
|
+
}
|
|
1735
|
+
})),
|
|
1736
|
+
import_lil_fp.Obj.assign(({ isValid, config }) => ({
|
|
1737
|
+
stdout(level2) {
|
|
1738
|
+
return (type, data) => {
|
|
1739
|
+
(0, import_lil_fp.pipe)(
|
|
1740
|
+
createEntry(level2, type, data),
|
|
1741
|
+
(0, import_lil_fp.match)(
|
|
1742
|
+
(0, import_lil_fp.when)(
|
|
1743
|
+
({ level: level3, type: type2 }) => level3 != null && isValid(level3, type2),
|
|
1744
|
+
(entry) => {
|
|
1745
|
+
const { msg, label } = formatEntry(entry) ?? {};
|
|
1746
|
+
console.log(label, msg);
|
|
1747
|
+
}
|
|
1748
|
+
),
|
|
1749
|
+
(0, import_lil_fp.when)(
|
|
1750
|
+
({ level: level3 }) => config.getLevel() !== "silent" && level3 == null,
|
|
1751
|
+
() => {
|
|
1752
|
+
console.log(...[type, data].filter(Boolean));
|
|
1753
|
+
}
|
|
1754
|
+
)
|
|
1755
|
+
)
|
|
1756
|
+
);
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
})),
|
|
1760
|
+
import_lil_fp.Obj.assign(({ stdout: stdout2 }) => ({
|
|
1761
|
+
timing: (level2) => (msg) => {
|
|
1762
|
+
const start = performance.now();
|
|
1763
|
+
return () => {
|
|
1764
|
+
const end = performance.now();
|
|
1765
|
+
const ms = end - start;
|
|
1766
|
+
stdout2(level2)("hrtime", `${msg} ${import_kleur.default.gray(`(${ms.toFixed(2)}ms)`)}`);
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
}))
|
|
1770
|
+
);
|
|
1771
|
+
return {
|
|
1772
|
+
get level() {
|
|
1773
|
+
return level;
|
|
1774
|
+
},
|
|
1775
|
+
set level(newLevel) {
|
|
1776
|
+
level = newLevel;
|
|
1777
|
+
},
|
|
1778
|
+
box,
|
|
1779
|
+
warn: stdout("warn"),
|
|
1780
|
+
info: stdout("info"),
|
|
1781
|
+
debug: stdout("debug"),
|
|
1782
|
+
error: stdout("error"),
|
|
1783
|
+
log: (data) => stdout(null)("", data),
|
|
1784
|
+
time: {
|
|
1785
|
+
info: timing("info"),
|
|
1786
|
+
debug: timing("debug")
|
|
1728
1787
|
}
|
|
1729
|
-
|
|
1730
|
-
return { level, ...data, msg, pid, time: new Date() };
|
|
1731
|
-
}
|
|
1732
|
-
format(entry) {
|
|
1733
|
-
entry.time.setMinutes(entry.time.getMinutes() - entry.time.getTimezoneOffset());
|
|
1734
|
-
const data = compact(entry);
|
|
1735
|
-
const formatted = typeof entry.msg == "string" ? entry.msg : import_util.default.inspect(data, { colors: true, depth: null });
|
|
1736
|
-
const uword = entry.type ? import_kleur.default.gray(`[${entry.type}]`) : void 0;
|
|
1737
|
-
if (!entry.level) {
|
|
1738
|
-
return [uword, formatted].filter(Boolean).join(" ");
|
|
1739
|
-
}
|
|
1740
|
-
const color = levelsMap[entry.level].c;
|
|
1741
|
-
const label = import_kleur.default.bold(color(`${entry.level}`));
|
|
1742
|
-
const msg = [`\u{1F43C}`, label, uword, formatted].filter(Boolean).join(" ");
|
|
1743
|
-
return msg;
|
|
1744
|
-
}
|
|
1745
|
-
parseErr({ err }) {
|
|
1746
|
-
if (!(err instanceof Error))
|
|
1747
|
-
err = new Error(err);
|
|
1748
|
-
const stack = err.stack.split(/[\r\n]+\s*/g);
|
|
1749
|
-
return {
|
|
1750
|
-
err: null,
|
|
1751
|
-
code: err.code,
|
|
1752
|
-
class: err.constructor.name,
|
|
1753
|
-
stack: stack.slice(1, -1),
|
|
1754
|
-
type: err.constructor.name,
|
|
1755
|
-
msg: import_kleur.default.red(err.message)
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
isValid(level, type) {
|
|
1759
|
-
const badLevel = levelsMap[this.level].w > levelsMap[level].w;
|
|
1760
|
-
const badType = matches(this.except, type) || this.only.length > 0 && !matches(this.only, type);
|
|
1761
|
-
return !(badType || badLevel);
|
|
1762
|
-
}
|
|
1763
|
-
stdout(level, ...args) {
|
|
1764
|
-
const baseEntry = this.getEntry(level, args);
|
|
1765
|
-
const entry = { ...this.defaults, ...baseEntry };
|
|
1766
|
-
const valid = this.isValid(level, entry.type);
|
|
1767
|
-
if (!valid)
|
|
1768
|
-
return false;
|
|
1769
|
-
const msg = this.format(entry);
|
|
1770
|
-
console.log(msg);
|
|
1771
|
-
return entry;
|
|
1772
|
-
}
|
|
1773
|
-
warn(...args) {
|
|
1774
|
-
return this.stdout("warn", ...args);
|
|
1775
|
-
}
|
|
1776
|
-
info(...args) {
|
|
1777
|
-
return this.stdout("info", ...args);
|
|
1778
|
-
}
|
|
1779
|
-
debug(...args) {
|
|
1780
|
-
return this.stdout("debug", ...args);
|
|
1781
|
-
}
|
|
1782
|
-
error(...args) {
|
|
1783
|
-
return this.stdout("error", ...args);
|
|
1784
|
-
}
|
|
1785
|
-
log(...args) {
|
|
1786
|
-
const entry = this.getEntry(null, args);
|
|
1787
|
-
if (this.level === "silent")
|
|
1788
|
-
return;
|
|
1789
|
-
console.log(this.format(entry));
|
|
1790
|
-
}
|
|
1791
|
-
get time() {
|
|
1792
|
-
const base = (level, msg, ...args) => {
|
|
1793
|
-
const str = `${msg} ${args.join(" ")}`;
|
|
1794
|
-
const start = process.hrtime();
|
|
1795
|
-
return () => {
|
|
1796
|
-
const end = process.hrtime(start);
|
|
1797
|
-
const ms = end[0] * 1e3 + end[1] * 1e-6;
|
|
1798
|
-
this.stdout(level, { type: "hrtime", msg: `${str} ${import_kleur.default.gray(`(${ms.toFixed(2)}ms)`)}` });
|
|
1799
|
-
};
|
|
1800
|
-
};
|
|
1801
|
-
return {
|
|
1802
|
-
info: (msg, ...args) => base("info", msg, ...args),
|
|
1803
|
-
debug: (msg, ...args) => base("debug", msg, ...args)
|
|
1804
|
-
};
|
|
1805
|
-
}
|
|
1806
|
-
box(content, title) {
|
|
1807
|
-
return boxen(content, {
|
|
1808
|
-
padding: { left: 3, right: 3, top: 1, bottom: 1 },
|
|
1809
|
-
borderColor: "magenta",
|
|
1810
|
-
borderStyle: "round",
|
|
1811
|
-
title,
|
|
1812
|
-
titleAlignment: "center"
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1788
|
+
};
|
|
1815
1789
|
};
|
|
1816
|
-
var logger =
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
}
|
|
1790
|
+
var logger = createLogger({
|
|
1791
|
+
filter: typeof process !== "undefined" ? process.env.PANDA_DEBUG : void 0
|
|
1792
|
+
});
|
|
1820
1793
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1821
1794
|
0 && (module.exports = {
|
|
1822
1795
|
colors,
|
|
1796
|
+
createLogger,
|
|
1823
1797
|
logger,
|
|
1824
1798
|
quote
|
|
1825
1799
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1571,6 +1571,7 @@ function boxen(text, options) {
|
|
|
1571
1571
|
|
|
1572
1572
|
// src/index.ts
|
|
1573
1573
|
import colors from "kleur";
|
|
1574
|
+
import { match, Obj, otherwise, pipe, when } from "lil-fp";
|
|
1574
1575
|
|
|
1575
1576
|
// ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
|
|
1576
1577
|
function escapeStringRegexp(string) {
|
|
@@ -1659,151 +1660,123 @@ function isMatch(inputs, patterns, options) {
|
|
|
1659
1660
|
}
|
|
1660
1661
|
|
|
1661
1662
|
// src/index.ts
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
res[key] = obj[key];
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
return res;
|
|
1672
|
-
}
|
|
1673
|
-
var levelsMap = {
|
|
1674
|
-
debug: { w: 0, c: colors.magenta },
|
|
1675
|
-
info: { w: 1, c: colors.blue },
|
|
1676
|
-
warn: { w: 2, c: colors.yellow },
|
|
1677
|
-
error: { w: 3, c: colors.red },
|
|
1678
|
-
silent: { w: 4, c: colors.white }
|
|
1663
|
+
var logLevels = {
|
|
1664
|
+
debug: { weight: 0, color: colors.magenta },
|
|
1665
|
+
info: { weight: 1, color: colors.blue },
|
|
1666
|
+
warn: { weight: 2, color: colors.yellow },
|
|
1667
|
+
error: { weight: 3, color: colors.red },
|
|
1668
|
+
silent: { weight: 4, color: colors.white }
|
|
1679
1669
|
};
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
this.except = conf.except;
|
|
1698
|
-
}
|
|
1699
|
-
this.defaults = conf.defaults || {};
|
|
1700
|
-
this.parsers = { err: this.parseErr };
|
|
1701
|
-
}
|
|
1702
|
-
addParser(key, parser) {
|
|
1703
|
-
this.parsers[key] = parser;
|
|
1704
|
-
}
|
|
1705
|
-
getEntry(level, args) {
|
|
1706
|
-
const data = typeof args[0] == "object" ? args.shift() : {};
|
|
1707
|
-
let msg = util.format(...args);
|
|
1708
|
-
const pid = process.pid != 1 ? process.pid : null;
|
|
1709
|
-
for (const key in this.parsers) {
|
|
1710
|
-
if (key in data) {
|
|
1711
|
-
Object.assign(data, this.parsers[key](data));
|
|
1670
|
+
var createEntry = (level, type, data) => {
|
|
1671
|
+
const msg = data instanceof Error ? colors.red(data.message) : data;
|
|
1672
|
+
return { type, level, msg };
|
|
1673
|
+
};
|
|
1674
|
+
var formatEntry = (entry) => pipe(
|
|
1675
|
+
{ entry },
|
|
1676
|
+
Obj.assign(({ entry: entry2 }) => ({
|
|
1677
|
+
uword: entry2.type ? colors.gray(`[${entry2.type}]`) : ""
|
|
1678
|
+
})),
|
|
1679
|
+
match(
|
|
1680
|
+
when(
|
|
1681
|
+
({ entry: entry2 }) => entry2.level != null,
|
|
1682
|
+
({ entry: entry2, uword }) => {
|
|
1683
|
+
const { msg, level } = entry2;
|
|
1684
|
+
const color = logLevels[level].color;
|
|
1685
|
+
const label = colors.bold(color(`${level}`));
|
|
1686
|
+
return { label: [`\u{1F43C}`, label, uword].filter(Boolean).join(" "), msg };
|
|
1712
1687
|
}
|
|
1688
|
+
),
|
|
1689
|
+
otherwise(({ entry: entry2, uword }) => {
|
|
1690
|
+
const { msg } = entry2;
|
|
1691
|
+
return { label: uword ?? "", msg };
|
|
1692
|
+
})
|
|
1693
|
+
)
|
|
1694
|
+
);
|
|
1695
|
+
var box = (content, title) => boxen(content, {
|
|
1696
|
+
padding: { left: 3, right: 3, top: 1, bottom: 1 },
|
|
1697
|
+
borderColor: "magenta",
|
|
1698
|
+
borderStyle: "round",
|
|
1699
|
+
title,
|
|
1700
|
+
titleAlignment: "center"
|
|
1701
|
+
});
|
|
1702
|
+
var quote = (...str) => colors.cyan(`\`${str.join("")}\``);
|
|
1703
|
+
var matches = (filters, value) => filters.some((search) => isMatch(value, search));
|
|
1704
|
+
var createLogger = (conf = {}) => {
|
|
1705
|
+
let level = conf.level ?? "info";
|
|
1706
|
+
const { stdout, timing } = pipe(
|
|
1707
|
+
conf,
|
|
1708
|
+
({ filter }) => ({
|
|
1709
|
+
getLevel: () => filter ? "debug" : level,
|
|
1710
|
+
filter: filter !== "*" ? filter?.split(/[\s,]+/) ?? [] : []
|
|
1711
|
+
}),
|
|
1712
|
+
Obj.assignTo("config"),
|
|
1713
|
+
Obj.assign(({ config }) => ({
|
|
1714
|
+
isValid(level2, type) {
|
|
1715
|
+
const badLevel = logLevels[config.getLevel()].weight > logLevels[level2].weight;
|
|
1716
|
+
const badType = config.filter.length > 0 && !matches(config.filter, type);
|
|
1717
|
+
return !(badType || badLevel);
|
|
1718
|
+
}
|
|
1719
|
+
})),
|
|
1720
|
+
Obj.assign(({ isValid, config }) => ({
|
|
1721
|
+
stdout(level2) {
|
|
1722
|
+
return (type, data) => {
|
|
1723
|
+
pipe(
|
|
1724
|
+
createEntry(level2, type, data),
|
|
1725
|
+
match(
|
|
1726
|
+
when(
|
|
1727
|
+
({ level: level3, type: type2 }) => level3 != null && isValid(level3, type2),
|
|
1728
|
+
(entry) => {
|
|
1729
|
+
const { msg, label } = formatEntry(entry) ?? {};
|
|
1730
|
+
console.log(label, msg);
|
|
1731
|
+
}
|
|
1732
|
+
),
|
|
1733
|
+
when(
|
|
1734
|
+
({ level: level3 }) => config.getLevel() !== "silent" && level3 == null,
|
|
1735
|
+
() => {
|
|
1736
|
+
console.log(...[type, data].filter(Boolean));
|
|
1737
|
+
}
|
|
1738
|
+
)
|
|
1739
|
+
)
|
|
1740
|
+
);
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
})),
|
|
1744
|
+
Obj.assign(({ stdout: stdout2 }) => ({
|
|
1745
|
+
timing: (level2) => (msg) => {
|
|
1746
|
+
const start = performance.now();
|
|
1747
|
+
return () => {
|
|
1748
|
+
const end = performance.now();
|
|
1749
|
+
const ms = end - start;
|
|
1750
|
+
stdout2(level2)("hrtime", `${msg} ${colors.gray(`(${ms.toFixed(2)}ms)`)}`);
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
}))
|
|
1754
|
+
);
|
|
1755
|
+
return {
|
|
1756
|
+
get level() {
|
|
1757
|
+
return level;
|
|
1758
|
+
},
|
|
1759
|
+
set level(newLevel) {
|
|
1760
|
+
level = newLevel;
|
|
1761
|
+
},
|
|
1762
|
+
box,
|
|
1763
|
+
warn: stdout("warn"),
|
|
1764
|
+
info: stdout("info"),
|
|
1765
|
+
debug: stdout("debug"),
|
|
1766
|
+
error: stdout("error"),
|
|
1767
|
+
log: (data) => stdout(null)("", data),
|
|
1768
|
+
time: {
|
|
1769
|
+
info: timing("info"),
|
|
1770
|
+
debug: timing("debug")
|
|
1713
1771
|
}
|
|
1714
|
-
|
|
1715
|
-
return { level, ...data, msg, pid, time: new Date() };
|
|
1716
|
-
}
|
|
1717
|
-
format(entry) {
|
|
1718
|
-
entry.time.setMinutes(entry.time.getMinutes() - entry.time.getTimezoneOffset());
|
|
1719
|
-
const data = compact(entry);
|
|
1720
|
-
const formatted = typeof entry.msg == "string" ? entry.msg : util.inspect(data, { colors: true, depth: null });
|
|
1721
|
-
const uword = entry.type ? colors.gray(`[${entry.type}]`) : void 0;
|
|
1722
|
-
if (!entry.level) {
|
|
1723
|
-
return [uword, formatted].filter(Boolean).join(" ");
|
|
1724
|
-
}
|
|
1725
|
-
const color = levelsMap[entry.level].c;
|
|
1726
|
-
const label = colors.bold(color(`${entry.level}`));
|
|
1727
|
-
const msg = [`\u{1F43C}`, label, uword, formatted].filter(Boolean).join(" ");
|
|
1728
|
-
return msg;
|
|
1729
|
-
}
|
|
1730
|
-
parseErr({ err }) {
|
|
1731
|
-
if (!(err instanceof Error))
|
|
1732
|
-
err = new Error(err);
|
|
1733
|
-
const stack = err.stack.split(/[\r\n]+\s*/g);
|
|
1734
|
-
return {
|
|
1735
|
-
err: null,
|
|
1736
|
-
code: err.code,
|
|
1737
|
-
class: err.constructor.name,
|
|
1738
|
-
stack: stack.slice(1, -1),
|
|
1739
|
-
type: err.constructor.name,
|
|
1740
|
-
msg: colors.red(err.message)
|
|
1741
|
-
};
|
|
1742
|
-
}
|
|
1743
|
-
isValid(level, type) {
|
|
1744
|
-
const badLevel = levelsMap[this.level].w > levelsMap[level].w;
|
|
1745
|
-
const badType = matches(this.except, type) || this.only.length > 0 && !matches(this.only, type);
|
|
1746
|
-
return !(badType || badLevel);
|
|
1747
|
-
}
|
|
1748
|
-
stdout(level, ...args) {
|
|
1749
|
-
const baseEntry = this.getEntry(level, args);
|
|
1750
|
-
const entry = { ...this.defaults, ...baseEntry };
|
|
1751
|
-
const valid = this.isValid(level, entry.type);
|
|
1752
|
-
if (!valid)
|
|
1753
|
-
return false;
|
|
1754
|
-
const msg = this.format(entry);
|
|
1755
|
-
console.log(msg);
|
|
1756
|
-
return entry;
|
|
1757
|
-
}
|
|
1758
|
-
warn(...args) {
|
|
1759
|
-
return this.stdout("warn", ...args);
|
|
1760
|
-
}
|
|
1761
|
-
info(...args) {
|
|
1762
|
-
return this.stdout("info", ...args);
|
|
1763
|
-
}
|
|
1764
|
-
debug(...args) {
|
|
1765
|
-
return this.stdout("debug", ...args);
|
|
1766
|
-
}
|
|
1767
|
-
error(...args) {
|
|
1768
|
-
return this.stdout("error", ...args);
|
|
1769
|
-
}
|
|
1770
|
-
log(...args) {
|
|
1771
|
-
const entry = this.getEntry(null, args);
|
|
1772
|
-
if (this.level === "silent")
|
|
1773
|
-
return;
|
|
1774
|
-
console.log(this.format(entry));
|
|
1775
|
-
}
|
|
1776
|
-
get time() {
|
|
1777
|
-
const base = (level, msg, ...args) => {
|
|
1778
|
-
const str = `${msg} ${args.join(" ")}`;
|
|
1779
|
-
const start = process.hrtime();
|
|
1780
|
-
return () => {
|
|
1781
|
-
const end = process.hrtime(start);
|
|
1782
|
-
const ms = end[0] * 1e3 + end[1] * 1e-6;
|
|
1783
|
-
this.stdout(level, { type: "hrtime", msg: `${str} ${colors.gray(`(${ms.toFixed(2)}ms)`)}` });
|
|
1784
|
-
};
|
|
1785
|
-
};
|
|
1786
|
-
return {
|
|
1787
|
-
info: (msg, ...args) => base("info", msg, ...args),
|
|
1788
|
-
debug: (msg, ...args) => base("debug", msg, ...args)
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
box(content, title) {
|
|
1792
|
-
return boxen(content, {
|
|
1793
|
-
padding: { left: 3, right: 3, top: 1, bottom: 1 },
|
|
1794
|
-
borderColor: "magenta",
|
|
1795
|
-
borderStyle: "round",
|
|
1796
|
-
title,
|
|
1797
|
-
titleAlignment: "center"
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1772
|
+
};
|
|
1800
1773
|
};
|
|
1801
|
-
var logger =
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
}
|
|
1774
|
+
var logger = createLogger({
|
|
1775
|
+
filter: typeof process !== "undefined" ? process.env.PANDA_DEBUG : void 0
|
|
1776
|
+
});
|
|
1805
1777
|
export {
|
|
1806
1778
|
colors,
|
|
1779
|
+
createLogger,
|
|
1807
1780
|
logger,
|
|
1808
1781
|
quote
|
|
1809
1782
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/logger",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20230203163304",
|
|
4
4
|
"description": "The core css panda library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"kleur": "^4.1.5"
|
|
17
|
+
"kleur": "^4.1.5",
|
|
18
|
+
"lil-fp": "1.0.6"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"matcher": "5.0.0",
|