| "use strict"; | ||
| // type-safe way to access global values that may not be available in all runtimes | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.context = void 0; | ||
| exports.context = globalThis; |
+3
-3
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.env = void 0; | ||
| const types_ts_1 = require("./types.js"); | ||
| const prompts = (variable) => types_ts_1.context.Deno?.permissions.querySync?.({ name: "env", variable })?.state === "prompt"; | ||
| const env = (variable) => (!prompts(variable) && (types_ts_1.context.process?.env ?? types_ts_1.context.env)?.[variable]) || ""; | ||
| const context_ts_1 = require("./context.js"); | ||
| const prompts = (variable) => context_ts_1.context.Deno?.permissions.querySync?.({ name: "env", variable })?.state === "prompt"; | ||
| const env = (variable) => (!prompts(variable) && (context_ts_1.context.process?.env ?? context_ts_1.context.env)?.[variable]) || ""; | ||
| exports.env = env; |
+29
-7
@@ -5,10 +5,13 @@ "use strict"; | ||
| exports.w = w; | ||
| const types_ts_1 = require("./types.js"); | ||
| const context_ts_1 = require("./context.js"); | ||
| const colours_ts_1 = require("./colours.js"); | ||
| const env_ts_1 = require("./env.js"); | ||
| const namespacing_ts_1 = require("./namespacing.js"); | ||
| function noop() { } | ||
| const DEBUG = (0, env_ts_1.env)("DEBUG"); | ||
| const stderr = types_ts_1.context.process?.stderr; | ||
| const useColour = stderr?.isTTY && !(0, env_ts_1.env)("NO_COLOR"); | ||
| const debug = types_ts_1.context.console.Console?.(stderr)?.debug || types_ts_1.context.console.debug; | ||
| const stderr = context_ts_1.context.process?.stderr; | ||
| const useColour = (0, env_ts_1.env)("FORCE_COLOR") || (!(0, env_ts_1.env)("NO_COLOR") && (stderr?.isTTY ?? context_ts_1.context.document) && !(0, env_ts_1.env)("CI")); | ||
| const cons = context_ts_1.context.console.Console?.(stderr) ?? context_ts_1.context.console; | ||
| const pick = (level) => (cons[level] ?? cons.log ?? noop).bind(cons); | ||
| const ns = (n) => (n ? n + " " : ""); | ||
| /** | ||
@@ -18,3 +21,2 @@ * The underlying namespace manager. | ||
| exports.namespaces = new namespacing_ts_1.Namespaces(DEBUG); | ||
| const ns = (n) => (n ? n + " " : ""); | ||
| /** | ||
@@ -45,3 +47,4 @@ * Create a debug instance for a namespace. | ||
| return; | ||
| if (types_ts_1.context.document) | ||
| // will fallback to the no-colour logger if useColour is false | ||
| if (context_ts_1.context.document && useColour) | ||
| debugfn.logger(`%c${ns(namespace)}%c${start}`, `color: #${(0, colours_ts_1.selectColour)(namespace)[3]}`, "color: inherit", ...data); | ||
@@ -54,4 +57,23 @@ else { | ||
| debugfn.enabled = exports.namespaces.check(namespace); | ||
| debugfn.logger = debug; | ||
| debugfn.logger = pick("debug"); | ||
| debugfn.panic = function panic(...data) { | ||
| const alertmsg = "PANIC! " + data.join(" "); | ||
| if ((0, env_ts_1.env)("W_PANIC_THROWS")) | ||
| throw new Error(alertmsg); | ||
| try { | ||
| debugfn.logger = pick("error"); | ||
| debugfn.enabled = true; | ||
| debugfn("PANIC! " + (data.shift() ?? ""), ...data, "\n"); | ||
| debugfn.logger(new Error()); | ||
| } | ||
| catch { } | ||
| debugger; | ||
| for (;;) | ||
| try { | ||
| context_ts_1.context.process?.exit(1); | ||
| context_ts_1.context.alert?.(alertmsg); | ||
| } | ||
| catch { } | ||
| }; | ||
| return debugfn; | ||
| } |
+1
-1
| { | ||
| "name": "w", | ||
| "version": "2.2.1", | ||
| "version": "2.3.0", | ||
| "homepage": "https://github.com/feathers-studio/wiretap", | ||
@@ -5,0 +5,0 @@ "repository": { |
+27
-0
@@ -100,2 +100,21 @@ <div align="center"> | ||
| ### Panic | ||
| Each logger instance includes a `panic` method that can be used for critical errors that should halt execution completely: | ||
| ```ts | ||
| const log = w("app:critical"); | ||
| log.panic("Fatal error occurred", { error }); // This will never return | ||
| ``` | ||
| By default, panic will: | ||
| 1. Log the error message to stderr | ||
| 2. Print a stack trace | ||
| 3. Trigger a debugger break | ||
| 4. Attempt to exit the process or show an alert (in browsers) | ||
| 5. Fallback to infinite loop | ||
| You can configure panic to throw an error instead by setting the `W_PANIC_THROWS=1` environment variable. | ||
| ### Programmatic Control | ||
@@ -124,2 +143,10 @@ | ||
| ### Colour Configuration | ||
| By default, `w`iretap will use colours in environments that support it. `w`iretap will read the following environment variables (in order of precedence): | ||
| - `FORCE_COLOR`: Force enable coloured output | ||
| - `NO_COLOR`: Disable coloured output | ||
| - `CI`: Disable coloured output in CI environments | ||
| ## Supported Environments: | ||
@@ -126,0 +153,0 @@ |
| "use strict"; | ||
| // type-safe way to access global values that may not be available in all runtimes | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.context = void 0; | ||
| exports.context = globalThis; |
11952
17.73%166
15.28%157
20.77%