2016-11-03 16:16:01 -06:00
|
|
|
// Copyright 2015 The Xorm Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build !windows,!nacl,!plan9
|
|
|
|
|
2020-03-22 09:12:55 -06:00
|
|
|
package log
|
2016-11-03 16:16:01 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/syslog"
|
|
|
|
)
|
|
|
|
|
2020-03-22 09:12:55 -06:00
|
|
|
var _ Logger = &SyslogLogger{}
|
2016-11-03 16:16:01 -06:00
|
|
|
|
|
|
|
// SyslogLogger will be depricated
|
|
|
|
type SyslogLogger struct {
|
|
|
|
w *syslog.Writer
|
|
|
|
showSQL bool
|
|
|
|
}
|
|
|
|
|
2020-03-22 09:12:55 -06:00
|
|
|
// NewSyslogLogger implements Logger
|
2016-11-03 16:16:01 -06:00
|
|
|
func NewSyslogLogger(w *syslog.Writer) *SyslogLogger {
|
|
|
|
return &SyslogLogger{w: w}
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Debug log content as Debug
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Debug(v ...interface{}) {
|
|
|
|
s.w.Debug(fmt.Sprint(v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Debugf log content as Debug and format
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Debugf(format string, v ...interface{}) {
|
|
|
|
s.w.Debug(fmt.Sprintf(format, v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Error log content as Error
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Error(v ...interface{}) {
|
|
|
|
s.w.Err(fmt.Sprint(v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Errorf log content as Errorf and format
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Errorf(format string, v ...interface{}) {
|
|
|
|
s.w.Err(fmt.Sprintf(format, v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Info log content as Info
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Info(v ...interface{}) {
|
|
|
|
s.w.Info(fmt.Sprint(v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Infof log content as Infof and format
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Infof(format string, v ...interface{}) {
|
|
|
|
s.w.Info(fmt.Sprintf(format, v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Warn log content as Warn
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Warn(v ...interface{}) {
|
|
|
|
s.w.Warning(fmt.Sprint(v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Warnf log content as Warnf and format
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) Warnf(format string, v ...interface{}) {
|
|
|
|
s.w.Warning(fmt.Sprintf(format, v...))
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// Level shows log level
|
2020-03-22 09:12:55 -06:00
|
|
|
func (s *SyslogLogger) Level() LogLevel {
|
|
|
|
return LOG_UNKNOWN
|
2016-11-03 16:16:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetLevel always return error, as current log/syslog package doesn't allow to set priority level after syslog.Writer created
|
2020-03-22 09:12:55 -06:00
|
|
|
func (s *SyslogLogger) SetLevel(l LogLevel) {}
|
2016-11-03 16:16:01 -06:00
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// ShowSQL set if logging SQL
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) ShowSQL(show ...bool) {
|
|
|
|
if len(show) == 0 {
|
|
|
|
s.showSQL = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.showSQL = show[0]
|
|
|
|
}
|
|
|
|
|
2017-01-03 01:20:28 -07:00
|
|
|
// IsShowSQL if logging SQL
|
2016-11-03 16:16:01 -06:00
|
|
|
func (s *SyslogLogger) IsShowSQL() bool {
|
|
|
|
return s.showSQL
|
|
|
|
}
|