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