5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-09 19:21:02 +08:00

More Logging updates

This commit is contained in:
Lea Anthony 2020-10-12 20:54:33 +11:00
parent 6150010d17
commit 8988f29cea
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
15 changed files with 296 additions and 190 deletions

View File

@ -64,6 +64,17 @@
"resolve": "^1.14.2"
}
},
"@rollup/plugin-url": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-url/-/plugin-url-5.0.1.tgz",
"integrity": "sha512-/dO8Ic+vR9VtMkHjmFBWzISjX0iDwrB3vLg8sy4A7hxu2Uk0J09kAXbtku7gJb1fqVcJUIByFG5d/4sgNh1DvA==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^3.0.4",
"make-dir": "^3.0.0",
"mime": "^2.4.4"
}
},
"@rollup/pluginutils": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz",
@ -124,9 +135,9 @@
}
},
"@wails/runtime": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.2.tgz",
"integrity": "sha512-Af/VqrJz7so3t7tJT83ZxlL7AqgfHIfrIC+ZH80MQsNmcNmYiyB3rwxMxSWCqwmf2iDWUZx7hZ+XfytAPhH8PA==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.3.tgz",
"integrity": "sha512-YfCItPdQ1Gk3AJWpEhnUKdL+eeod9lTtUV697G0q/Y6SnOc86B70S6osvyTCQcQmHVfNVhObpSdaosjWRShupg==",
"dev": true
},
"alphanum-sort": {
@ -1395,6 +1406,15 @@
"sourcemap-codec": "^1.4.4"
}
},
"make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
"integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
"dev": true,
"requires": {
"semver": "^6.0.0"
}
},
"mdn-data": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz",
@ -3198,6 +3218,12 @@
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"serialize-javascript": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz",

View File

@ -10,7 +10,8 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-node-resolve": "^7.0.0",
"@wails/runtime": "^1.0.2",
"@rollup/plugin-url": "^5.0.1",
"@wails/runtime": "^1.0.3",
"focus-visible": "^5.2.0",
"halfmoon": "^1.1.1",
"postcss": "^8.1.1",

View File

