golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/windows/svc/eventlog/log_test.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build windows 6 7 package eventlog_test 8 9 import ( 10 "testing" 11 12 "golang.org/x/sys/windows/svc/eventlog" 13 ) 14 15 func TestLog(t *testing.T) { 16 if testing.Short() { 17 t.Skip("skipping test in short mode - it modifies system logs") 18 } 19 20 const name = "mylog" 21 const supports = eventlog.Error | eventlog.Warning | eventlog.Info 22 err := eventlog.InstallAsEventCreate(name, supports) 23 if err != nil { 24 t.Fatalf("Install failed: %s", err) 25 } 26 defer func() { 27 err = eventlog.Remove(name) 28 if err != nil { 29 t.Fatalf("Remove failed: %s", err) 30 } 31 }() 32 33 l, err := eventlog.Open(name) 34 if err != nil { 35 t.Fatalf("Open failed: %s", err) 36 } 37 defer l.Close() 38 39 err = l.Info(1, "info") 40 if err != nil { 41 t.Fatalf("Info failed: %s", err) 42 } 43 err = l.Warning(2, "warning") 44 if err != nil { 45 t.Fatalf("Warning failed: %s", err) 46 } 47 err = l.Error(3, "error") 48 if err != nil { 49 t.Fatalf("Error failed: %s", err) 50 } 51 }