Documentation ¶
Index ¶
- func Set(logger Logger) (err error)
- type Logger
- type Mock
- func (log *Mock) AuditErr(msg error)
- func (log *Mock) AuditInfo(msg string)
- func (log *Mock) AuditObject(msg string, obj interface{})
- func (log *Mock) AuditPanic()
- func (m *Mock) Clear()
- func (log *Mock) Debug(msg string)
- func (log *Mock) Err(msg string)
- func (m *Mock) GetAll() []string
- func (m *Mock) GetAllMatching(reString string) []string
- func (log *Mock) Info(msg string)
- func (log *Mock) Warning(msg string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger interface { Err(m string) Warning(m string) Info(m string) Debug(m string) AuditPanic() AuditInfo(string) AuditObject(string, interface{}) AuditErr(error) }
A Logger logs messages with explicit priority levels. It is implemented by a logging back-end as provided by New() or NewMock().
Example ¶
impl := setup(nil) bw, ok := impl.w.(*bothWriter) if !ok { fmt.Printf("Wrong type of impl's writer: %T\n", impl.w) return } bw.clk = clock.NewFake() impl.AuditErr(errors.New("Error Audit")) impl.Warning("Warning Audit")
Output: �[31m�[1mE000000 log.test [AUDIT] Error Audit�[0m �[33mW000000 log.test Warning Audit�[0m
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock is a logger that stores all log messages in memory to be examined by a test.
func UseMock ¶
func UseMock() *Mock
UseMock sets a mock logger as the default logger, and returns it.
func (*Mock) AuditErr ¶
func (log *Mock) AuditErr(msg error)
AuditErr can format an error for auditing; it does so at ERR level. AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
func (*Mock) AuditInfo ¶
func (log *Mock) AuditInfo(msg string)
AuditInfo sends an INFO-severity message that is prefixed with the audit tag, for special handling at the upstream system logger.
func (*Mock) AuditObject ¶
func (log *Mock) AuditObject(msg string, obj interface{})
AuditObject sends an INFO-severity JSON-serialized object message that is prefixed with the audit tag, for special handling at the upstream system logger.
func (*Mock) AuditPanic ¶
func (log *Mock) AuditPanic()
AuditPanic catches panicking executables. This method should be added in a defer statement as early as possible AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
func (*Mock) Err ¶
func (log *Mock) Err(msg string)
Err level messages are always marked with the audit tag, for special handling at the upstream system logger.
func (*Mock) GetAll ¶
GetAll returns all messages logged since insantiation or the last call to Clear().
The caller must not modify the returned slice or its elements.
func (*Mock) GetAllMatching ¶
GetAllMatching returns all messages logged since instantiation or the last Clear() whose text matches the given regexp. The regexp is accepted as a string and compiled on the fly, because convenience is more important than performance.
The caller must not modify the elements of the returned slice.