Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by mail.sr.ht (Postfix) with ESMTPS id 5852F401CF for <~eliasnaur/gio-patches@lists.sr.ht>; Fri, 10 Jan 2020 17:12:42 +0000 (UTC) Authentication-Results: mail.sr.ht; dkim=pass (2048-bit key) header.d=eliasnaur.com header.i=@eliasnaur.com header.b=eNIGOzMI Received: by mail-ed1-f68.google.com with SMTP id t17so2224507eds.6 for <~eliasnaur/gio-patches@lists.sr.ht>; Fri, 10 Jan 2020 09:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eliasnaur.com; s=google; h=content-transfer-encoding:in-reply-to:date:subject:from:to:cc :message-id; bh=YRdIWMuN1JdK0lLmLOOG3mVfB/HSMd7a5NdmHQgeEh8=; b=eNIGOzMIzeM8Eq7WuXEwHqu+Fruo6qKqL2eXcyAd1zBRUkBlcYw5LFhldMRnADZc5r itjm4dJW4ECkEizPPTzm94YgxSQZjjpvQbyManV3uSPfdZqAxeQrBXheaX4LOXZBwi3p Zv00uceU7lWT8N6V9qZWrbUhLsMUPZvaIy8Hq/yHebww06BXozQdQaqihHGa1O7vuqPU QicRDskaXPA64wJ7ztDcGmss3n2lfI+ZUcLhIaU4efgBNntB7ZmbyNXyANIOL/tO7XTw Duj08Mknj4mYYYCeSD4KyEEKuZqhmfgwQnmT4tFtdDkbwDrcKv1lYAwte6jmG42+GKkI gEkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:in-reply-to:date :subject:from:to:cc:message-id; bh=YRdIWMuN1JdK0lLmLOOG3mVfB/HSMd7a5NdmHQgeEh8=; b=oS3TUBEptKTRfrC5bi5+KRnX9m/3LOnOiu8ZAkrDOVTzNxRPqglBx0x9c+GCohSbN/ t21f4fec+9fm0/6hfq+N+jrhd8tN9bZiXbP85mxXuvZJ0tqf0tMdcIzgmfVyxF4HhGkm 3BPUPeJ0sHGsqNZqMulCg7GG0lkP5ZgPFZFQryf/HuoZuRSw09lR/WcOt5LYL6WCDFC2 hRmz2xD75P0QZnw/UB95l+5oMwtbES5kJfcQovbfHcsd47PZJ3VLpGGaeJS/zWBqTWsj N4hCFuwI/5WYsCk1riwU3xgHm6nd8Jumm9sn0wziYUkDvVGg9DBGh9LBnlJ5G+bwtoF7 IaSw== X-Gm-Message-State: APjAAAXw7ZgtY5rHFMZX/+riPECpRXdBNNYXn5ABiH6RuyTMxHgRtt2w 3BT3HUQVYPOSaluD4qGLS8sS1w== X-Google-Smtp-Source: APXvYqwg7JRQi0MimeTvgPV2oQkLimHnKx3vcAPlxzVgFgIM3iUK1eropeWlHTx08OpCs1WV+unYeQ== X-Received: by 2002:a05:6402:2052:: with SMTP id bc18mr4627075edb.161.1578676361347; Fri, 10 Jan 2020 09:12:41 -0800 (PST) Received: from localhost ([145.255.60.245]) by smtp.gmail.com with ESMTPSA id 2sm59944edv.87.2020.01.10.09.12.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2020 09:12:40 -0800 (PST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 In-Reply-To: <20200110144548.34087-1-mural@ctli.io> Date: Fri, 10 Jan 2020 18:10:50 +0100 Subject: Re: [gio] app/internal/log: add logger for Windows DebugView From: "Elias Naur" To: "mural" , <~eliasnaur/gio-patches@lists.sr.ht> Cc: "mural" Message-Id: On Fri Jan 10, 2020 at 22:45, mural wrote: > Signed-off-by: mural > --- > app/internal/log/log_windows.go | 41 +++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > create mode 100644 app/internal/log/log_windows.go > > diff --git a/app/internal/log/log_windows.go b/app/internal/log/log_windo= ws.go > new file mode 100644 > index 0000000..2019bcd > --- /dev/null > +++ b/app/internal/log/log_windows.go > @@ -0,0 +1,41 @@ > +// SPDX-License-Identifier: Unlicense OR MIT > + > +package log > + > +import ( > + "io" > + "log" > + "os" > + "syscall" > + "unsafe" > +) > + > +type logger struct{} > + > +var ( > + kernel32 =3D syscall.NewLazyDLL("kernel32") > + outputDebugStringW =3D kernel32.NewProc("OutputDebugStringW") > + debugView *logger > +) > + > +func init() { > + // Windows DebugView already includes timestamps. > + log.SetFlags(log.Flags() &^ log.LstdFlags) > + > + var out io.Writer > + if syscall.Stderr !=3D syscall.InvalidHandle { Did you test the change? From my manual testing, syscall.Stderr is never equal to syscall.InvalidHandle when building with `-ldflags=3D"-H windowsgui"`. Regardless, you shouldn't set the logger to os.Stderr here. Just leave it alone and return early. > + out =3D os.Stderr > + } else { > + out =3D debugView > + } > + log.SetOutput(out) > +} > + > +func (l *logger) Write(buf []byte) (int, error) { > + p, err :=3D syscall.UTF16PtrFromString(string(buf)) > + if err !=3D nil { > + return 0, err > + } > + outputDebugStringW.Call(uintptr(unsafe.Pointer(p))) > + return len(buf), nil > +} > --=20 > 2.19.1