log.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. //go:build windows
  5. // +build windows
  6. package debug
  7. import (
  8. "os"
  9. "strconv"
  10. )
  11. // Log interface allows different log implementations to be used.
  12. type Log interface {
  13. Close() error
  14. Info(eid uint32, msg string) error
  15. Warning(eid uint32, msg string) error
  16. Error(eid uint32, msg string) error
  17. }
  18. // ConsoleLog provides access to the console.
  19. type ConsoleLog struct {
  20. Name string
  21. }
  22. // New creates new ConsoleLog.
  23. func New(source string) *ConsoleLog {
  24. return &ConsoleLog{Name: source}
  25. }
  26. // Close closes console log l.
  27. func (l *ConsoleLog) Close() error {
  28. return nil
  29. }
  30. func (l *ConsoleLog) report(kind string, eid uint32, msg string) error {
  31. s := l.Name + "." + kind + "(" + strconv.Itoa(int(eid)) + "): " + msg + "\n"
  32. _, err := os.Stdout.Write([]byte(s))
  33. return err
  34. }
  35. // Info writes an information event msg with event id eid to the console l.
  36. func (l *ConsoleLog) Info(eid uint32, msg string) error {
  37. return l.report("info", eid, msg)
  38. }
  39. // Warning writes an warning event msg with event id eid to the console l.
  40. func (l *ConsoleLog) Warning(eid uint32, msg string) error {
  41. return l.report("warn", eid, msg)
  42. }
  43. // Error writes an error event msg with event id eid to the console l.
  44. func (l *ConsoleLog) Error(eid uint32, msg string) error {
  45. return l.report("error", eid, msg)
  46. }