Documentation
¶
Overview ¶
Package logger is the central log repository for gopher2600. There is a single log for the entire application and can be accessed through the package level functions.
New log entries are made with the package level Log() and Logf() functions. Both these functions require an implementation of the Permission interface. This interface tests whether the environment making the logging request is allowed to make new log entries.
The environment.Environment type satisfies the Permission interface. If it's not convenient to provide an instance of that type then logging.Allow can be used to provide blanket permission to the caller.
The Colorizer type can be used with SetEcho() to output a simply coloured log entries (using ANSI control codes).
The logger package should not be used inside any init() function.
Index ¶
- func BorrowLog(f func([]Entry))
- func Clear()
- func Log(perm Permission, tag string, detail any)
- func Logf(perm Permission, tag, detail string, args ...any)
- func SetEcho(output io.Writer, writeRecent bool)
- func Tail(output io.Writer, number int)
- func Write(output io.Writer)
- func WriteRecent(output io.Writer)
- type Entry
- type Logger
- func (l *Logger) BorrowLog(f func([]Entry))
- func (l *Logger) Clear()
- func (l *Logger) Log(perm Permission, tag string, detail any)
- func (l *Logger) Logf(perm Permission, tag, detail string, args ...any)
- func (l *Logger) SetEcho(output io.Writer, writeRecent bool)
- func (l *Logger) Tail(output io.Writer, number int)
- func (l *Logger) Write(output io.Writer)
- func (l *Logger) WriteRecent(output io.Writer)
- type Permission
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BorrowLog ¶
func BorrowLog(f func([]Entry))
BorrowLog gives the provided function the critial section and access to the list of log entries
func Log ¶
func Log(perm Permission, tag string, detail any)
Log adds an entry to the central logger
func Logf ¶
func Logf(perm Permission, tag, detail string, args ...any)
Logf adds a new entry to the central logger. The detail string is interpreted as a formatting string as described by the fmt package
func Tail ¶
Tail writes the last N entries in the central logger to io.Writer. A number parameter of <0 will output the entire log.
func WriteRecent ¶
WriteRecent returns only the entries in the central logger added since the last call to WriteRecent
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
not exposing Logger to outside of the package. the package level functions can be used to log to the central Logger
func (*Logger) BorrowLog ¶
BorrowLog gives the provided function the critial section and access to the list of log entries
func (*Logger) Log ¶
func (l *Logger) Log(perm Permission, tag string, detail any)
Log adds a new entry to the logger. The detail string will be interpreted as either a string, an error type or a fmt.Stringer type
In the case of being an error type, the detail string will be taken from the Error() function
Detail arguments of an unsupported type will be formatted using the %v verb from the fmt package. ie. fmt.Sprintf("%v", detail)
func (*Logger) Logf ¶
func (l *Logger) Logf(perm Permission, tag, detail string, args ...any)
Logf adds a new entry to the logger. The detail string is interpreted as a formatting string as described by the fmt package
func (*Logger) Tail ¶
Tail writes the last N entries in the central logger to io.Writer. A number parameter of <0 will output the entire log.
func (*Logger) WriteRecent ¶
WriteRecent returns only the entries added since the last call to CopyRecent
type Permission ¶
type Permission interface {
AllowLogging() bool
}
Permission implementations indicate whether the environment making a log request is allowed to create new log entries. Good for controlling when or if log entries are to be made
var Allow Permission = allow{}
Allow indicates that the logging request should be allowed. A good default to use if a log entry should always be made.