Skip to content

Commit

Permalink
set logger level to info by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Xue Jiao committed Oct 21, 2021
1 parent 49ea1ad commit 8f36442
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mysql_dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
func (db *mysql) GetTables() ([]*core.Table, error) {
args := []interface{}{db.DbName}
s := "SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT` from " +
"`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB')"
"`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')"
db.LogSQL(s, args)

rows, err := db.DB().Query(s, args...)
Expand Down
18 changes: 3 additions & 15 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
}
colName = session.Engine.Quote(nm) + "." + colName
}
session.Statement.ConditionStr = fmt.Sprintf("%v IS NULL OR %v = '0001-01-01 00:00:00'",
session.Statement.ConditionStr = fmt.Sprintf("(%v IS NULL OR %v = '0001-01-01 00:00:00')",
colName, colName)
}
}
Expand Down Expand Up @@ -1426,18 +1426,6 @@ func (session *Session) Ping() error {
return session.DB().Ping()
}

/*
func (session *Session) isColumnExist(tableName string, col *core.Column) (bool, error) {
defer session.resetStatement()
if session.IsAutoClose {
defer session.Close()
}
return session.Engine.dialect.IsColumnExist(tableName, col)
//sqlStr, args := session.Engine.dialect.ColumnCheckSql(tableName, colName)
//results, err := session.query(sqlStr, args...)
//return len(results) > 0, err
}*/

func (engine *Engine) tableName(beanOrTableName interface{}) (string, error) {
v := rValue(beanOrTableName)
if v.Type().Kind() == reflect.String {
Expand Down Expand Up @@ -1596,7 +1584,7 @@ func (session *Session) dropAll() error {
func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) *reflect.Value {
var col *core.Column
if col = table.GetColumnIdx(key, idx); col == nil {
session.Engine.LogWarn(fmt.Sprintf("table %v's has not column %v. %v", table.Name, key, table.Columns()))
session.Engine.LogWarn(fmt.Sprintf("table %v has no column %v. %v", table.Name, key, table.ColumnsSeq()))
return nil
}

Expand Down Expand Up @@ -4223,7 +4211,7 @@ func (s *Session) Sync2(beans ...interface{}) error {
}

if oriTable == nil {
engine.LogWarnf("Table %s has no struct to mapping it", table.Name)
//engine.LogWarnf("Table %s has no struct to mapping it", table.Name)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{},
}

if col.IsDeleted && !unscoped { // tag "deleted" is enabled
colNames = append(colNames, fmt.Sprintf("%v IS NULL or %v = '0001-01-01 00:00:00'",
colNames = append(colNames, fmt.Sprintf("(%v IS NULL OR %v = '0001-01-01 00:00:00')",
colName, colName))
}

Expand Down
22 changes: 21 additions & 1 deletion syslogger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// 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

package xorm

import (
Expand All @@ -8,8 +13,11 @@ import (
"github.com/go-xorm/core"
)

var _ core.ILogger = &SyslogLogger{}

type SyslogLogger struct {
w *syslog.Writer
w *syslog.Writer
showSQL bool
}

func NewSyslogLogger(w *syslog.Writer) *SyslogLogger {
Expand Down Expand Up @@ -56,3 +64,15 @@ func (s *SyslogLogger) Level() core.LogLevel {
func (s *SyslogLogger) SetLevel(l core.LogLevel) (err error) {
return fmt.Errorf("unable to set syslog level")
}

func (s *SyslogLogger) ShowSQL(show ...bool) {
if len(show) == 0 {
s.showSQL = true
return
}
s.showSQL = show[0]
}

func (s *SyslogLogger) IsShowSQL() bool {
return s.showSQL
}
6 changes: 4 additions & 2 deletions xorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
Version string = "0.5.0.0216"
Version string = "0.5.1.0228"
)

func regDrvsNDialects() bool {
Expand Down Expand Up @@ -87,7 +87,9 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
TZLocation: time.Local,
}

engine.SetLogger(NewSimpleLogger(os.Stdout))
logger := NewSimpleLogger(os.Stdout)
logger.SetLevel(core.LOG_INFO)
engine.SetLogger(logger)
engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper)))

runtime.SetFinalizer(engine, close)
Expand Down

0 comments on commit 8f36442

Please sign in to comment.