logger.go 955 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package logger
  5. import (
  6. "fmt"
  7. "os"
  8. "time"
  9. )
  10. // Debug sends a debug log message.
  11. func Debug(format string, v ...interface{}) {
  12. formatMessage("DEBUG", format, v...)
  13. }
  14. // Info sends an info log message.
  15. func Info(format string, v ...interface{}) {
  16. formatMessage("INFO", format, v...)
  17. }
  18. // Error sends an error log message.
  19. func Error(format string, v ...interface{}) {
  20. formatMessage("ERROR", format, v...)
  21. }
  22. // Fatal sends a fatal log message and stop the execution of the program.
  23. func Fatal(format string, v ...interface{}) {
  24. formatMessage("FATAL", format, v...)
  25. os.Exit(1)
  26. }
  27. func formatMessage(level, format string, v ...interface{}) {
  28. prefix := fmt.Sprintf("[%s] [%s] ", time.Now().Format("2006-01-02T15:04:05"), level)
  29. fmt.Fprintf(os.Stderr, prefix+format+"\n", v...)
  30. }