@ -6,6 +6,7 @@ import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import autoPreprocess from 'svelte-preprocess';
import { string } from "rollup-plugin-string";
import url from '@rollup/plugin-url';
const production = !process.env.ROLLUP_WATCH;
@ -19,9 +20,18 @@ export default {
},
onwarn: handleRollupWarning,
plugins: [
// Embed binary files
url({
include: ['**/*.woff', '**/*.woff2'],
limit: Infinity,
}),
// Embed text files
string({
include: ["**/*.jsx","**/*.go"],
}),
svelte({
preprocess: autoPreprocess(),
// enable run-time checks when not in production

View File

@ -0,0 +1,119 @@
:root {
--lm-base-body-bg-color: #0000;
--dm-base-body-bg-color: #0000;
--lm-sidebar-bg-color: #0000;
--dm-sidebar-bg-color: #0000;
--dm-sidebar-link-text-color: white;
--dm-sidebar-link-text-color-hover: rgb(255, 214, 0);
--lm-sidebar-link-text-color: black;
--lm-sidebar-link-text-color-hover: rgb(158, 158, 255);
--dm-sidebar-link-text-color-active: rgb(255, 214, 0);
--dm-sidebar-link-text-color-active-hover: rgb(255, 214, 0);
--sidebar-title-font-size: 1.75rem;
--sidebar-brand-font-size: 2.3rem;
--base-font-size: 1.6rem;
/* Switch */
--dm-switch-bg-color: rgb(28,173,213);
--lm-switch-bg-color: rgb(28,173,213);
--dm-switch-bg-color-checked: rgb(186,167,49);
--lm-switch-bg-color-checked: rgb(186,167,49);
--lm-switch-slider-bg-color: #FFF;
--dm-switch-slider-bg-color: #FFF;
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(128,128,128,.25);
border: 2px solid transparent;
border-radius: 10px;
background-clip: padding-box;
}
&:hover {
background-color: rgba(128,128,128,.5);
}
::-webkit-scrollbar-track {
background-color: rgba(128,128,128,0);
}
.sidebar-link {
cursor: pointer;
}
.rhs {
background-color: #333;
}
.inner-content {
position: absolute;
top: 40px;
bottom: 40px;
width: 99%;
overflow-y: auto;
}
.content-wrapper {
overflow: hidden;
}
.dark-content-wrapper {
background-color: #25282c;
}
/*
.sidebar {
background-color: #0000;
} */
.sidebar-brand {
padding-top: 35px;
padding-bottom: 25px;
cursor: pointer;
}
.sidebar-menu {
background-color: #0000;
}
/* Credit: https://stackoverflow.com/a/4407335 */
.noselect {
cursor: default;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
.allow-select {
-webkit-touch-callout: initial; /* iOS Safari */
-webkit-user-select: initial; /* Safari */
-khtml-user-select: initial; /* Konqueror HTML */
-moz-user-select: initial; /* Old versions of Firefox */
-ms-user-select: initial; /* Internet Explorer/Edge */
user-select: initial; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
.list {
margin-top: 2rem;
margin-left: 2rem;
}
.list li {
margin-bottom: 0.5rem;
}
/* * {
font-family: 'Roboto';
} */

View File

@ -68,119 +68,6 @@
<style global>
@import 'halfmoon/css/halfmoon-variables.min.css';
:root {
--lm-base-body-bg-color: #0000;
--dm-base-body-bg-color: #0000;
--lm-sidebar-bg-color: #0000;
--dm-sidebar-bg-color: #0000;
--dm-sidebar-link-text-color: white;
--dm-sidebar-link-text-color-hover: rgb(255, 214, 0);
--lm-sidebar-link-text-color: black;
--lm-sidebar-link-text-color-hover: rgb(158, 158, 255);
--dm-sidebar-link-text-color-active: rgb(255, 214, 0);
--dm-sidebar-link-text-color-active-hover: rgb(255, 214, 0);
--sidebar-title-font-size: 1.75rem;
--sidebar-brand-font-size: 2.3rem;
/* Switch */
--dm-switch-bg-color: rgb(28,173,213);
--lm-switch-bg-color: rgb(28,173,213);
--dm-switch-bg-color-checked: rgb(186,167,49);
--lm-switch-bg-color-checked: rgb(186,167,49);
--lm-switch-slider-bg-color: #FFF;
--dm-switch-slider-bg-color: #FFF;
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(128,128,128,.25);
border: 2px solid transparent;
border-radius: 10px;
background-clip: padding-box;
}
&:hover {
background-color: rgba(128,128,128,.5);
}
::-webkit-scrollbar-track {
background-color: rgba(128,128,128,0);
}
.sidebar-link {
font-weight: bold;
cursor: pointer;
}
.rhs {
background-color: #333;
}
.inner-content {
position: absolute;
top: 40px;
bottom: 40px;
width: 99%;
overflow-y: auto;
}
.content-wrapper {
overflow: hidden;
}
.dark-content-wrapper {
background-color: #25282c;
}
/*
.sidebar {
background-color: #0000;
} */
.sidebar-brand {
padding-top: 35px;
padding-bottom: 25px;
cursor: pointer;
}
.sidebar-menu {
background-color: #0000;
}
/* Credit: https://stackoverflow.com/a/4407335 */
.noselect {
cursor: default;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
.allow-select {
-webkit-touch-callout: initial; /* iOS Safari */
-webkit-user-select: initial; /* Safari */
-khtml-user-select: initial; /* Konqueror HTML */
-moz-user-select: initial; /* Old versions of Firefox */
-ms-user-select: initial; /* Internet Explorer/Edge */
user-select: initial; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
.list {
margin-top: 2rem;
margin-left: 2rem;
}
.list li {
margin-bottom: 0.5rem;
}
/* @import './assets/fonts/roboto.css'; */
@import './App.css';
</style>

File diff suppressed because one or more lines are too long

View File

@ -50,19 +50,9 @@
<div class="description">{description}</div>
{/if}
</div>
<div class="example">
<div class="{showCode ? 'code-title-open' : 'code-title-closed'}" on:click="{toggleExample}" >
<span style="display: inline-block; width: 15px;">{showCode?'▼':'▶'}</span>
Example Code
</div>
{#if showCode}
<Highlight class="allow-select" language="{lang}" {code} style="max-height: 500px;"/>
{/if}
</div>
<div class="run">
<div class="{showRun ? 'run-title-open' : 'run-title-closed'}" on:click="{toggleRun}">
<span style="display: inline-block; width: 15px;">{showRun?'▼':'▶'}</span>
<span style="display: inline-block; width: 10px; font-size: 11px">{showRun?'▼':'▶'}</span>
Try Me!
</div>
{#if showRun}
@ -71,6 +61,15 @@
</div>
{/if}
</div>
<div class="example">
<div class="{showCode ? 'code-title-open' : 'code-title-closed'}" on:click="{toggleExample}" >
<span style="display: inline-block; width: 10px; font-size: 11px">{showCode?'▼':'▶'}</span>
Example Code
</div>
{#if showCode}
<Highlight class="allow-select" language="{lang}" {code} style="max-height: 500px;"/>
{/if}
</div>
</div>
<style>
@ -80,23 +79,29 @@
justify-content: space-between;
border-bottom: 1px solid #5555;
flex-wrap: wrap;
padding-bottom: 10px;
align-items: center;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
}
.title {
font-size: 1.75rem;
font-size: 2rem;
}
.code-title-open {
padding-top: 15px;
padding-bottom: 0;
margin-top: 5px;
margin-bottom: -5px;
padding-left: 5px;
cursor: pointer;
font-size: 1.5rem;
}
.code-title-closed {
padding-top: 15px;
padding-bottom: 5px;
margin-top: 5px;
padding-left: 5px;
cursor: pointer;
font-size: 1.5rem;
}
.run-content-dark {
@ -110,16 +115,20 @@
}
.run-title-open {
margin-top: 15px;
margin-bottom: 15px;
margin-top: 5px;
margin-bottom: 5px;
padding-bottom: 0;
padding-left: 5px;
cursor: pointer;
font-size: 1.5rem;
}
.run-title-closed {
margin-top: 15px;
margin-bottom: 15px;
margin-top: 5px;
margin-bottom: 5px;
padding-left: 5px;
cursor: pointer;
font-size: 1.5rem;
}
.toggle {
@ -129,8 +138,7 @@
.example {
padding-right: 5px;
border-bottom: 1px solid #5555;
padding-bottom: 10px;
border-top: 1px solid #5555;
}
.custom-switch {
@ -142,7 +150,9 @@
background-color: #3F3F4B;
border-radius: 5px;
border: 1px solid #555;
padding: 15px;
padding: 5px;
margin-top: 20px;
margin-bottom: 10px;
}
.codeblock-light {
@ -150,6 +160,8 @@
border-radius: 5px;
border: 1px solid #ccc;
padding: 15px;
margin-top: 20px;
margin-bottom: 10px;
}
.description {

View File

@ -0,0 +1,43 @@
<script>
import { darkMode } from '../Store';
import { Highlight } from "svelte-highlight";
import { go, javascript } from "svelte-highlight/languages";
// Default to Go
export let isJs = false;
// Calculate CSS to use
$: lang = isJs ? javascript : go;
// Calculate Code for code block
export let jsCode = "Hi from JS!";
export let goCode = "Hi from Go!";
$: code = isJs ? jsCode : goCode;
</script>
<div data-wails-no-drag class={$darkMode ? "codeblock" : "codeblock-light"}>
<Highlight class="allow-select" language="{lang}" {code} style="margin: -5px; max-height: 500px; font-size: 13px"/>
</div>
<style>
.codeblock {
background-color: #3F3F4B;
border: 1px solid #555;
padding: 5px;
margin-top: 20px;
margin-bottom: 10px;
}
.codeblock-light {
background-color: #e5e5e5;
border: 1px solid #ccc;
padding: 5px;
margin-top: 20px;
margin-bottom: 10px;
}
</style>

View File

@ -1,6 +1,7 @@
<script>
import { Log } from '@wails/runtime';
import CodeBlock from '../../../components/CodeBlock.svelte';
import CodeSnippet from '../../../components/CodeSnippet.svelte';
import jsCode from './code.jsx';
import goCode from './code.go';
@ -28,13 +29,17 @@
}
}
$: encodedMessage = message.replace(`"`, `“`);
$: testcodeJs = "import { runtime } from '@wails/runtime';\nruntime.Log." + loglevel + "(`" + encodedMessage + "`);";
$: testcodeGo = '// runtime is given through WailsInit()\nruntime.Log.' + loglevel + '("' + encodedMessage + '")';
</script>
<CodeBlock bind:isJs={isJs} {jsCode} {goCode} title="Logging" {id}>
<div class="logging-form">
<form data-wails-no-drag class="w-500 mw-full">
<form data-wails-no-drag class="mw-full">
<div class="form-group">
<label for="Debug">Select Logging Level</label>
<label for="Debug">Select Log Method</label>
{#each loglevels as option, index}
{#if index === $logLevel}
<span style="margin-top: 5px; height: 20px; display: inline-block;"><hr style="width: 270px;display: inline-block; vertical-align: middle; margin-right: 10px"/> Current Log Level </span>
@ -52,6 +57,9 @@
</div>
<input class="btn btn-primary" type="button" on:click="{sendLogMessage}" value="Log using {lang} runtime">
<CodeSnippet bind:isJs={isJs} jsCode={testcodeJs} goCode={testcodeGo}></CodeSnippet>
</form>
</div>
</CodeBlock>

View File

@ -8,13 +8,14 @@ type MyStruct struct {
func (l *MyStruct) WailsInit(runtime *wails.Runtime) error {
message := "Hello World!"
runtime.Log.Print(message)
runtime.Log.Trace(message)
runtime.Log.Debug(message)
runtime.Log.Info(message)
runtime.Log.Warning(message)
runtime.Log.Error(message)
runtime.Log.Fatal(message)
// runtime.Log.Trace(message)
// runtime.Log.Debug(message)
// runtime.Log.Info(message)
// runtime.Log.Warning(message)
// runtime.Log.Error(message)
// runtime.Log.Fatal(message)
l.runtime = runtime
return nil

View File

@ -22,23 +22,23 @@
<br/>
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/>
<code>Info</code>, then <code>Trace</code> and <code>Debug</code> messages will be surpressed. <br/><br/>
<code>Fatal</code> will log the message and then immediately exit the program.<br/><br/>
<code>Print</code> will send a raw message to the log regardless of log level.<br/><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
</FakeTerm>
<br/>
Custom loggers may be given to your Wails application. More details <Link href="https://www.google.com">here</Link>.
<div style="padding: 15px"></div>
<br/><br/>
<Log></Log>
<br/>
<br/><br/>
<SetLogLevel></SetLogLevel>
</div>

View File

@ -1,5 +1,6 @@
<script>
import CodeBlock from '../../../components/CodeBlock.svelte';
import CodeSnippet from '../../../components/CodeSnippet.svelte';
import { logLevel } from '../../../Store';
import { Log } from '@wails/runtime';
@ -23,11 +24,13 @@
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
`;
$: testcodeJs = "import { Log } from '@wails/runtime';\nLog.SetLogLevel(Log.Level." + loglevelText.toUpperCase() + ");";
$: testcodeGo = 'import "github.com/wailsapp/wails/v2/pkg/logger"\n\n// runtime is given through WailsInit()\nruntime.Log.SetLogLevel(logger.' + loglevelText.toUpperCase() + ')';
</script>
<CodeBlock bind:isJs={isJs} {jsCode} {goCode} title="SetLogLevel" {id} {description}>
<div class="logging-form">
<form data-wails-no-drag class="w-500 mw-full">
<form data-wails-no-drag class="mw-full">
<!-- Radio -->
<div class="form-group">
<label for="Debug">Select Logging Level</label>
@ -38,6 +41,7 @@
</div>
{/each}
</div>
<CodeSnippet bind:isJs={isJs} jsCode={testcodeJs} goCode={testcodeGo}></CodeSnippet>
<input class="btn btn-primary" type="button" on:click="{setLogLevel}" value="SetLogLevel using {lang} runtime">
</form>
</div>

View File

@ -1,22 +1,22 @@
package main
// SET LOG LEVEL
import (
wails "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
)
import wails "github.com/wailsapp/wails/v2"
type MyStruct struct {
// Logger struct
type Logger struct {
runtime *wails.Runtime
}
func (l *MyStruct) WailsInit(runtime *wails.Runtime) error {
func (l *Logger) WailsInit(runtime *wails.Runtime) error {
runtime.Log.Print(message)
runtime.Log.Trace(message)
runtime.Log.Debug(message)
runtime.Log.Info(message)
runtime.Log.Warning(message)
runtime.Log.Error(message)
runtime.Log.Fatal(message)
runtime.Log.SetLogLevel(logger.TRACE)
// runtime.Log.SetLogLevel(logger.DEBUG)
// runtime.Log.SetLogLevel(logger.INFO)
// runtime.Log.SetLogLevel(logger.WARNING)
// runtime.Log.SetLogLevel(logger.ERROR)
l.runtime = runtime
return nil

View File

@ -1,20 +1,9 @@
import { Log } from '@wails/runtime';
// SET LOG LEVEL
function doSomeOperation() {
// Do things
let value = doSomething();
Log.Print("A raw message");
Log.Trace("I got: " + value);
Log.Debug("A debug message");
Log.Info("An Info message");
Log.Warning("A Warning message");
Log.Error("An Error message");
}
function abort() {
// Do some things
Log.Fatal("I accidentally the whole application!");
function setLogLevel() {
Log.SetLogLevel(Log.Level.TRACE);
// Log.SetLogLevel(Log.Level.DEBUG);
// Log.SetLogLevel(Log.Level.INFO);
// Log.SetLogLevel(Log.Level.WARNING);
// Log.SetLogLevel(Log.Level.ERROR);
}

View File

@ -16,8 +16,6 @@ func main() {
Height: 768,
MinWidth: 800,
MinHeight: 600,
MaxWidth: 1400,
MaxHeight: 800,
Mac: &mac.Options{
WebviewIsTransparent: true,
WindowBackgroundIsTranslucent: true,