diff --git a/config.go b/config.go index 4c4134e9bf61cce88844c7e4487bfcd255b753e0..48b6de506167a747b2fb63a41f5f2e9956a8cba8 100644 --- a/config.go +++ b/config.go @@ -4,23 +4,23 @@ import ( "sync/atomic" ) -type config struct { +type conf struct { loggingEnabled uint32 queryLogger atomic.Value } -func (c *config) Logger() Logger { +func (c *conf) Logger() Logger { if lg := c.queryLogger.Load(); lg != nil { return lg.(Logger) } return nil } -func (c *config) SetLogger(lg Logger) { +func (c *conf) SetLogger(lg Logger) { c.queryLogger.Store(lg) } -func (c *config) SetLogging(value bool) { +func (c *conf) SetLogging(value bool) { if value { atomic.StoreUint32(&c.loggingEnabled, 1) return @@ -28,11 +28,11 @@ func (c *config) SetLogging(value bool) { atomic.StoreUint32(&c.loggingEnabled, 0) } -func (c *config) LoggingEnabled() bool { +func (c *conf) LoggingEnabled() bool { if v := atomic.LoadUint32(&c.loggingEnabled); v == 1 { return true } return false } -var Config = config{} +var Conf = conf{} diff --git a/internal/sqladapter/database.go b/internal/sqladapter/database.go index ff76d904a63f12cd47e44df1f55e7c5dfc645c53..1b2575f48099b42f5cad80fbf8169d34ef1dfeee 100644 --- a/internal/sqladapter/database.go +++ b/internal/sqladapter/database.go @@ -222,7 +222,7 @@ func (d *database) StatementExec(stmt *exql.Statement, args ...interface{}) (sql var query string var err error - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: query, @@ -251,7 +251,7 @@ func (d *database) StatementQuery(stmt *exql.Statement, args ...interface{}) (*s var query string var err error - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: query, @@ -277,7 +277,7 @@ func (d *database) StatementQueryRow(stmt *exql.Statement, args ...interface{}) var query string var err error - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: query, diff --git a/logger.go b/logger.go index 7b3885879d7286f7b7eb59ef23e4021f95941c95..a29c6292ef44f831741dfb0106ef5feae07d7d9c 100644 --- a/logger.go +++ b/logger.go @@ -10,8 +10,8 @@ import ( // QueryStatus represents a query after being executed. type QueryStatus struct { - SessionID uint64 - TxID uint64 + SessID uint64 + TxID uint64 Query string Args []interface{} @@ -40,13 +40,13 @@ const ( func init() { if envEnabled(EnvEnableDebug) { - Config.SetLogger(&defaultLogger{}) // Using default logger. - Config.SetLogging(true) + Conf.SetLogger(&defaultLogger{}) // Using default logger. + Conf.SetLogging(true) } } // Logger represents a logging collector. You can pass a logging collector to -// db.Config.SetLogger(myCollector) to make it collect db.QueryStatus messages +// db.Conf.SetLogger(myCollector) to make it collect db.QueryStatus messages // after every query. type Logger interface { Log(*QueryStatus) @@ -54,11 +54,11 @@ type Logger interface { // Log sends a query status report to the configured logger. func Log(m *QueryStatus) { - if lg := Config.Logger(); lg != nil { + if lg := Conf.Logger(); lg != nil { lg.Log(m) return } - log.Printf("No logger has been configured, use db.Config.SetLogger()") + log.Printf("No logger has been configured, use db.Conf.SetLogger()") } var ( diff --git a/mongo/result.go b/mongo/result.go index 0916964def348075c2d84bbdc3e6644fcf5a6236..0fa0a794f0509ece898fedc19dbcf687f46b4cbb 100644 --- a/mongo/result.go +++ b/mongo/result.go @@ -125,7 +125,7 @@ func (r *result) Select(fields ...interface{}) db.Result { // All dumps all results into a pointer to an slice of structs or maps. func (r *result) All(dst interface{}) (err error) { - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: fmt.Sprintf("find(%s)", mustJSON(r.queryChunks.Conditions)), @@ -162,7 +162,7 @@ func (r *result) Group(fields ...interface{}) db.Result { // One fetches only one result from the resultset. func (r *result) One(dst interface{}) (err error) { - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: fmt.Sprintf("findOne(%s)", mustJSON(r.queryChunks.Conditions)), @@ -196,7 +196,7 @@ func (r *result) Next(dst interface{}) bool { // Delete remove the matching items from the collection. func (r *result) Delete() (err error) { - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: fmt.Sprintf("remove(%s)", mustJSON(r.queryChunks.Conditions)), @@ -229,7 +229,7 @@ func (r *result) Close() error { func (r *result) Update(src interface{}) (err error) { updateSet := map[string]interface{}{"$set": src} - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: fmt.Sprintf("update(%s, %s)", mustJSON(r.queryChunks.Conditions), mustJSON(updateSet)), @@ -287,7 +287,7 @@ func (r *result) query() (*mgo.Query, error) { // Count counts matching elements. func (r *result) Count() (total uint64, err error) { - if db.Config.LoggingEnabled() { + if db.Conf.LoggingEnabled() { defer func(start time.Time) { db.Log(&db.QueryStatus{ Query: fmt.Sprintf("find(%s).count()", mustJSON(r.queryChunks.Conditions)),