defaults.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // mauLogger - A logger for Go programs
  2. // Copyright (C) 2016-2018 Tulir Asokan
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. package maulogger
  17. import (
  18. "os"
  19. )
  20. // DefaultLogger ...
  21. var DefaultLogger = Create().(*BasicLogger)
  22. // SetWriter formats the given parts with fmt.Sprint and logs the result with the SetWriter level
  23. func SetWriter(w *os.File) {
  24. DefaultLogger.SetWriter(w)
  25. }
  26. // OpenFile formats the given parts with fmt.Sprint and logs the result with the OpenFile level
  27. func OpenFile() error {
  28. return DefaultLogger.OpenFile()
  29. }
  30. // Close formats the given parts with fmt.Sprint and logs the result with the Close level
  31. func Close() {
  32. DefaultLogger.Close()
  33. }
  34. // Sub creates a Sublogger
  35. func Sub(module string) Logger {
  36. return DefaultLogger.Sub(module)
  37. }
  38. // Raw formats the given parts with fmt.Sprint and logs the result with the Raw level
  39. func Raw(level Level, module, message string) {
  40. DefaultLogger.Raw(level, module, message)
  41. }
  42. // Log formats the given parts with fmt.Sprint and logs the result with the given level
  43. func Log(level Level, parts ...interface{}) {
  44. DefaultLogger.DefaultSub.Log(level, parts...)
  45. }
  46. // Logln formats the given parts with fmt.Sprintln and logs the result with the given level
  47. func Logln(level Level, parts ...interface{}) {
  48. DefaultLogger.DefaultSub.Logln(level, parts...)
  49. }
  50. // Logf formats the given message and args with fmt.Sprintf and logs the result with the given level
  51. func Logf(level Level, message string, args ...interface{}) {
  52. DefaultLogger.DefaultSub.Logf(level, message, args...)
  53. }
  54. // Logfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the given level
  55. func Logfln(level Level, message string, args ...interface{}) {
  56. DefaultLogger.DefaultSub.Logfln(level, message, args...)
  57. }
  58. // Debug formats the given parts with fmt.Sprint and logs the result with the Debug level
  59. func Debug(parts ...interface{}) {
  60. DefaultLogger.DefaultSub.Debug(parts...)
  61. }
  62. // Debugln formats the given parts with fmt.Sprintln and logs the result with the Debug level
  63. func Debugln(parts ...interface{}) {
  64. DefaultLogger.DefaultSub.Debugln(parts...)
  65. }
  66. // Debugf formats the given message and args with fmt.Sprintf and logs the result with the Debug level
  67. func Debugf(message string, args ...interface{}) {
  68. DefaultLogger.DefaultSub.Debugf(message, args...)
  69. }
  70. // Info formats the given parts with fmt.Sprint and logs the result with the Info level
  71. func Info(parts ...interface{}) {
  72. DefaultLogger.DefaultSub.Info(parts...)
  73. }
  74. // Infoln formats the given parts with fmt.Sprintln and logs the result with the Info level
  75. func Infoln(parts ...interface{}) {
  76. DefaultLogger.DefaultSub.Infoln(parts...)
  77. }
  78. // Infof formats the given message and args with fmt.Sprintf and logs the result with the Info level
  79. func Infof(message string, args ...interface{}) {
  80. DefaultLogger.DefaultSub.Infof(message, args...)
  81. }
  82. // Warn formats the given parts with fmt.Sprint and logs the result with the Warn level
  83. func Warn(parts ...interface{}) {
  84. DefaultLogger.DefaultSub.Warn(parts...)
  85. }
  86. // Warnln formats the given parts with fmt.Sprintln and logs the result with the Warn level
  87. func Warnln(parts ...interface{}) {
  88. DefaultLogger.DefaultSub.Warnln(parts...)
  89. }
  90. // Warnf formats the given message and args with fmt.Sprintf and logs the result with the Warn level
  91. func Warnf(message string, args ...interface{}) {
  92. DefaultLogger.DefaultSub.Warnf(message, args...)
  93. }
  94. // Error formats the given parts with fmt.Sprint and logs the result with the Error level
  95. func Error(parts ...interface{}) {
  96. DefaultLogger.DefaultSub.Error(parts...)
  97. }
  98. // Errorln formats the given parts with fmt.Sprintln and logs the result with the Error level
  99. func Errorln(parts ...interface{}) {
  100. DefaultLogger.DefaultSub.Errorln(parts...)
  101. }
  102. // Errorf formats the given message and args with fmt.Sprintf and logs the result with the Error level
  103. func Errorf(message string, args ...interface{}) {
  104. DefaultLogger.DefaultSub.Errorf(message, args...)
  105. }
  106. // Fatal formats the given parts with fmt.Sprint and logs the result with the Fatal level
  107. func Fatal(parts ...interface{}) {
  108. DefaultLogger.DefaultSub.Fatal(parts...)
  109. }
  110. // Fatalln formats the given parts with fmt.Sprintln and logs the result with the Fatal level
  111. func Fatalln(parts ...interface{}) {
  112. DefaultLogger.DefaultSub.Fatalln(parts...)
  113. }
  114. // Fatalf formats the given message and args with fmt.Sprintf and logs the result with the Fatal level
  115. func Fatalf(message string, args ...interface{}) {
  116. DefaultLogger.DefaultSub.Fatalf(message, args...)
  117. }
  118. // Write formats the given parts with fmt.Sprint and logs the result with the Write level
  119. func (log *BasicLogger) Write(p []byte) (n int, err error) {
  120. return log.DefaultSub.Write(p)
  121. }
  122. // Log formats the given parts with fmt.Sprint and logs the result with the given level
  123. func (log *BasicLogger) Log(level Level, parts ...interface{}) {
  124. log.DefaultSub.Log(level, parts...)
  125. }
  126. // Logln formats the given parts with fmt.Sprintln and logs the result with the given level
  127. func (log *BasicLogger) Logln(level Level, parts ...interface{}) {
  128. log.DefaultSub.Logln(level, parts...)
  129. }
  130. // Logf formats the given message and args with fmt.Sprintf and logs the result with the given level
  131. func (log *BasicLogger) Logf(level Level, message string, args ...interface{}) {
  132. log.DefaultSub.Logf(level, message, args...)
  133. }
  134. // Logfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the given level
  135. func (log *BasicLogger) Logfln(level Level, message string, args ...interface{}) {
  136. log.DefaultSub.Logfln(level, message, args...)
  137. }
  138. // Debug formats the given parts with fmt.Sprint and logs the result with the Debug level
  139. func (log *BasicLogger) Debug(parts ...interface{}) {
  140. log.DefaultSub.Debug(parts...)
  141. }
  142. // Debugln formats the given parts with fmt.Sprintln and logs the result with the Debug level
  143. func (log *BasicLogger) Debugln(parts ...interface{}) {
  144. log.DefaultSub.Debugln(parts...)
  145. }
  146. // Debugf formats the given message and args with fmt.Sprintf and logs the result with the Debug level
  147. func (log *BasicLogger) Debugf(message string, args ...interface{}) {
  148. log.DefaultSub.Debugf(message, args...)
  149. }
  150. // Debugfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Debug level
  151. func (log *BasicLogger) Debugfln(message string, args ...interface{}) {
  152. log.DefaultSub.Debugfln(message, args...)
  153. }
  154. // Info formats the given parts with fmt.Sprint and logs the result with the Info level
  155. func (log *BasicLogger) Info(parts ...interface{}) {
  156. log.DefaultSub.Info(parts...)
  157. }
  158. // Infoln formats the given parts with fmt.Sprintln and logs the result with the Info level
  159. func (log *BasicLogger) Infoln(parts ...interface{}) {
  160. log.DefaultSub.Infoln(parts...)
  161. }
  162. // Infofln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Info level
  163. func (log *BasicLogger) Infofln(message string, args ...interface{}) {
  164. log.DefaultSub.Infofln(message, args...)
  165. }
  166. // Infof formats the given message and args with fmt.Sprintf and logs the result with the Info level
  167. func (log *BasicLogger) Infof(message string, args ...interface{}) {
  168. log.DefaultSub.Infof(message, args...)
  169. }
  170. // Warn formats the given parts with fmt.Sprint and logs the result with the Warn level
  171. func (log *BasicLogger) Warn(parts ...interface{}) {
  172. log.DefaultSub.Warn(parts...)
  173. }
  174. // Warnln formats the given parts with fmt.Sprintln and logs the result with the Warn level
  175. func (log *BasicLogger) Warnln(parts ...interface{}) {
  176. log.DefaultSub.Warnln(parts...)
  177. }
  178. // Warnfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Warn level
  179. func (log *BasicLogger) Warnfln(message string, args ...interface{}) {
  180. log.DefaultSub.Warnfln(message, args...)
  181. }
  182. // Warnf formats the given message and args with fmt.Sprintf and logs the result with the Warn level
  183. func (log *BasicLogger) Warnf(message string, args ...interface{}) {
  184. log.DefaultSub.Warnf(message, args...)
  185. }
  186. // Error formats the given parts with fmt.Sprint and logs the result with the Error level
  187. func (log *BasicLogger) Error(parts ...interface{}) {
  188. log.DefaultSub.Error(parts...)
  189. }
  190. // Errorln formats the given parts with fmt.Sprintln and logs the result with the Error level
  191. func (log *BasicLogger) Errorln(parts ...interface{}) {
  192. log.DefaultSub.Errorln(parts...)
  193. }
  194. // Errorf formats the given message and args with fmt.Sprintf and logs the result with the Error level
  195. func (log *BasicLogger) Errorf(message string, args ...interface{}) {
  196. log.DefaultSub.Errorf(message, args...)
  197. }
  198. // Errorfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Error level
  199. func (log *BasicLogger) Errorfln(message string, args ...interface{}) {
  200. log.DefaultSub.Errorfln(message, args...)
  201. }
  202. // Fatal formats the given parts with fmt.Sprint and logs the result with the Fatal level
  203. func (log *BasicLogger) Fatal(parts ...interface{}) {
  204. log.DefaultSub.Fatal(parts...)
  205. }
  206. // Fatalln formats the given parts with fmt.Sprintln and logs the result with the Fatal level
  207. func (log *BasicLogger) Fatalln(parts ...interface{}) {
  208. log.DefaultSub.Fatalln(parts...)
  209. }
  210. // Fatalf formats the given message and args with fmt.Sprintf and logs the result with the Fatal level
  211. func (log *BasicLogger) Fatalf(message string, args ...interface{}) {
  212. log.DefaultSub.Fatalf(message, args...)
  213. }
  214. // Fatalfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Fatal level
  215. func (log *BasicLogger) Fatalfln(message string, args ...interface{}) {
  216. log.DefaultSub.Fatalfln(message, args...)
  217. }