Logging

Rakiba uses Telemere for structured logging with beautiful ANSI-colored output. Logs are automatically formatted with timestamps, namespaces, and contextual data.

Output

Logs go to both console and file (logs/dev.log):

[INFO]  2024-01-15 10:30:00 app.core server-starting {:port 3000}
[DEBUG] 2024-01-15 10:30:01 app.routes my-handler {:user-id 123}
[WARN]  2024-01-15 10:30:02 app.core - Watch out!
[ERROR] 2024-01-15 10:30:03 app.core - Something broke {:code 500}
[INFO]  2024-01-15 10:30:04 GET /api/users 200 (12ms)

Colors by Level

Log levels are color-coded in the terminal for quick visual scanning:

LevelColorUse Case
TRACEWhite/GrayFine-grained debugging
DEBUGCyanDevelopment debugging
INFOGreenNormal operations
WARNYellowPotential issues
ERRORRedErrors that need attention
FATALMagentaCritical failures

HTTP Status Code Colors

HTTP request logs also use color-coded status codes:

Status RangeColorMeaning
2xxGreenSuccess
3xxCyanRedirect
4xxYellowClient error
5xxRedServer error

Configuration

Configure logging in your project’s config.edn:

{:logging {:level :info              ; :trace :debug :info :warn :error :fatal
           :file true                ; write to logs/dev.log (default: true)
           :levels {"app.routes" :debug
                    "rakiba.lib" :info}}}

Options explained:

  • :level - Global minimum log level
  • :file - Whether to write logs to logs/dev.log
  • :levels - Per-namespace log level overrides

Environment Variable

Override the log level at startup via environment variable:

LOG_LEVEL=debug bb clj

This is useful for temporarily enabling debug logging without modifying config.edn.

Usage

Use the Telemere API for logging in your application:

(require '[taoensso.telemere :as t])

;; Simple logging
(t/log! :info "Server started")
(t/log! :debug "Processing request" {:user-id 123})
(t/log! :error "Something failed" {:error "timeout"})

;; Structured logging with event IDs
(t/log! {:level :info
         :id ::user-created
         :data {:user-id 123 :email "foo@bar.com"}})

The ::user-created syntax creates a namespaced keyword, making it easy to search and filter logs by event type.

Tailing Logs

Watch logs in real-time with tail:

tail -f logs/dev.log

The file includes ANSI colors, so you’ll see the same beautiful colored output as the console. This is great for monitoring logs in a separate terminal while developing.

Tip: Telemere is included as a core dependency in all Rakiba projects. You don’t need to add it to your deps.edn.

Learn More