glog_chaining.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package glog
  7. import (
  8. "context"
  9. "io"
  10. )
  11. // Expose returns the default logger of glog.
  12. func Expose() *Logger {
  13. return logger
  14. }
  15. // Ctx is a chaining function,
  16. // which sets the context for current logging.
  17. // The parameter <keys> specifies the context keys for retrieving values.
  18. func Ctx(ctx context.Context, keys ...interface{}) *Logger {
  19. return logger.Ctx(ctx, keys...)
  20. }
  21. // To is a chaining function,
  22. // which redirects current logging content output to the sepecified <writer>.
  23. func To(writer io.Writer) *Logger {
  24. return logger.To(writer)
  25. }
  26. // Path is a chaining function,
  27. // which sets the directory path to <path> for current logging content output.
  28. func Path(path string) *Logger {
  29. return logger.Path(path)
  30. }
  31. // Cat is a chaining function,
  32. // which sets the category to <category> for current logging content output.
  33. func Cat(category string) *Logger {
  34. return logger.Cat(category)
  35. }
  36. // File is a chaining function,
  37. // which sets file name <pattern> for the current logging content output.
  38. func File(pattern string) *Logger {
  39. return logger.File(pattern)
  40. }
  41. // Level is a chaining function,
  42. // which sets logging level for the current logging content output.
  43. func Level(level int) *Logger {
  44. return logger.Level(level)
  45. }
  46. // LevelStr is a chaining function,
  47. // which sets logging level for the current logging content output using level string.
  48. func LevelStr(levelStr string) *Logger {
  49. return logger.LevelStr(levelStr)
  50. }
  51. // Skip is a chaining function,
  52. // which sets stack skip for the current logging content output.
  53. // It also affects the caller file path checks when line number printing enabled.
  54. func Skip(skip int) *Logger {
  55. return logger.Skip(skip)
  56. }
  57. // Stack is a chaining function,
  58. // which sets stack options for the current logging content output .
  59. func Stack(enabled bool, skip ...int) *Logger {
  60. return logger.Stack(enabled, skip...)
  61. }
  62. // StackWithFilter is a chaining function,
  63. // which sets stack filter for the current logging content output .
  64. func StackWithFilter(filter string) *Logger {
  65. return logger.StackWithFilter(filter)
  66. }
  67. // StdPrint is a chaining function,
  68. // which enables/disables stdout for the current logging content output.
  69. // It's enabled in default.
  70. func Stdout(enabled ...bool) *Logger {
  71. return logger.Stdout(enabled...)
  72. }
  73. // Header is a chaining function,
  74. // which enables/disables log header for the current logging content output.
  75. // It's enabled in default.
  76. func Header(enabled ...bool) *Logger {
  77. return logger.Header(enabled...)
  78. }
  79. // Line is a chaining function,
  80. // which enables/disables printing its caller file along with its line number.
  81. // The parameter <long> specified whether print the long absolute file path, eg: /a/b/c/d.go:23.
  82. func Line(long ...bool) *Logger {
  83. return logger.Line(long...)
  84. }
  85. // Async is a chaining function,
  86. // which enables/disables async logging output feature.
  87. func Async(enabled ...bool) *Logger {
  88. return logger.Async(enabled...)
  89. }