Merges log records with currently stored. Windows in neutralino work as separate processes, so Debug class in the main window will be different from Debug class in the about window. So, to have a complete log from all the windows, you should send them by, for example, IPC.write() method to your main window, and then merge it by this method
About window
import { Debug, IPC } from'@empathize/framework';declareconstNeutralino;// This event will be called before window closing// Be careful because this event works only when// exitProcessOnClose = falseNeutralino.events.on('windowClose',async () => {// Wait before it will be storedawaitIPC.write({ type:'log', log:Debug.getRecords() });// And then we need to manually close this processNeutralino.app.exit();});
Main window
import { Debug, IPC } from'@empathize/framework';IPC.read().then((records) => {records.forEach((record) => {if (record.data.type ==='log') {// And don't forget to call .pop() method// to remove this record from the IPC.read() poolDebug.merge(record.pop().data.log); } });});
Debug.getRecords()
System class that used primarily with Debug.merge()
Debug.get()
Returns list of strings
import { Debug, fs, path, dir } from'@empathize/framework';constpathToFile=path.join(dir.app,'logs',`${Debug.startedAt}.log`);constdebugLog=Debug.get().join('\r\n');fs.write(pathToFile, debugLog);
Debug.handler(callback)
import { Debug } from'@empathize/framework';Debug.handler((record) => {console.log(`Made new log record:\r\n${record.log.join('\r\n')}`);});
Debug.loggable(func)
This method will return a new function that will log some user-specified strings at the start and at the end of its work
Sync functions
import { Debug } from'@empathize/framework';// sum(1, 2) -> 3letsum= (a:number, b:number):number=> a + b;// Replace this sum function with a new one, generated by Debug.loggable(()// This new function will generate a log at the start and finish of its work// Also <number> can be replaced with <ReturnType<typeof sum>>// which is the same, but generates automatically by the TypeScriptsum =Debug.loggable<number>(sum, {// Function name to log function:'sum',// DebugOptions to log at startstart: (thread,...args) =>`Calculating ${args[0]} + ${args[1]}`,// DebugOptions to log at finishfinish: (thread, output) =>`Calculated ${output}`});console.log(`1 + 2 = ${sum(1,2)}`);
Async functions
import { Debug } from'@empathize/framework';// await sum(1, 2) -> 3letsum= (a:number, b:number):Promise<number> => {returnnewPromise((resolve) => {setTimeout(() =>resolve(a + b),3000); });};// Here I use <ReturnType<typeof sum>>, but it also// acceptable to use <Promise<number>>sum =Debug.loggable<ReturnType<typeof sum>>(sum, {// Function name to log function:'sum',// DebugOptions to log at startstart: (thread,...args) =>`Calculating ${args[0]} + ${args[1]}`,// DebugOptions to log at finishfinish: (thread, output) =>`Calculated ${output}`});sum(1,2).then((result) =>console.log(`1 + 2 = ${result}`));
This function is highly useful to generate log generation in your already existing code without modifying it. For example:
import { Debug, Configs } from'@empathize/framework';// We're rewriting Configs.get() function and then// it will automatically generate log outputConfigs.get =Debug.loggable<ReturnType<typeofConfigs.get>>(Configs.get, { function:'Configs.get', context: Configs,start: (thread,...args) =>`Getting ${args[0]} config value`,finish: (thread, output) =>`Resolved value: ${output}`});
Property context means an object or class at which name this function should be called. Because we're making a copy of the original function - this copy will have no access to this, and to manually give this function this value - you should specify its context - parent class or object this function belongs to