@pandacss/logger 0.0.0-dev-20221121152823

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Segun Adebayo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ import colors from 'kleur';
2
+ export { default as colors } from 'kleur';
3
+
4
+ declare const levelsMap: {
5
+ debug: {
6
+ w: number;
7
+ c: colors.Color;
8
+ };
9
+ info: {
10
+ w: number;
11
+ c: colors.Color;
12
+ };
13
+ warn: {
14
+ w: number;
15
+ c: colors.Color;
16
+ };
17
+ error: {
18
+ w: number;
19
+ c: colors.Color;
20
+ };
21
+ silent: {
22
+ w: number;
23
+ c: colors.Color;
24
+ };
25
+ };
26
+ declare type LogLevel = keyof typeof levelsMap;
27
+ declare type Config = {
28
+ level?: LogLevel;
29
+ defaults?: any;
30
+ only?: string[];
31
+ except?: string[];
32
+ };
33
+ declare type Entry = {
34
+ type: string;
35
+ level: LogLevel;
36
+ time: Date;
37
+ pid: number;
38
+ msg: string;
39
+ err?: Error | string;
40
+ [key: string]: any;
41
+ };
42
+ declare class Logger {
43
+ level: LogLevel;
44
+ only: string[];
45
+ except: string[];
46
+ defaults: any;
47
+ parsers: any;
48
+ constructor(conf?: Config);
49
+ addParser(key: string, parser: (data: any) => any): void;
50
+ private getEntry;
51
+ format(entry: Entry): string;
52
+ private parseErr;
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;
63
+ };
64
+ }
65
+ declare const logger: Logger;
66
+ declare function quote(...str: string[]): string;
67
+
68
+ export { Config, LogLevel, logger, quote };
package/dist/index.js ADDED
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ colors: () => import_kleur.default,
30
+ logger: () => logger,
31
+ quote: () => quote
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+
35
+ // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
36
+ function escapeStringRegexp(string) {
37
+ if (typeof string !== "string") {
38
+ throw new TypeError("Expected a string");
39
+ }
40
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
41
+ }
42
+
43
+ // ../../node_modules/.pnpm/matcher@5.0.0/node_modules/matcher/index.js
44
+ var regexpCache = /* @__PURE__ */ new Map();
45
+ var sanitizeArray = (input, inputName) => {
46
+ if (!Array.isArray(input)) {
47
+ switch (typeof input) {
48
+ case "string":
49
+ input = [input];
50
+ break;
51
+ case "undefined":
52
+ input = [];
53
+ break;
54
+ default:
55
+ throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
56
+ }
57
+ }
58
+ return input.filter((string) => {
59
+ if (typeof string !== "string") {
60
+ if (typeof string === "undefined") {
61
+ return false;
62
+ }
63
+ throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
64
+ }
65
+ return true;
66
+ });
67
+ };
68
+ var makeRegexp = (pattern, options) => {
69
+ options = {
70
+ caseSensitive: false,
71
+ ...options
72
+ };
73
+ const cacheKey = pattern + JSON.stringify(options);
74
+ if (regexpCache.has(cacheKey)) {
75
+ return regexpCache.get(cacheKey);
76
+ }
77
+ const negated = pattern[0] === "!";
78
+ if (negated) {
79
+ pattern = pattern.slice(1);
80
+ }
81
+ pattern = escapeStringRegexp(pattern).replace(/\\\*/g, "[\\s\\S]*");
82
+ const regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? "" : "i");
83
+ regexp.negated = negated;
84
+ regexpCache.set(cacheKey, regexp);
85
+ return regexp;
86
+ };
87
+ var baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
88
+ inputs = sanitizeArray(inputs, "inputs");
89
+ patterns = sanitizeArray(patterns, "patterns");
90
+ if (patterns.length === 0) {
91
+ return [];
92
+ }
93
+ patterns = patterns.map((pattern) => makeRegexp(pattern, options));
94
+ const { allPatterns } = options || {};
95
+ const result = [];
96
+ for (const input of inputs) {
97
+ let matches2;
98
+ const didFit = [...patterns].fill(false);
99
+ for (const [index, pattern] of patterns.entries()) {
100
+ if (pattern.test(input)) {
101
+ didFit[index] = true;
102
+ matches2 = !pattern.negated;
103
+ if (!matches2) {
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ if (!(matches2 === false || matches2 === void 0 && patterns.some((pattern) => !pattern.negated) || allPatterns && didFit.some((yes, index) => !yes && !patterns[index].negated))) {
109
+ result.push(input);
110
+ if (firstMatchOnly) {
111
+ break;
112
+ }
113
+ }
114
+ }
115
+ return result;
116
+ };
117
+ function isMatch(inputs, patterns, options) {
118
+ return baseMatcher(inputs, patterns, options, true).length > 0;
119
+ }
120
+
121
+ // src/index.ts
122
+ var import_kleur = __toESM(require("kleur"));
123
+ var import_util = __toESM(require("util"));
124
+ var omitKeys = ["level", "type", "time", "pid"];
125
+ function compact(obj) {
126
+ const res = {};
127
+ for (const key in obj) {
128
+ if (!omitKeys.includes(key) && obj[key] != null) {
129
+ res[key] = obj[key];
130
+ }
131
+ }
132
+ return res;
133
+ }
134
+ var levelsMap = {
135
+ debug: { w: 0, c: import_kleur.default.magenta },
136
+ info: { w: 1, c: import_kleur.default.blue },
137
+ warn: { w: 2, c: import_kleur.default.yellow },
138
+ error: { w: 3, c: import_kleur.default.red },
139
+ silent: { w: 4, c: import_kleur.default.white }
140
+ };
141
+ function matches(filters, value) {
142
+ return filters.some((search) => isMatch(value, search));
143
+ }
144
+ var Logger = class {
145
+ level;
146
+ only = [];
147
+ except = [];
148
+ defaults;
149
+ parsers;
150
+ constructor(conf = {}) {
151
+ const debugEnv = process.env.PANDA_DEBUG;
152
+ this.level = debugEnv ? "debug" : conf.level || "info";
153
+ const only = conf.only ?? debugEnv;
154
+ if (only && only !== "*") {
155
+ this.only = Array.isArray(only) ? only : only.split(/[\s,]+/);
156
+ }
157
+ if (conf.except) {
158
+ this.except = conf.except;
159
+ }
160
+ this.defaults = conf.defaults || {};
161
+ this.parsers = { err: this.parseErr };
162
+ }
163
+ addParser(key, parser) {
164
+ this.parsers[key] = parser;
165
+ }
166
+ getEntry(level, args) {
167
+ const data = typeof args[0] == "object" ? args.shift() : {};
168
+ let msg = import_util.default.format(...args);
169
+ const pid = process.pid != 1 ? process.pid : null;
170
+ for (const key in this.parsers) {
171
+ if (key in data) {
172
+ Object.assign(data, this.parsers[key](data));
173
+ }
174
+ }
175
+ msg = msg || data.msg;
176
+ return { level, ...data, msg, pid, time: new Date() };
177
+ }
178
+ format(entry) {
179
+ entry.time.setMinutes(entry.time.getMinutes() - entry.time.getTimezoneOffset());
180
+ const data = compact(entry);
181
+ const formatted = typeof entry.msg == "string" ? entry.msg : import_util.default.inspect(data, { colors: true, depth: null });
182
+ const uword = entry.type ? import_kleur.default.gray(`[${entry.type}]`) : void 0;
183
+ if (!entry.level) {
184
+ return [uword, formatted].filter(Boolean).join(" ");
185
+ }
186
+ const color = levelsMap[entry.level].c;
187
+ const label = import_kleur.default.bold(color(`${entry.level}`));
188
+ const msg = [`\u{1F43C}`, label, uword, formatted].filter(Boolean).join(" ");
189
+ return msg;
190
+ }
191
+ parseErr({ err }) {
192
+ if (!(err instanceof Error))
193
+ err = new Error(err);
194
+ const stack = err.stack.split(/[\r\n]+\s*/g);
195
+ return {
196
+ err: null,
197
+ code: err.code,
198
+ class: err.constructor.name,
199
+ stack: stack.slice(1, -1),
200
+ type: err.constructor.name,
201
+ msg: import_kleur.default.red(err.message)
202
+ };
203
+ }
204
+ isValid(level, type) {
205
+ const badLevel = levelsMap[this.level].w > levelsMap[level].w;
206
+ const badType = matches(this.except, type) || this.only.length > 0 && !matches(this.only, type);
207
+ return !(badType || badLevel);
208
+ }
209
+ stdout(level, ...args) {
210
+ const baseEntry = this.getEntry(level, args);
211
+ const entry = { ...this.defaults, ...baseEntry };
212
+ const valid = this.isValid(level, entry.type);
213
+ if (!valid)
214
+ return false;
215
+ const msg = this.format(entry);
216
+ console.log(msg);
217
+ return entry;
218
+ }
219
+ warn(...args) {
220
+ return this.stdout("warn", ...args);
221
+ }
222
+ info(...args) {
223
+ return this.stdout("info", ...args);
224
+ }
225
+ debug(...args) {
226
+ return this.stdout("debug", ...args);
227
+ }
228
+ error(...args) {
229
+ return this.stdout("error", ...args);
230
+ }
231
+ log(...args) {
232
+ const entry = this.getEntry(null, args);
233
+ if (this.level === "silent")
234
+ return;
235
+ console.log(this.format(entry));
236
+ }
237
+ get time() {
238
+ const base = (level, msg, ...args) => {
239
+ const str = `${msg} ${args.join(" ")}`;
240
+ const start = process.hrtime();
241
+ return () => {
242
+ const end = process.hrtime(start);
243
+ const ms = end[0] * 1e3 + end[1] * 1e-6;
244
+ this.stdout(level, { type: "hrtime", msg: `${str} ${import_kleur.default.gray(`(${ms.toFixed(2)}ms)`)}` });
245
+ };
246
+ };
247
+ return {
248
+ info: (msg, ...args) => base("info", msg, ...args),
249
+ debug: (msg, ...args) => base("debug", msg, ...args)
250
+ };
251
+ }
252
+ };
253
+ var logger = new Logger();
254
+ function quote(...str) {
255
+ return import_kleur.default.cyan(`\`${str.join("")}\``);
256
+ }
257
+ // Annotate the CommonJS export names for ESM import in node:
258
+ 0 && (module.exports = {
259
+ colors,
260
+ logger,
261
+ quote
262
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,227 @@
1
+ // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
2
+ function escapeStringRegexp(string) {
3
+ if (typeof string !== "string") {
4
+ throw new TypeError("Expected a string");
5
+ }
6
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
7
+ }
8
+
9
+ // ../../node_modules/.pnpm/matcher@5.0.0/node_modules/matcher/index.js
10
+ var regexpCache = /* @__PURE__ */ new Map();
11
+ var sanitizeArray = (input, inputName) => {
12
+ if (!Array.isArray(input)) {
13
+ switch (typeof input) {
14
+ case "string":
15
+ input = [input];
16
+ break;
17
+ case "undefined":
18
+ input = [];
19
+ break;
20
+ default:
21
+ throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
22
+ }
23
+ }
24
+ return input.filter((string) => {
25
+ if (typeof string !== "string") {
26
+ if (typeof string === "undefined") {
27
+ return false;
28
+ }
29
+ throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
30
+ }
31
+ return true;
32
+ });
33
+ };
34
+ var makeRegexp = (pattern, options) => {
35
+ options = {
36
+ caseSensitive: false,
37
+ ...options
38
+ };
39
+ const cacheKey = pattern + JSON.stringify(options);
40
+ if (regexpCache.has(cacheKey)) {
41
+ return regexpCache.get(cacheKey);
42
+ }
43
+ const negated = pattern[0] === "!";
44
+ if (negated) {
45
+ pattern = pattern.slice(1);
46
+ }
47
+ pattern = escapeStringRegexp(pattern).replace(/\\\*/g, "[\\s\\S]*");
48
+ const regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? "" : "i");
49
+ regexp.negated = negated;
50
+ regexpCache.set(cacheKey, regexp);
51
+ return regexp;
52
+ };
53
+ var baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
54
+ inputs = sanitizeArray(inputs, "inputs");
55
+ patterns = sanitizeArray(patterns, "patterns");
56
+ if (patterns.length === 0) {
57
+ return [];
58
+ }
59
+ patterns = patterns.map((pattern) => makeRegexp(pattern, options));
60
+ const { allPatterns } = options || {};
61
+ const result = [];
62
+ for (const input of inputs) {
63
+ let matches2;
64
+ const didFit = [...patterns].fill(false);
65
+ for (const [index, pattern] of patterns.entries()) {
66
+ if (pattern.test(input)) {
67
+ didFit[index] = true;
68
+ matches2 = !pattern.negated;
69
+ if (!matches2) {
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ if (!(matches2 === false || matches2 === void 0 && patterns.some((pattern) => !pattern.negated) || allPatterns && didFit.some((yes, index) => !yes && !patterns[index].negated))) {
75
+ result.push(input);
76
+ if (firstMatchOnly) {
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ return result;
82
+ };
83
+ function isMatch(inputs, patterns, options) {
84
+ return baseMatcher(inputs, patterns, options, true).length > 0;
85
+ }
86
+
87
+ // src/index.ts
88
+ import colors from "kleur";
89
+ import util from "util";
90
+ var omitKeys = ["level", "type", "time", "pid"];
91
+ function compact(obj) {
92
+ const res = {};
93
+ for (const key in obj) {
94
+ if (!omitKeys.includes(key) && obj[key] != null) {
95
+ res[key] = obj[key];
96
+ }
97
+ }
98
+ return res;
99
+ }
100
+ var levelsMap = {
101
+ debug: { w: 0, c: colors.magenta },
102
+ info: { w: 1, c: colors.blue },
103
+ warn: { w: 2, c: colors.yellow },
104
+ error: { w: 3, c: colors.red },
105
+ silent: { w: 4, c: colors.white }
106
+ };
107
+ function matches(filters, value) {
108
+ return filters.some((search) => isMatch(value, search));
109
+ }
110
+ var Logger = class {
111
+ level;
112
+ only = [];
113
+ except = [];
114
+ defaults;
115
+ parsers;
116
+ constructor(conf = {}) {
117
+ const debugEnv = process.env.PANDA_DEBUG;
118
+ this.level = debugEnv ? "debug" : conf.level || "info";
119
+ const only = conf.only ?? debugEnv;
120
+ if (only && only !== "*") {
121
+ this.only = Array.isArray(only) ? only : only.split(/[\s,]+/);
122
+ }
123
+ if (conf.except) {
124
+ this.except = conf.except;
125
+ }
126
+ this.defaults = conf.defaults || {};
127
+ this.parsers = { err: this.parseErr };
128
+ }
129
+ addParser(key, parser) {
130
+ this.parsers[key] = parser;
131
+ }
132
+ getEntry(level, args) {
133
+ const data = typeof args[0] == "object" ? args.shift() : {};
134
+ let msg = util.format(...args);
135
+ const pid = process.pid != 1 ? process.pid : null;
136
+ for (const key in this.parsers) {
137
+ if (key in data) {
138
+ Object.assign(data, this.parsers[key](data));
139
+ }
140
+ }
141
+ msg = msg || data.msg;
142
+ return { level, ...data, msg, pid, time: new Date() };
143
+ }
144
+ format(entry) {
145
+ entry.time.setMinutes(entry.time.getMinutes() - entry.time.getTimezoneOffset());
146
+ const data = compact(entry);
147
+ const formatted = typeof entry.msg == "string" ? entry.msg : util.inspect(data, { colors: true, depth: null });
148
+ const uword = entry.type ? colors.gray(`[${entry.type}]`) : void 0;
149
+ if (!entry.level) {
150
+ return [uword, formatted].filter(Boolean).join(" ");
151
+ }
152
+ const color = levelsMap[entry.level].c;
153
+ const label = colors.bold(color(`${entry.level}`));
154
+ const msg = [`\u{1F43C}`, label, uword, formatted].filter(Boolean).join(" ");
155
+ return msg;
156
+ }
157
+ parseErr({ err }) {
158
+ if (!(err instanceof Error))
159
+ err = new Error(err);
160
+ const stack = err.stack.split(/[\r\n]+\s*/g);
161
+ return {
162
+ err: null,
163
+ code: err.code,
164
+ class: err.constructor.name,
165
+ stack: stack.slice(1, -1),
166
+ type: err.constructor.name,
167
+ msg: colors.red(err.message)
168
+ };
169
+ }
170
+ isValid(level, type) {
171
+ const badLevel = levelsMap[this.level].w > levelsMap[level].w;
172
+ const badType = matches(this.except, type) || this.only.length > 0 && !matches(this.only, type);
173
+ return !(badType || badLevel);
174
+ }
175
+ stdout(level, ...args) {
176
+ const baseEntry = this.getEntry(level, args);
177
+ const entry = { ...this.defaults, ...baseEntry };
178
+ const valid = this.isValid(level, entry.type);
179
+ if (!valid)
180
+ return false;
181
+ const msg = this.format(entry);
182
+ console.log(msg);
183
+ return entry;
184
+ }
185
+ warn(...args) {
186
+ return this.stdout("warn", ...args);
187
+ }
188
+ info(...args) {
189
+ return this.stdout("info", ...args);
190
+ }
191
+ debug(...args) {
192
+ return this.stdout("debug", ...args);
193
+ }
194
+ error(...args) {
195
+ return this.stdout("error", ...args);
196
+ }
197
+ log(...args) {
198
+ const entry = this.getEntry(null, args);
199
+ if (this.level === "silent")
200
+ return;
201
+ console.log(this.format(entry));
202
+ }
203
+ get time() {
204
+ const base = (level, msg, ...args) => {
205
+ const str = `${msg} ${args.join(" ")}`;
206
+ const start = process.hrtime();
207
+ return () => {
208
+ const end = process.hrtime(start);
209
+ const ms = end[0] * 1e3 + end[1] * 1e-6;
210
+ this.stdout(level, { type: "hrtime", msg: `${str} ${colors.gray(`(${ms.toFixed(2)}ms)`)}` });
211
+ };
212
+ };
213
+ return {
214
+ info: (msg, ...args) => base("info", msg, ...args),
215
+ debug: (msg, ...args) => base("debug", msg, ...args)
216
+ };
217
+ }
218
+ };
219
+ var logger = new Logger();
220
+ function quote(...str) {
221
+ return colors.cyan(`\`${str.join("")}\``);
222
+ }
223
+ export {
224
+ colors,
225
+ logger,
226
+ quote
227
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@pandacss/logger",
3
+ "version": "0.0.0-dev-20221121152823",
4
+ "description": "The core css panda library",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "author": "Segun Adebayo <joseshegs@gmail.com>",
9
+ "sideEffects": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "dependencies": {
17
+ "kleur": "^4.1.5"
18
+ },
19
+ "devDependencies": {
20
+ "matcher": "5.0.0"
21
+ },
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
24
+ "build-fast": "tsup src/index.ts --format=esm,cjs --no-dts",
25
+ "dev": "pnpm build-fast --watch"
26
+ }
27
+ }