fslog_instance.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package fslog
  2. import (
  3. "log"
  4. "os"
  5. "runtime/debug"
  6. )
  7. const (
  8. levelInfo = "INFO"
  9. levelDebug = "DEBUG"
  10. levelError = "ERROR"
  11. levelWarning = "WARNING"
  12. )
  13. const (
  14. logHeaderFormat = `[level=%s service=%s module=%s subject=%s object=%s operation=%s] %s`
  15. )
  16. func init() {
  17. log.SetOutput(os.Stdout)
  18. log.SetFlags(log.Ldate | log.Ltime)
  19. }
  20. func Info(serviceName string, moduleName string, subject string, object string,
  21. operation string, content string) {
  22. sendConsoleLog(levelInfo, serviceName, moduleName, subject, object, operation, content)
  23. }
  24. func Error(serviceName string, moduleName string, subject string,
  25. object string, operation string, content string) {
  26. sendConsoleLog(levelError, serviceName, moduleName, subject, object, operation,
  27. content+"\n"+string(debug.Stack()))
  28. }
  29. func Debug(serviceName string, moduleName string, subject string,
  30. object string, operation string, content string) {
  31. sendConsoleLog(levelDebug, serviceName, moduleName, subject, object, operation, content)
  32. }
  33. func Warning(serviceName string, moduleName string, subject string,
  34. object string, operation string, content string) {
  35. sendConsoleLog(levelWarning, serviceName, moduleName, subject, object, operation, content)
  36. }
  37. func sendConsoleLog(level string, serviceName string, moduleName string, subject string,
  38. object string, operation string, content string) {
  39. log.Printf(logHeaderFormat, level, serviceName, moduleName, subject, object, operation, content)
  40. }