mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-21 11:26:15 +02:00
fix(log): strip ansi color/escape codes from browser console output
Co-authored-by: Angus Peart <angusp@gmail.com>
This commit is contained in:
+168
-164
@@ -6,170 +6,174 @@ async function a(i){return c$1("tauri",i)}
|
||||
|
||||
var W={};e(W,{TauriEvent:()=>c,emit:()=>D,listen:()=>E,once:()=>_});async function s(n,t){return a({__tauriModule:"Event",message:{cmd:"unlisten",event:n,eventId:t}})}async function m(n,t,i){await a({__tauriModule:"Event",message:{cmd:"emit",event:n,windowLabel:t,payload:i}});}async function o(n,t,i){return a({__tauriModule:"Event",message:{cmd:"listen",event:n,windowLabel:t,handler:s$1(i)}}).then(r=>async()=>s(n,r))}async function u(n,t,i){return o(n,t,r=>{i(r),s(n,r.id).catch(()=>{});})}var c=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e.CHECK_UPDATE="tauri://update",e.UPDATE_AVAILABLE="tauri://update-available",e.INSTALL_UPDATE="tauri://update-install",e.STATUS_UPDATE="tauri://update-status",e.DOWNLOAD_PROGRESS="tauri://update-download-progress",e))(c||{});async function E(n,t){return o(n,null,t)}async function _(n,t){return u(n,null,t)}async function D(n,t){return m(n,void 0,t)}
|
||||
|
||||
var LogLevel;
|
||||
(function (LogLevel) {
|
||||
/**
|
||||
* The "trace" level.
|
||||
*
|
||||
* Designates very low priority, often extremely verbose, information.
|
||||
*/
|
||||
LogLevel[LogLevel["Trace"] = 1] = "Trace";
|
||||
/**
|
||||
* The "debug" level.
|
||||
*
|
||||
* Designates lower priority information.
|
||||
*/
|
||||
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
||||
/**
|
||||
* The "info" level.
|
||||
*
|
||||
* Designates useful information.
|
||||
*/
|
||||
LogLevel[LogLevel["Info"] = 3] = "Info";
|
||||
/**
|
||||
* The "warn" level.
|
||||
*
|
||||
* Designates hazardous situations.
|
||||
*/
|
||||
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
||||
/**
|
||||
* The "error" level.
|
||||
*
|
||||
* Designates very serious errors.
|
||||
*/
|
||||
LogLevel[LogLevel["Error"] = 5] = "Error";
|
||||
})(LogLevel || (LogLevel = {}));
|
||||
async function log(level, message, options) {
|
||||
var _a, _b;
|
||||
const traces = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((line) => line.split("@"));
|
||||
const filtered = traces === null || traces === void 0 ? void 0 : traces.filter(([name, location]) => {
|
||||
return name.length > 0 && location !== "[native code]";
|
||||
});
|
||||
const { file, line, ...keyValues } = options !== null && options !== void 0 ? options : {};
|
||||
await c$1("plugin:log|log", {
|
||||
level,
|
||||
message,
|
||||
location: (_b = filtered === null || filtered === void 0 ? void 0 : filtered[0]) === null || _b === void 0 ? void 0 : _b.filter((v) => v.length > 0).join("@"),
|
||||
file,
|
||||
line,
|
||||
keyValues,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Logs a message at the error level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { error } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const err_info = "No connection";
|
||||
* const port = 22;
|
||||
*
|
||||
* error(`Error: ${err_info} on port ${port}`);
|
||||
* ```
|
||||
*/
|
||||
async function error(message, options) {
|
||||
await log(LogLevel.Error, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the warn level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { warn } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const warn_description = "Invalid Input";
|
||||
*
|
||||
* warn(`Warning! {warn_description}!`);
|
||||
* ```
|
||||
*/
|
||||
async function warn(message, options) {
|
||||
await log(LogLevel.Warn, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the info level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { info } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const conn_info = { port: 40, speed: 3.20 };
|
||||
*
|
||||
* info(`Connected to port {conn_info.port} at {conn_info.speed} Mb/s`);
|
||||
* ```
|
||||
*/
|
||||
async function info(message, options) {
|
||||
await log(LogLevel.Info, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the debug level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { debug } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* debug(`New position: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function debug(message, options) {
|
||||
await log(LogLevel.Debug, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the trace level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { trace } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* let pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* trace(`Position is: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function trace(message, options) {
|
||||
await log(LogLevel.Trace, message, options);
|
||||
}
|
||||
async function attachConsole() {
|
||||
return await E("log://log", (event) => {
|
||||
const payload = event.payload;
|
||||
switch (payload.level) {
|
||||
case LogLevel.Trace:
|
||||
console.log(payload.message);
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
console.debug(payload.message);
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
console.info(payload.message);
|
||||
break;
|
||||
case LogLevel.Warn:
|
||||
console.warn(payload.message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
console.error(payload.message);
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(`unknown log level ${payload.level}`);
|
||||
}
|
||||
});
|
||||
var LogLevel;
|
||||
(function (LogLevel) {
|
||||
/**
|
||||
* The "trace" level.
|
||||
*
|
||||
* Designates very low priority, often extremely verbose, information.
|
||||
*/
|
||||
LogLevel[LogLevel["Trace"] = 1] = "Trace";
|
||||
/**
|
||||
* The "debug" level.
|
||||
*
|
||||
* Designates lower priority information.
|
||||
*/
|
||||
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
||||
/**
|
||||
* The "info" level.
|
||||
*
|
||||
* Designates useful information.
|
||||
*/
|
||||
LogLevel[LogLevel["Info"] = 3] = "Info";
|
||||
/**
|
||||
* The "warn" level.
|
||||
*
|
||||
* Designates hazardous situations.
|
||||
*/
|
||||
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
||||
/**
|
||||
* The "error" level.
|
||||
*
|
||||
* Designates very serious errors.
|
||||
*/
|
||||
LogLevel[LogLevel["Error"] = 5] = "Error";
|
||||
})(LogLevel || (LogLevel = {}));
|
||||
async function log(level, message, options) {
|
||||
var _a, _b;
|
||||
const traces = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((line) => line.split("@"));
|
||||
const filtered = traces === null || traces === void 0 ? void 0 : traces.filter(([name, location]) => {
|
||||
return name.length > 0 && location !== "[native code]";
|
||||
});
|
||||
const { file, line, ...keyValues } = options !== null && options !== void 0 ? options : {};
|
||||
await c$1("plugin:log|log", {
|
||||
level,
|
||||
message,
|
||||
location: (_b = filtered === null || filtered === void 0 ? void 0 : filtered[0]) === null || _b === void 0 ? void 0 : _b.filter((v) => v.length > 0).join("@"),
|
||||
file,
|
||||
line,
|
||||
keyValues,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Logs a message at the error level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { error } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const err_info = "No connection";
|
||||
* const port = 22;
|
||||
*
|
||||
* error(`Error: ${err_info} on port ${port}`);
|
||||
* ```
|
||||
*/
|
||||
async function error(message, options) {
|
||||
await log(LogLevel.Error, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the warn level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { warn } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const warn_description = "Invalid Input";
|
||||
*
|
||||
* warn(`Warning! {warn_description}!`);
|
||||
* ```
|
||||
*/
|
||||
async function warn(message, options) {
|
||||
await log(LogLevel.Warn, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the info level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { info } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const conn_info = { port: 40, speed: 3.20 };
|
||||
*
|
||||
* info(`Connected to port {conn_info.port} at {conn_info.speed} Mb/s`);
|
||||
* ```
|
||||
*/
|
||||
async function info(message, options) {
|
||||
await log(LogLevel.Info, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the debug level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { debug } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* debug(`New position: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function debug(message, options) {
|
||||
await log(LogLevel.Debug, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the trace level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { trace } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* let pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* trace(`Position is: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function trace(message, options) {
|
||||
await log(LogLevel.Trace, message, options);
|
||||
}
|
||||
async function attachConsole() {
|
||||
return await E("log://log", (event) => {
|
||||
const payload = event.payload;
|
||||
// Strip ANSI escape codes
|
||||
const message = payload.message.replace(
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
||||
switch (payload.level) {
|
||||
case LogLevel.Trace:
|
||||
console.log(message);
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
console.debug(message);
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
console.info(message);
|
||||
break;
|
||||
case LogLevel.Warn:
|
||||
console.warn(message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
console.error(message);
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(`unknown log level ${payload.level}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { attachConsole, debug, error, info, trace, warn };
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+168
-164
@@ -1,170 +1,174 @@
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
|
||||
var LogLevel;
|
||||
(function (LogLevel) {
|
||||
/**
|
||||
* The "trace" level.
|
||||
*
|
||||
* Designates very low priority, often extremely verbose, information.
|
||||
*/
|
||||
LogLevel[LogLevel["Trace"] = 1] = "Trace";
|
||||
/**
|
||||
* The "debug" level.
|
||||
*
|
||||
* Designates lower priority information.
|
||||
*/
|
||||
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
||||
/**
|
||||
* The "info" level.
|
||||
*
|
||||
* Designates useful information.
|
||||
*/
|
||||
LogLevel[LogLevel["Info"] = 3] = "Info";
|
||||
/**
|
||||
* The "warn" level.
|
||||
*
|
||||
* Designates hazardous situations.
|
||||
*/
|
||||
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
||||
/**
|
||||
* The "error" level.
|
||||
*
|
||||
* Designates very serious errors.
|
||||
*/
|
||||
LogLevel[LogLevel["Error"] = 5] = "Error";
|
||||
})(LogLevel || (LogLevel = {}));
|
||||
async function log(level, message, options) {
|
||||
var _a, _b;
|
||||
const traces = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((line) => line.split("@"));
|
||||
const filtered = traces === null || traces === void 0 ? void 0 : traces.filter(([name, location]) => {
|
||||
return name.length > 0 && location !== "[native code]";
|
||||
});
|
||||
const { file, line, ...keyValues } = options !== null && options !== void 0 ? options : {};
|
||||
await invoke("plugin:log|log", {
|
||||
level,
|
||||
message,
|
||||
location: (_b = filtered === null || filtered === void 0 ? void 0 : filtered[0]) === null || _b === void 0 ? void 0 : _b.filter((v) => v.length > 0).join("@"),
|
||||
file,
|
||||
line,
|
||||
keyValues,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Logs a message at the error level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { error } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const err_info = "No connection";
|
||||
* const port = 22;
|
||||
*
|
||||
* error(`Error: ${err_info} on port ${port}`);
|
||||
* ```
|
||||
*/
|
||||
async function error(message, options) {
|
||||
await log(LogLevel.Error, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the warn level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { warn } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const warn_description = "Invalid Input";
|
||||
*
|
||||
* warn(`Warning! {warn_description}!`);
|
||||
* ```
|
||||
*/
|
||||
async function warn(message, options) {
|
||||
await log(LogLevel.Warn, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the info level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { info } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const conn_info = { port: 40, speed: 3.20 };
|
||||
*
|
||||
* info(`Connected to port {conn_info.port} at {conn_info.speed} Mb/s`);
|
||||
* ```
|
||||
*/
|
||||
async function info(message, options) {
|
||||
await log(LogLevel.Info, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the debug level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { debug } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* debug(`New position: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function debug(message, options) {
|
||||
await log(LogLevel.Debug, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the trace level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { trace } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* let pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* trace(`Position is: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function trace(message, options) {
|
||||
await log(LogLevel.Trace, message, options);
|
||||
}
|
||||
async function attachConsole() {
|
||||
return await listen("log://log", (event) => {
|
||||
const payload = event.payload;
|
||||
switch (payload.level) {
|
||||
case LogLevel.Trace:
|
||||
console.log(payload.message);
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
console.debug(payload.message);
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
console.info(payload.message);
|
||||
break;
|
||||
case LogLevel.Warn:
|
||||
console.warn(payload.message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
console.error(payload.message);
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(`unknown log level ${payload.level}`);
|
||||
}
|
||||
});
|
||||
var LogLevel;
|
||||
(function (LogLevel) {
|
||||
/**
|
||||
* The "trace" level.
|
||||
*
|
||||
* Designates very low priority, often extremely verbose, information.
|
||||
*/
|
||||
LogLevel[LogLevel["Trace"] = 1] = "Trace";
|
||||
/**
|
||||
* The "debug" level.
|
||||
*
|
||||
* Designates lower priority information.
|
||||
*/
|
||||
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
||||
/**
|
||||
* The "info" level.
|
||||
*
|
||||
* Designates useful information.
|
||||
*/
|
||||
LogLevel[LogLevel["Info"] = 3] = "Info";
|
||||
/**
|
||||
* The "warn" level.
|
||||
*
|
||||
* Designates hazardous situations.
|
||||
*/
|
||||
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
||||
/**
|
||||
* The "error" level.
|
||||
*
|
||||
* Designates very serious errors.
|
||||
*/
|
||||
LogLevel[LogLevel["Error"] = 5] = "Error";
|
||||
})(LogLevel || (LogLevel = {}));
|
||||
async function log(level, message, options) {
|
||||
var _a, _b;
|
||||
const traces = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((line) => line.split("@"));
|
||||
const filtered = traces === null || traces === void 0 ? void 0 : traces.filter(([name, location]) => {
|
||||
return name.length > 0 && location !== "[native code]";
|
||||
});
|
||||
const { file, line, ...keyValues } = options !== null && options !== void 0 ? options : {};
|
||||
await invoke("plugin:log|log", {
|
||||
level,
|
||||
message,
|
||||
location: (_b = filtered === null || filtered === void 0 ? void 0 : filtered[0]) === null || _b === void 0 ? void 0 : _b.filter((v) => v.length > 0).join("@"),
|
||||
file,
|
||||
line,
|
||||
keyValues,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Logs a message at the error level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { error } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const err_info = "No connection";
|
||||
* const port = 22;
|
||||
*
|
||||
* error(`Error: ${err_info} on port ${port}`);
|
||||
* ```
|
||||
*/
|
||||
async function error(message, options) {
|
||||
await log(LogLevel.Error, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the warn level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { warn } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const warn_description = "Invalid Input";
|
||||
*
|
||||
* warn(`Warning! {warn_description}!`);
|
||||
* ```
|
||||
*/
|
||||
async function warn(message, options) {
|
||||
await log(LogLevel.Warn, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the info level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { info } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const conn_info = { port: 40, speed: 3.20 };
|
||||
*
|
||||
* info(`Connected to port {conn_info.port} at {conn_info.speed} Mb/s`);
|
||||
* ```
|
||||
*/
|
||||
async function info(message, options) {
|
||||
await log(LogLevel.Info, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the debug level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { debug } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* const pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* debug(`New position: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function debug(message, options) {
|
||||
await log(LogLevel.Debug, message, options);
|
||||
}
|
||||
/**
|
||||
* Logs a message at the trace level.
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```js
|
||||
* import { trace } from 'tauri-plugin-log-api';
|
||||
*
|
||||
* let pos = { x: 3.234, y: -1.223 };
|
||||
*
|
||||
* trace(`Position is: x: {pos.x}, y: {pos.y}`);
|
||||
* ```
|
||||
*/
|
||||
async function trace(message, options) {
|
||||
await log(LogLevel.Trace, message, options);
|
||||
}
|
||||
async function attachConsole() {
|
||||
return await listen("log://log", (event) => {
|
||||
const payload = event.payload;
|
||||
// Strip ANSI escape codes
|
||||
const message = payload.message.replace(
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
||||
switch (payload.level) {
|
||||
case LogLevel.Trace:
|
||||
console.log(message);
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
console.debug(message);
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
console.info(message);
|
||||
break;
|
||||
case LogLevel.Warn:
|
||||
console.warn(message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
console.error(message);
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(`unknown log level ${payload.level}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { attachConsole, debug, error, info, trace, warn };
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAQA,IAAK,QA+BJ,CAAA;AA/BD,CAAA,UAAK,QAAQ,EAAA;AACX;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS,CAAA;AACT;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAK,CAAA;AACL;;;;AAIG;AACH,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA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C,CAAC;gBACrB,MAAM;YACR,KAAK,QAAQ,CAAC,KAAK;AACjB,gBAAA,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACvB,MAAM;YACR,KAAK,QAAQ,CAAC,IAAI;AAChB,gBAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACtB,MAAM;YACR,KAAK,QAAQ,CAAC,IAAI;AAChB,gBAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACtB,MAAM;YACR,KAAK,QAAQ,CAAC,KAAK;AACjB,gBAAA,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACvB,MAAM;AACR,YAAA;;gBAEE,MAAM,IAAI,KAAK,CAAC,CAAA,kBAAA,EAAqB,OAAO,CAAC,KAAK,CAAE,CAAA,CAAC,CAAC;AACzD,SAAA;AACH,KAAC,CAAC,CAAC;AACL;;;;"}
|
||||
@@ -182,21 +182,28 @@ export async function attachConsole(): Promise<UnlistenFn> {
|
||||
return await listen("log://log", (event) => {
|
||||
const payload = event.payload as RecordPayload;
|
||||
|
||||
// Strip ANSI escape codes
|
||||
const message = payload.message.replace(
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
||||
""
|
||||
);
|
||||
|
||||
switch (payload.level) {
|
||||
case LogLevel.Trace:
|
||||
console.log(payload.message);
|
||||
console.log(message);
|
||||
break;
|
||||
case LogLevel.Debug:
|
||||
console.debug(payload.message);
|
||||
console.debug(message);
|
||||
break;
|
||||
case LogLevel.Info:
|
||||
console.info(payload.message);
|
||||
console.info(message);
|
||||
break;
|
||||
case LogLevel.Warn:
|
||||
console.warn(payload.message);
|
||||
console.warn(message);
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
console.error(payload.message);
|
||||
console.error(message);
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
|
||||
Reference in New Issue
Block a user