Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type GormLoggerInterface
- type LogLevel
- type Logger
- func (l Logger) AfterSQL(ctx xormlogger.LogContext)
- func (l Logger) BeforeSQL(ctx xormlogger.LogContext)
- func (l Logger) Debugf(format string, v ...interface{})
- func (l Logger) Error(ctx context.Context, msg string, data ...interface{})
- func (l Logger) Errorf(format string, v ...interface{})
- func (l Logger) Info(ctx context.Context, msg string, data ...interface{})
- func (l Logger) Infof(format string, v ...interface{})
- func (l Logger) IsShowSQL() bool
- func (l Logger) Level() xormlogger.LogLevel
- func (l Logger) LogMode(level dbLogger.LogLevel) dbLogger.Interface
- func (l Logger) Print(values ...interface{})
- func (l Logger) SetLevel(lv xormlogger.LogLevel)
- func (l Logger) ShowSQL(show ...bool)
- func (l Logger) String() string
- func (l Logger) Trace(ctx context.Context, begin time.Time, ...)
- func (l Logger) Warn(ctx context.Context, msg string, data ...interface{})
- func (l Logger) Warnf(format string, v ...interface{})
- type Option
- type XormLoggerInterface
Constants ¶
View Source
const ( OFF = iota + 1 DEBUG INFO WARN ERROR )
View Source
const (
SessionIDKey = "__xorm_session_id"
)
Variables ¶
View Source
var LogFormatter = func(values ...interface{}) (messages []interface{}) { if len(values) > 1 { var ( sql string formattedValues []string level = values[0] ) if level == "sql" { messages = append(messages, fmt.Sprintf("执行耗时: %.2fms\t", float64(values[2].(time.Duration).Nanoseconds()/1e4)/100.0)) for _, value := range values[4].([]interface{}) { indirectValue := reflect.Indirect(reflect.ValueOf(value)) if indirectValue.IsValid() { value = indirectValue.Interface() if t, ok := value.(time.Time); ok { if t.IsZero() { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", "0000-00-00 00:00:00")) } else { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", t.Format("2006-01-02 15:04:05"))) } } else if b, ok := value.([]byte); ok { if str := string(b); isPrintable(str) { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", str)) } else { formattedValues = append(formattedValues, "'<binary>'") } } else if r, ok := value.(driver.Valuer); ok { if value, err := r.Value(); err == nil && value != nil { formattedValues = append(formattedValues, fmt.Sprintf("'%v'", value)) } else { formattedValues = append(formattedValues, "NULL") } } else { switch value.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, bool: formattedValues = append(formattedValues, fmt.Sprintf("%v", value)) default: formattedValues = append(formattedValues, fmt.Sprintf("'%v'", value)) } } } else { formattedValues = append(formattedValues, "NULL") } } if numericPlaceHolderRegexp.MatchString(values[3].(string)) { sql = values[3].(string) for index, value := range formattedValues { placeholder := fmt.Sprintf(`\$%d([^\d]|$)`, index+1) sql = regexp.MustCompile(placeholder).ReplaceAllString(sql, value+"$1") } } else { formattedValuesLength := len(formattedValues) for index, value := range sqlRegexp.Split(values[3].(string), -1) { sql += value if index < formattedValuesLength { sql += formattedValues[index] } } } messages = append(messages, fmt.Sprintf("执行SQL: %v\t", sql)) messages = append(messages, fmt.Sprintf("影响行数: %v", strconv.FormatInt(values[5].(int64), 10))) } else { messages = append(messages, values[2:]...) } } return }
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Logger *zap.Logger `json:"logger,omitempty"` LogLevel LogLevel `json:"logLevel,omitempty"` SlowThreshold time.Duration `json:"slowThreshold,omitempty"` Colorful bool `json:"colorful,omitempty"` IgnoreRecordNotFoundError bool `json:"ignoreRecordNotFoundError,omitempty"` ParameterizedQueries bool `json:"parameterizedQueries,omitempty"` ShowSql bool `json:"showSql,omitempty"` }
type GormLoggerInterface ¶
type GormLoggerInterface interface { LogMode(gormlogger.LogLevel) gormlogger.Interface Info(context.Context, string, ...interface{}) Warn(context.Context, string, ...interface{}) Error(context.Context, string, ...interface{}) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) }
type Logger ¶
type Logger struct { LogLevel LogLevel SlowThreshold time.Duration Colorful bool IgnoreRecordNotFoundError bool ParameterizedQueries bool // contains filtered or unexported fields }
func NewDBLogger ¶
func (Logger) AfterSQL ¶
func (l Logger) AfterSQL(ctx xormlogger.LogContext)
func (Logger) BeforeSQL ¶
func (l Logger) BeforeSQL(ctx xormlogger.LogContext)
func (Logger) Level ¶
func (l Logger) Level() xormlogger.LogLevel
func (Logger) SetLevel ¶
func (l Logger) SetLevel(lv xormlogger.LogLevel)
type Option ¶ added in v0.1.1
type Option interface { Name() string Value() interface{} }
func WithCustomLogger ¶ added in v0.1.1
type XormLoggerInterface ¶
type XormLoggerInterface interface { BeforeSQL(context xormlogger.LogContext) // only invoked when IsShowSQL is true AfterSQL(context xormlogger.LogContext) Debugf(format string, v ...interface{}) Errorf(format string, v ...interface{}) Infof(format string, v ...interface{}) Warnf(format string, v ...interface{}) Level() xormlogger.LogLevel SetLevel(l xormlogger.LogLevel) ShowSQL(show ...bool) IsShowSQL() bool }
Click to show internal directories.
Click to hide internal directories.