log.go 1.4 KB

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