FluxaORM: A Golang ORM for MySQL and Redis
Guide
Plugins
GitHub
Guide
Plugins
GitHub
    • Introduction
    • Registry
    • Data pools
    • Entities
    • Entity fields
    • MySQL Indexes
    • Engine
    • ORM
    • Entity Schema
    • Schema Update
    • CRUD
    • Async flush
    • Searching for Entities
    • Redis Search Engine
    • MySQL Queries
    • Local Cache
    • Redis Operations
    • Distributed Lock
    • Queries Log
    • Plugins
    • Log tables

Queries Log

You can log all MySQL, Redis, and local cache queries by registering a logger using the RegisterQueryLogger() method of orm.ORM:

type MyLogger struct{}

func (l *MyLogger) Handle(log map[string]interface{}) {
	fmt.Printf("QUERY %s in %s", log["query"], log["source"])
}

c.RegisterQueryLogger(&MyLogger{}, true, true, true)

This method requires an implementation of the orm.LogHandler interface:

type LogHandler interface {
	Handle(log map[string]interface{})
}

The log map attribute provides the following fields:

keyvalue typedescription
sourcestringmysql or redis or local_cache
poolstringdata pool name
querystringfull query
operationstringshort label of query
microsecondsint64query time
startedint64Unix timestamp (nanoseconds) when the query started
finishedint64Unix timestamp (nanoseconds) when the query finished
errorstringquery error, if the query returned an error

Queries to the local cache are very fast, which is why the query log for this cache layer does not provide the microseconds, started, and finished keys.

You can specify which queries should be logged by setting the respective boolean arguments in the engine.RegisterQueryLogger() method:

// only queries to MySQL
c.RegisterQueryLogger(&MyLogger{}, true, false, false)
// only queries to redis
c.RegisterQueryLogger(&MyLogger{}, false, true, false)
// only queries to local cache
c.RegisterQueryLogger(&MyLogger{}, false, false, true)
Edit this page
Last Updated: 7/30/25, 8:24 PM
Prev
Distributed Lock
Next
Plugins