Skip to content

Log example from Imguidemo #756

Answered by gucio321
viduq asked this question in Q&A
Feb 1, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

IDK if you can enable this anyhow, but you can easily implement that mechanism. Here is the code:

package main

import (
	"io"
	"log"
	"os"

	"github.com/AllenDang/giu"
)

var giuLogger = &GiuLogger{}

var _ io.Writer = &GiuLogger{}

type GiuLogger struct {
	buffer string
}

func (g *GiuLogger) Write(p []byte) (int, error) {
	g.buffer = string(p) + g.buffer
	return os.Stdout.Write(p)
}

func loop() {
	giu.SingleWindow().Layout(
		giu.Row(
			giu.Button("Log message 1").OnClick(func() {
				log.Print("[INFO] HI!!!")
			}),
			giu.Button("Log message 2").OnClick(func() {
				log.Print("[ERROR] THIS is a log example!")
			}),
		),
		giu.InputTextMultiline(&giuLogger.buffer).Flags(giu.InputTe…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@viduq
Comment options

Answer selected by viduq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants