Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by mail.sr.ht (Postfix) with ESMTPS id D1451402AF for <~eliasnaur/gio-patches@lists.sr.ht>; Fri, 10 Jan 2020 17:40:34 +0000 (UTC) Authentication-Results: mail.sr.ht; dkim=pass (2048-bit key) header.d=ctli.io header.i=@ctli.io header.b=YPj2ucXx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oxGu/96a Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 9C0DB5E6; Fri, 10 Jan 2020 12:40:33 -0500 (EST) Received: from imap2 ([10.202.2.52]) by compute5.internal (MEProxy); Fri, 10 Jan 2020 12:40:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ctli.io; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=fm3; bh=yC0GpcgYCbyU6tlKxvpMNoYTMuLhYX+ 41sCaOaenieQ=; b=YPj2ucXxtRB6RZo3NxvMZw+846RDc7TQbNy+6S2rWViGiof RaznmCmbQzFe+hjkYXQmss+ZWJIerr5WvLj7Q2A7F7RiafvOLpufvFxpaKDCwiEp PTUFSbnHvmPjZF/JvRZAfyAIfued68kzqOh2vMzed2xqBXXiz4hJsDZKvptPd4LS sZkfwb6fv8NMLZ1+9umpeoeJgqcQEPVuQyE1pGWBU8tPxN4LKBo+zW/2DfMaEqe8 /I3GbC4ulQ/ersDC2OIJHjF6y48HcB7VWKIpFJR6omFyBi3USU7kr+xZxRlPTJnb BWK9rTi1bsoQubabDtLQr1SqkKUuQCDpEJAPamw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=yC0Gpc gYCbyU6tlKxvpMNoYTMuLhYX+41sCaOaenieQ=; b=oxGu/96aFNT9EhhlbwoDSY A9tTGmHWS0lCO2adadJPQwEq92J/3r5fDLu/wiiMObwhF55eoFtHTLdezRB+ZmKL N8an3SmJdM3EJZE/3927BUQjSiQRwDl4NcuLosIgM+LWq69z5aHShUUO9CVlC8hD mSV5M9W5CvN8bLxqmJoEDpcrl4rw78NtNGsLT+NLUIK1opcUnaArVSNn+2zOi1VZ zi4hvqj8CT6cOSU0biJL/+HqJPXQFhRik/ftvOupdCcED8une9kG7R1vjM4PYckO EvJfSQNBpWfvObPVjcPu7TqFc1id2MrsF3v5iGAr86wt7n/4rWj9avBhgqVPXCLA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeifedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsehttd ertderredtnecuhfhrohhmpehmuhhrrghluceomhhurhgrlhestghtlhhirdhioheqnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehmuhhrrghlsegtthhlihdrihhonecuvehluhhsth gvrhfuihiivgeptd X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 05F1FE00A2; Fri, 10 Jan 2020 12:40:33 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-740-g7d9d84e-fmstable-20200109v1 Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Sat, 11 Jan 2020 01:42:03 +0800 From: mural To: "Elias Naur" , ~eliasnaur/gio-patches@lists.sr.ht Subject: Re: [gio] app/internal/log: add logger for Windows DebugView Content-Type: text/plain It's strange that I was struggling with git-send-email and still couldn't figure out how to make it work on macOS before going to bed. I thought no emails were sent successfully. (I managed to use the web interface of sr.ht before this one) On Sat, Jan 11, 2020, at 1:10 AM, Elias Naur wrote: > 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_windows.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 = syscall.NewLazyDLL("kernel32") > > + outputDebugStringW = 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 != syscall.InvalidHandle { > > Did you test the change? From my manual testing, syscall.Stderr No. I don't have a Windows dev environment at the moment. I will find one at my home or wait until next weekday at the workspace. It looks that this approach does not work. > is never equal to syscall.InvalidHandle when building with > `-ldflags="-H windowsgui"`. > > Regardless, you shouldn't set the logger to os.Stderr here. Just > leave it alone and return early. Ah, understood. I will revise the patch tomorrow. > > > + out = os.Stderr > > + } else { > > + out = debugView > > + } > > + 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.19.1 > >