5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-15 16:39:32 +08:00

SetLogLevel fully supported

This commit is contained in:
Lea Anthony 2020-10-12 06:56:51 +11:00
parent 39c599d2de
commit c165b97d57
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
3 changed files with 33 additions and 17 deletions

View File

@ -16,10 +16,6 @@
var id = "Logging";
$: () => {
console.log("Loglevel:", $logLevel)
}
function sendLogMessage() {
if( message.length > 0 ) {
if( isJs ) {
@ -55,7 +51,7 @@
<input type="text" class="form-control" id="{id}-message" placeholder="Hello World!" bind:value="{message}" required="required">
</div>
<input class="btn btn-primary" type="button" on:click="{sendLogMessage}" value="Call {lang} method">
<input class="btn btn-primary" type="button" on:click="{sendLogMessage}" value="Log using {lang} runtime">
</form>
</div>
</CodeBlock>

View File

@ -1,4 +1,6 @@
<script>
import FakeTerm from '../../components/FakeTerm.svelte';
import Link from '../../components/Link.svelte';
import Log from './Log/Log.svelte';
import SetLogLevel from './SetLogLevel/SetLogLevel.svelte';
@ -8,23 +10,29 @@
<div>
<h4>Logging</h4>
Logging is part of the Wails Runtime and is accessed through the <code>runtime.Log</code> object. There are {loglevels.length} methods available:
Logging is part of the Wails Runtime and is accessed through the <code>runtime.Log</code> object.
<ul class="list">
There are {loglevels.length} methods available:
<ol class="list">
{#each loglevels as option}
<li>{option}</li>
{/each}
</ul>
</ol>
<br/>
The default logger will log all messages to the console EG:<br/>
<pre>
Logs are only output if they are above or equal to the current log level. Example: If the current log level is
<code>Info</code>, then <code>Trace</code> and <code>Debug</code> messages will be surpressed. <br/>
<code>Fatal</code> will log the message and then immediately exit the program.<br/>
<code>Print</code> will send a raw message to the log. You can use <code>Print</code> at any log level.<br/>
The default logger will log messages to the console in the following format:<br/>
<FakeTerm>
INFO | I am an Info message
ERROR | I am an Error message
WARN | I am a Warning message
</pre>
<code>Fatal</code> will print the message and then immediately exit the program.
</FakeTerm>
Custom loggers may be given to your Wails application. More details <Link href="https://www.google.com">here</Link>.
<div style="padding: 15px"></div>

View File

@ -2,19 +2,30 @@
import CodeBlock from '../../../components/CodeBlock.svelte';
import { logLevel } from '../../../Store';
import { Log } from '@wails/runtime';
import jsCode from './code.jsx';
import goCode from './code.go';
var options = ["Trace", "Debug", "Info", "Warning", "Error"];
let isJs = false;
var id = "SetLogLevel";
let loglevelText = options[$logLevel];
$: logLevel.set(options.indexOf(loglevelText));
$: setLogLevelMethod = isJs ? Log.SetLogLevel : backend.main.Logger.SetLogLevel;
function setLogLevel() {
let logLevelUpper = loglevelText.toUpperCase();
let logLevelNumber = Log.Level[logLevelUpper];
setLogLevelMethod(logLevelNumber);
};
$: lang = isJs ? 'Javascript' : 'Go';
let description = `You can set the log level using Log.SetLogLevel(). It accepts a log level (number) but the log levels supported have been added to Log: Log.TRACE
`;
</script>
<CodeBlock {jsCode} {goCode} title="SetLogLevel" {id}>
<CodeBlock bind:isJs={isJs} {jsCode} {goCode} title="SetLogLevel" {id} {description}>
<div class="logging-form">
<form data-wails-no-drag class="w-500 mw-full">
<!-- Radio -->
@ -27,6 +38,7 @@
</div>
{/each}
</div>
<input class="btn btn-primary" type="button" on:click="{setLogLevel}" value="SetLogLevel using {lang} runtime">
</form>
</div>
</CodeBlock>