From 638ea8fd17fe23fd164fd095954883c7a3e110a4 Mon Sep 17 00:00:00 2001 From: ncpa0cpl Date: Thu, 19 Dec 2024 16:17:11 +0100 Subject: [PATCH] docs: added doc on the console --- docs/console.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 docs/console.md diff --git a/docs/console.md b/docs/console.md new file mode 100644 index 0000000..94faea5 --- /dev/null +++ b/docs/console.md @@ -0,0 +1,45 @@ +# Console + +React GTK extends the built-in console. It enhances the printed output as well as adds a few non-standard +methods. + +## console.setPretty(boolean) + +By default, when in production mode this settings is disabled, and enabled in the development mode. +This setting can be changed by calling `console.setPretty(true)` or `console.setPretty(false)`. + +When enabled, the console will print the output with ANSII colors in the log labels, error messages, +stack traces and object representations. + +## console.setMaxDepth(number) + +By default this is set to 0, which means no limit. + +This settings determines, when printing an object, how deep the object should be printed. If the +object is nested deeper than the specified depth, the output will be truncated. + +## console.mapStackTrace(string) + +The stack traces of all error will contain only paths to the bundle file, making it hard to debug +the code. So when printing the console will use the source maps (if enabled) to map each line of +the error's stack traces to rhe corresponding source file. + +This function allows you to do that same mapping manually, without printing it out. This can be useful +when you want to save that trace to a log file or send ir to a Monitoring Service like DataDog, Sentry, etc. + +## console.formatStackTrace(string) + +This function will format the stack trace in the same manner as if it was printed to the console. It +will add the ANSII coloring if the pretty setting is enabled. + +## console.format(any) + +This function will format the object in the same manner as if it was printed to the console and return it +as a string. It respects the same settings as all the printing functions (like setPretty or setMaxDepth.) + +## console.onLogPrinted(Callback) + +This function allows you to listen to all the logs that are printed to the console. This is an alternative to +overriding the console.log function. Note however that this will not capture logs that are emitted outside +of the application code and it's dependencies. If you want to capture all logs, you should look into the +`GLib.log_set_writer_func` function. (note 2: GLib loggin is used by React GTK only in the production mode.)