stdout.go 518 B

123456789101112131415161718192021222324252627
  1. package log
  2. import (
  3. "fmt"
  4. stdlog "log"
  5. "os"
  6. )
  7. // stdoutHandler stdout log handler
  8. type stdoutHandler struct {
  9. out *stdlog.Logger
  10. }
  11. // NewStdHandler create a stdout log handler
  12. func NewStdHandler() Handler {
  13. return &stdoutHandler{out: stdlog.New(os.Stdout, "", stdlog.LstdFlags|stdlog.Lshortfile)}
  14. }
  15. // Log stdout loging
  16. func (h *stdoutHandler) Log(level, msg string) {
  17. _ = h.out.Output(5, fmt.Sprintf("[%s] %s", level, msg))
  18. }
  19. // Close stdout loging
  20. func (h *stdoutHandler) Close() (err error) {
  21. return
  22. }