FluxaORM v2: Code-Generation-Based Go ORM for MySQL and Redis
Guide
GitHub
Guide
GitHub
    • Introduction
    • Registry
    • Data Pools
    • Entities
    • Entity Fields
    • MySQL Indexes
    • Code Generation
    • Engine
    • Context
    • Entity Schema
    • Schema Update
    • CRUD Operations
    • Async Flush
    • Search
    • Redis Search
    • MySQL Queries
    • Local Cache
    • Context Cache
    • Fake Delete
    • Entity Lifecycle Callbacks
    • Metrics
    • Redis Operations
    • Distributed Lock
    • Event Broker
    • Dirty Streams
    • Queries Log
    • Testing

Queries Log

You can log all MySQL, Redis, and local cache queries by registering a log handler on a fluxaorm.Context:

import "github.com/latolukasz/fluxaorm/v2"

type MyLogger struct{}

func (l *MyLogger) Handle(ctx fluxaorm.Context, log map[string]any) {
    fmt.Printf("QUERY %s in %s\n", log["query"], log["source"])
}

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

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

type LogHandler interface {
    Handle(ctx Context, log map[string]any)
}

Note that the Handle method receives the current fluxaorm.Context as its first argument, which gives you access to request metadata and other contextual information.

Log Entry Fields

The log map provides the following fields:

KeyValue TypeDescription
sourcestringmysql, redis, or local_cache
poolstringData pool name
querystringFull query string
operationstringShort label describing the operation
microsecondsint64Query execution time in microseconds
startedint64Unix timestamp (nanoseconds) when the query started
finishedint64Unix timestamp (nanoseconds) when the query finished
errorstringQuery error message, present only if the query returned an error
missstringSet to "TRUE" when a cache miss occurred
metaMetaRequest metadata set via ctx.SetMetaData(), present only if metadata exists

Queries to the local cache are very fast, which is why the log entries for local cache queries do not include the microseconds, started, and finished fields.

Filtering by Source

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

// Log only MySQL queries
ctx.RegisterQueryLogger(&MyLogger{}, true, false, false)

// Log only Redis queries
ctx.RegisterQueryLogger(&MyLogger{}, false, true, false)

// Log only local cache queries
ctx.RegisterQueryLogger(&MyLogger{}, false, false, true)

// Log MySQL and Redis queries
ctx.RegisterQueryLogger(&MyLogger{}, true, true, false)

Built-in Debug Logger

FluxaORM includes a built-in colored console logger that you can enable for quick debugging:

// Enable debug logging for all sources (MySQL, Redis, local cache)
ctx.EnableQueryDebug()

// Enable debug logging for specific sources
ctx.EnableQueryDebugCustom(true, true, false) // MySQL and Redis only

The debug logger prints each query to stderr with color-coded output showing the source, pool, operation, timing, and query text.

Edit this page
Last Updated: 2/28/26, 4:35 PM
Prev
Dirty Streams
Next
Testing