本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.0KB

  1. // Copyright 2015 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build !windows,!nacl,!plan9
  5. package xorm
  6. import (
  7. "fmt"
  8. "log/syslog"
  9. "xorm.io/core"
  10. )
  11. var _ core.ILogger = &SyslogLogger{}
  12. // SyslogLogger will be depricated
  13. type SyslogLogger struct {
  14. w *syslog.Writer
  15. showSQL bool
  16. }
  17. // NewSyslogLogger implements core.ILogger
  18. func NewSyslogLogger(w *syslog.Writer) *SyslogLogger {
  19. return &SyslogLogger{w: w}
  20. }
  21. // Debug log content as Debug
  22. func (s *SyslogLogger) Debug(v ...interface{}) {
  23. s.w.Debug(fmt.Sprint(v...))
  24. }
  25. // Debugf log content as Debug and format
  26. func (s *SyslogLogger) Debugf(format string, v ...interface{}) {
  27. s.w.Debug(fmt.Sprintf(format, v...))
  28. }
  29. // Error log content as Error
  30. func (s *SyslogLogger) Error(v ...interface{}) {
  31. s.w.Err(fmt.Sprint(v...))
  32. }
  33. // Errorf log content as Errorf and format
  34. func (s *SyslogLogger) Errorf(format string, v ...interface{}) {
  35. s.w.Err(fmt.Sprintf(format, v...))
  36. }
  37. // Info log content as Info
  38. func (s *SyslogLogger) Info(v ...interface{}) {
  39. s.w.Info(fmt.Sprint(v...))
  40. }
  41. // Infof log content as Infof and format
  42. func (s *SyslogLogger) Infof(format string, v ...interface{}) {
  43. s.w.Info(fmt.Sprintf(format, v...))
  44. }
  45. // Warn log content as Warn
  46. func (s *SyslogLogger) Warn(v ...interface{}) {
  47. s.w.Warning(fmt.Sprint(v...))
  48. }
  49. // Warnf log content as Warnf and format
  50. func (s *SyslogLogger) Warnf(format string, v ...interface{}) {
  51. s.w.Warning(fmt.Sprintf(format, v...))
  52. }
  53. // Level shows log level
  54. func (s *SyslogLogger) Level() core.LogLevel {
  55. return core.LOG_UNKNOWN
  56. }
  57. // SetLevel always return error, as current log/syslog package doesn't allow to set priority level after syslog.Writer created
  58. func (s *SyslogLogger) SetLevel(l core.LogLevel) {}
  59. // ShowSQL set if logging SQL
  60. func (s *SyslogLogger) ShowSQL(show ...bool) {
  61. if len(show) == 0 {
  62. s.showSQL = true
  63. return
  64. }
  65. s.showSQL = show[0]
  66. }
  67. // IsShowSQL if logging SQL
  68. func (s *SyslogLogger) IsShowSQL() bool {
  69. return s.showSQL
  70. }
上海开阖软件有限公司 沪ICP备12045867号-1