logcallscalldepth.go 4.1 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. // Startedcd uses the Trace destination and adds a Started tag to the log line
  11. func Startedcd(callDepth int, title string, functionName string) {
  12. logger.Trace.Output(callDepth, fmt.Sprintf("%s : %s : Started\n", title, functionName))
  13. }
  14. // Startedfcd uses the Trace destination and writes a Started tag to the log line
  15. func Startedfcd(callDepth int, title string, functionName string, format string, a ...interface{}) {
  16. logger.Trace.Output(callDepth, fmt.Sprintf("%s : %s : Started : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  17. }
  18. // Completedcd uses the Trace destination and writes a Completed tag to the log line
  19. func Completedcd(callDepth int, title string, functionName string) {
  20. logger.Trace.Output(callDepth, fmt.Sprintf("%s : %s : Completed\n", title, functionName))
  21. }
  22. // Completedfcd uses the Trace destination and writes a Completed tag to the log line
  23. func Completedfcd(callDepth int, title string, functionName string, format string, a ...interface{}) {
  24. logger.Trace.Output(callDepth, fmt.Sprintf("%s : %s : Completed : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  25. }
  26. // CompletedErrorcd uses the Error destination and writes a Completed tag to the log line
  27. func CompletedErrorcd(callDepth int, err error, title string, functionName string) {
  28. logger.Error.Output(callDepth, fmt.Sprintf("%s : %s : Completed : ERROR : %s\n", title, functionName, err))
  29. }
  30. // CompletedErrorfcd uses the Error destination and writes a Completed tag to the log line
  31. func CompletedErrorfcd(callDepth int, err error, title string, functionName string, format string, a ...interface{}) {
  32. logger.Error.Output(callDepth, fmt.Sprintf("%s : %s : Completed : ERROR : %s : %s\n", title, functionName, fmt.Sprintf(format, a...), err))
  33. }
  34. //** TRACE
  35. // Tracecd writes to the Trace destination
  36. func Tracecd(callDepth int, title string, functionName string, format string, a ...interface{}) {
  37. logger.Trace.Output(callDepth, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  38. }
  39. //** INFO
  40. // Infocd writes to the Info destination
  41. func Infocd(callDepth int, title string, functionName string, format string, a ...interface{}) {
  42. logger.Info.Output(callDepth, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  43. }
  44. //** WARNING
  45. // Warningcd writes to the Warning destination
  46. func Warningcd(callDepth int, title string, functionName string, format string, a ...interface{}) {
  47. logger.Warning.Output(callDepth, fmt.Sprintf("%s : %s : Info : %s\n", title, functionName, fmt.Sprintf(format, a...)))
  48. }
  49. //** ERROR
  50. // Errorcd writes to the Error destination and accepts an err
  51. func Errorcd(callDepth int, err error, title string, functionName string) {
  52. logger.Error.Output(callDepth, fmt.Sprintf("%s : %s : ERROR : %s\n", title, functionName, err))
  53. }
  54. // Errorfcd writes to the Error destination and accepts an err
  55. func Errorfcd(callDepth int, err error, title string, functionName string, format string, a ...interface{}) {
  56. logger.Error.Output(callDepth, fmt.Sprintf("%s : %s : ERROR : %s : %s\n", title, functionName, fmt.Sprintf(format, a...), err))
  57. }
  58. //** ALERT
  59. // Alertcd write to the Error destination and sends email alert
  60. func Alertcd(callDepth int, 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(callDepth, message)
  63. SendEmailException(subject, message)
  64. }
  65. // CompletedAlertcd write to the Error destination, writes a Completed tag to the log line and sends email alert
  66. func CompletedAlertcd(callDepth int, 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(callDepth, message)
  69. SendEmailException(subject, message)
  70. }