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 <mural@ctli.io>> > ---> > 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> >
[gio v1] app/internal/log: add logger for Windows DebugView
On Mon Jan 13, 2020 at 7:43 PM, mural wrote:
> Signed-off-by: mural <mural@ctli.io>> ---> 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_windows.go> new file mode 100644> index 0000000..0642919> --- /dev/null> +++ b/app/internal/log/log_windows.go> @@ -0,0 +1,34 @@> + // Windows DebugView already includes timestamps.> + if syscall.Stderr == 0 || syscall.Stderr == syscall.InvalidHandle {
Your commit message implies that 0 is returned for unattached I/O. If
so, please remove the InvalidHandle check which will only confuse future
readers.
[gio v2] app/internal/log: add logger for Windows DebugView