~eliasnaur/gio-patches

gio: app/internal/log: add logger for Windows DebugView v1 PROPOSED

~typeless
~typeless: 1
 app/internal/log: add logger for Windows DebugView

 1 files changed, 32 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9493/mbox | git am -3
Learn more about email & git

[PATCH gio] app/internal/log: add logger for Windows DebugView Export this patch

~typeless
From: mural <mural@ctli.io>

Signed-off-by: mural <mural@ctli.io>
---
 app/internal/log/log_windows.go | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 app/internal/log/log_windows.go

diff --git a/app/internal/log/log_windows.go b/app/internal/log/log_windows.go
new file mode 100644
index 0000000..c7691d2
--- /dev/null
+++ b/app/internal/log/log_windows.go
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Unlicense OR MIT

package log

import (
	"log"
	"syscall"
	"unsafe"
)

type logger struct{}

var (
	kernel32           = syscall.NewLazyDLL("kernel32")
	outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
	out                logger
)

func init() {
	// Windows DbgView already includes timestamps.
	log.SetFlags(log.Flags() &^ log.LstdFlags)
	log.SetOutput(&out)
}

func (l *logger) Write(buf []byte) (int, error) {
	p, err := syscall.UTF16PtrFromString(string(buf))
	if err != nil {
		return 0, err
	}
	outputDebugStringW.Call(uintptr(unsafe.Pointer(p)))
	return len(buf), nil
}
-- 
2.24.1
View this thread in the archives