-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to redirect logs to file and open them.
- Loading branch information
1 parent
2cfdcee
commit cbb891a
Showing
5 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
// Neutralino dev patch | ||
// import "$lib/neu/init" | ||
|
||
import './app.css' | ||
import './ts/window' | ||
import App from './App.svelte' | ||
import { init } from "@neutralinojs/lib" | ||
import Integrations from "./pages/Integrations.svelte" | ||
import "./app.css"; | ||
import "./ts/window"; | ||
import "./ts/debugging"; | ||
import App from "./App.svelte"; | ||
import { init } from "@neutralinojs/lib"; | ||
import Integrations from "./pages/Integrations.svelte"; | ||
|
||
init() | ||
init(); | ||
|
||
const app = new App({ | ||
// @ts-expect-error | ||
target: document.getElementById('app'), | ||
}) | ||
// @ts-expect-error | ||
target: document.getElementById("app"), | ||
}); | ||
|
||
export default app | ||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// This serves the purpose of redirecting every console logs to the neutralinojs.log file for debugging on the users' end. | ||
|
||
import { debug } from "@neutralinojs/lib"; | ||
|
||
let isRedirectionEnabled = false; | ||
|
||
function formatConsoleLog(...args: any[]): string { | ||
return args | ||
.map((arg) => { | ||
if (arg === null) { | ||
return "null"; | ||
} else if (arg === undefined) { | ||
return "undefined"; | ||
} else if (typeof arg === "string") { | ||
return arg; | ||
} else if (typeof arg === "number") { | ||
return arg.toString(); | ||
} else if (typeof arg === "boolean") { | ||
return arg.toString(); | ||
} else if (Array.isArray(arg)) { | ||
return JSON.stringify(arg); | ||
} else if (typeof arg === "object") { | ||
return JSON.stringify(arg, getCircularReplacer()); | ||
} else if (typeof arg === "function") { | ||
return arg.toString(); | ||
} else { | ||
return String(arg); | ||
} | ||
}) | ||
.join(" "); | ||
} | ||
|
||
function getCircularReplacer() { | ||
const seen = new WeakSet(); | ||
return (key: string, value: any) => { | ||
if (typeof value === "object" && value !== null) { | ||
if (seen.has(value)) { | ||
return "[Circular]"; | ||
} | ||
seen.add(value); | ||
} | ||
return value; | ||
}; | ||
} | ||
|
||
const originalConsoleLog = console.log; | ||
const originalConsoleError = console.error; | ||
const originalConsoleWarn = console.warn; | ||
const originalConsoleInfo = console.info; | ||
const originalConsoleDebug = console.debug; | ||
|
||
console.log = (...args: any[]) => { | ||
if (isRedirectionEnabled) { | ||
const formattedMessage = formatConsoleLog(...args); | ||
debug.log(formattedMessage); | ||
} | ||
originalConsoleLog.apply(console, args); | ||
}; | ||
|
||
console.error = (...args: any[]) => { | ||
if (isRedirectionEnabled) { | ||
const formattedMessage = formatConsoleLog(...args); | ||
debug.log(formattedMessage); | ||
} | ||
originalConsoleError.apply(console, args); | ||
}; | ||
|
||
console.warn = (...args: any[]) => { | ||
if (isRedirectionEnabled) { | ||
const formattedMessage = formatConsoleLog(...args); | ||
debug.log(formattedMessage); | ||
} | ||
originalConsoleWarn.apply(console, args); | ||
}; | ||
|
||
console.info = (...args: any[]) => { | ||
if (isRedirectionEnabled) { | ||
const formattedMessage = formatConsoleLog(...args); | ||
debug.log(formattedMessage); | ||
} | ||
originalConsoleInfo.apply(console, args); | ||
}; | ||
|
||
console.debug = (...args: any[]) => { | ||
if (isRedirectionEnabled) { | ||
const formattedMessage = formatConsoleLog(...args); | ||
debug.log(formattedMessage); | ||
} | ||
originalConsoleDebug.apply(console, args); | ||
}; | ||
|
||
export function enableConsoleRedirection() { | ||
isRedirectionEnabled = true; | ||
} | ||
|
||
export function disableConsoleRedirection() { | ||
isRedirectionEnabled = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters