logcalls.go 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2013 Ardan Studios. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE handle.
  4. // Package tracelog : logcalls.go provides formatting functions.
  5. package tracelog
  6. import (
  7. "fmt"
  8. )
  9. //** STARTED AND COMPLETED
  10. // Started uses the Serialize destination and adds a Started tag to the log line
  11. func Started(title string, functionName string) {
  12. logger.Trace.Output(2, fmt.Sprintf("%s : %s : Started\n", title, functionName))
  13. }
  14. // Startedf uses the Serialize destination and writes a Started tag to the log line
  15. func Startedf(title string, functionName string, format string, a ...interface{}) {
  16. logger.Trace.Output(2, fmt.Sprintf("%s : %s : Started : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  17. }
  18. // Completed uses the Serialize destination and writes a Completed tag to the log line
  19. func Completed(title string, functionName string) {
  20. logger.Trace.Output(2, fmt.Sprintf("%s : %s : Completed\n", title, functionName))
  21. }
  22. // Completedf uses the Serialize destination and writes a Completed tag to the log line
  23. func Completedf(title string, functionName string, format string, a ...interface{}) {
  24. logger.Trace.Output(2, fmt.Sprintf("%s : %s : Completed : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  25. }
  26. // CompletedError uses the Error destination and writes a Completed tag to the log line
  27. func CompletedError(err error, title string, functionName string) {
  28. logger.Error.Output(2, fmt.Sprintf("%s : %s : Completed : ERROR : %s\n", title, functionName, err))
  29. }
  30. // CompletedErrorf uses the Error destination and writes a Completed tag to the log line
  31. func CompletedErrorf(err error, title string, functionName string, format string, a ...interface{}) {
  32. logger.Error.Output(2, fmt.Sprintf("%s : %s : Completed : ERROR : %s : %s\n", title, functionName, fmt.Sprintf(format, a...), err))
  33. }
  34. //** TRACE
  35. // Trace writes to the Trace destination
  36. func Trace(title string, functionName string, format string, a ...interface{}) {
  37. logger.Trace.Output(2, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  38. }
  39. //** INFO
  40. // Info writes to the Info destination
  41. func Info(title string, functionName string, format string, a ...interface{}) {
  42. logger.Info.Output(2, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  43. }
  44. //** WARNING
  45. // Warning writes to the Warning destination
  46. func Warning(title string, functionName string, format string, a ...interface{}) {
  47. logger.Warning.Output(2, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  48. }
  49. //** ERROR
  50. // Error writes to the Error destination and accepts an err
  51. func Error(err error, title string, functionName string) {
  52. logger.Error.Output(2, fmt.Sprintf("%s : %s : ERROR : %s\n", title, functionName, err))
  53. }
  54. // Errorf writes to the Error destination and accepts an err
  55. func Errorf(err error, title string, functionName string, format string, a ...interface{}) {
  56. logger.Error.Output(2, fmt.Sprintf("%s : %s : ERROR : %s : %s\n", title, functionName, fmt.Sprintf(format, a...), err))
  57. }
  58. //** ALERT
  59. // Alert write to the Error destination and sends email alert
  60. func Alert(subject string, title string, functionName string, format string, a ...interface{}) {
  61. message := fmt.Sprintf("%s : %s : ALERT : %s\n", title, functionName, fmt.Sprintf(format, a...))
  62. logger.Error.Output(2, message)
  63. SendEmailException(subject, message)
  64. }
  65. // CompletedAlert write to the Error destination, writes a Completed tag to the log line and sends email alert
  66. func CompletedAlert(subject string, title string, functionName string, format string, a ...interface{}) {
  67. message := fmt.Sprintf("%s : %s : Completed : ALERT : %s\n", title, functionName, fmt.Sprintf(format, a...))
  68. logger.Error.Output(2, message)
  69. SendEmailException(subject, message)
  70. }