Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by mail.sr.ht (Postfix) with ESMTPS id 0325440129 for <~eliasnaur/gio-patches@lists.sr.ht>; Mon, 13 Jan 2020 11:44:01 +0000 (UTC) Authentication-Results: mail.sr.ht; dkim=pass (2048-bit key) header.d=ctli.io header.i=@ctli.io header.b=S33u9kkS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=alSP93V5 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A34D9228D3; Mon, 13 Jan 2020 06:44:01 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 13 Jan 2020 06:44:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ctli.io; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=LW7cKw/KCU9DX TLUZj+i9UbHnM/Fv4Tq7j8Rh2VFB8A=; b=S33u9kkSpvm9nwlzbxP7JqRqT9Keu PziE4eos/JUTq1BNs9rZEnS9bw+Lgre+tRMNSHzMxkTi9hTHbt8e34VeBWC2NCZz nrzycuSEXV6aSM6fLSWc3Ctlor0+AzyRcBcFWyC0JVlwwvg95cZLvaiwTl2hoJ8J WvR++mAJmz71P+m/9fMFj98mrDHZI/lNhOVPJBJ7cA4JkvUQo5tKa+A7GiUuFaTT bu55GyOnsg8So16qxiePQ734qMfKkOrKBpFIBGsb6Nr045GQPGQHkMXOhG3WFn5b Yo0sba7n3fTWSbM2Twp6t4YgMtuqiQ/BnCO61QUO+wNZXbWrnWQMzYBig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=LW7cKw/KCU9DXTLUZj+i9UbHnM/Fv4Tq7j8Rh2VFB8A=; b=alSP93V5 KLCvV2KnjwYJ563x66LBvbxG2vVAmcZEdULeSukkS8x9uNCrzaFo/D3e4pPKcOKC OPxeArA4Czwl+6paQUX1E04wWYrwbHcUG/+vyTpbGWVdvTiz5Bd+gCG8l+kl0Srh oVLaSa5EhNNVRs/9Zn+4JKOq2roa0FNrXC32/jpsbKzbNOFOHtw/1UBMYt+yxWIZ qDmWICvrV81F2aEYmeIY1efaB1cNJHghyyoVDoS93L2wEEpaSMysuEa+Cq12gT5C nGFin9jkZyiz+lImEFOYKgRPm3YffC4duXq6g6dA4UWydLOJuPx1ZAOXb8Ca9N4E 1TQ1VI2FiG4N8w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdejtddgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepmhhurhgrlhcuoehmuhhrrghlsegtthhlihdrihhoqeenucff ohhmrghinhepfigvlhhlrdgrphhppdhmihgtrhhoshhofhhtrdgtohhmnecukfhppeeiud drvdduledrudeggedrvdduudenucfrrghrrghmpehmrghilhhfrhhomhepmhhurhgrlhes tghtlhhirdhiohenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from bs003.castech.com.tw (castech.com.tw [61.219.144.211]) by mail.messagingengine.com (Postfix) with ESMTPA id 2C1E380061; Mon, 13 Jan 2020 06:43:59 -0500 (EST) From: mural To: ~eliasnaur/gio-patches@lists.sr.ht Cc: mural Subject: [gio v1] app/internal/log: add logger for Windows DebugView Date: Mon, 13 Jan 2020 19:43:55 +0800 Message-Id: <20200113114355.17505-1-mural@ctli.io> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Signed-off-by: mural --- According to https://docs.microsoft.com/en-us/windows/console/getstdhandle, GetStdHandle would return NULL if there is no associated standard handles= . So we chack 0 as well. app/internal/log/log_windows.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 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..0642919 --- /dev/null +++ b/app/internal/log/log_windows.go @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Unlicense OR MIT + +package log + +import ( + "log" + "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. + if syscall.Stderr =3D=3D 0 || syscall.Stderr =3D=3D syscall.InvalidHand= le { + log.SetFlags(log.Flags() &^ log.LstdFlags) + log.SetOutput(debugView) + } +} + +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.24.1