mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
fe1df00d02
Signed-off-by: Elias Naur <mail@eliasnaur.com>
35 lines
655 B
Go
35 lines
655 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"log"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
type logger struct{}
|
|
|
|
var (
|
|
kernel32 = syscall.NewLazyDLL("kernel32")
|
|
outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
|
|
debugView *logger
|
|
)
|
|
|
|
func init() {
|
|
// Windows DebugView already includes timestamps.
|
|
if syscall.Stderr == 0 {
|
|
log.SetFlags(log.Flags() &^ log.LstdFlags)
|
|
log.SetOutput(debugView)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|