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