aboutsummaryrefslogtreecommitdiff
path: root/config/log.cr
blob: 225d25cca2ff7736550bc7e356c1d44f9446c2e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "file_utils"

if LuckyEnv.test?
  # Logs to `tmp/test.log` so you can see what's happening without having
  # a bunch of log output in your spec results.
  FileUtils.mkdir_p("tmp")

  backend = Log::IOBackend.new(File.new("tmp/test.log", mode: "w"))
  backend.formatter = Lucky::PrettyLogFormatter.proc
  Log.dexter.configure(:debug, backend)
elsif LuckyEnv.production?
  # Lucky uses JSON in production so logs can be searched more easily
  #
  # If you want logs like in develpoment use 'Lucky::PrettyLogFormatter.proc'.
  backend = Log::IOBackend.new
  backend.formatter = Dexter::JSONLogFormatter.proc
  Log.dexter.configure(:info, backend)
else
  # Use a pretty formatter printing to STDOUT in development
  backend = Log::IOBackend.new
  backend.formatter = Lucky::PrettyLogFormatter.proc
  Log.dexter.configure(:debug, backend)
  DB::Log.level = :info
end

# Lucky only logs when before/after pipes halt by redirecting, or rendering a
# response. Pipes that run without halting are not logged.
#
# If you want to log every pipe that runs, set the log level to ':info'
Lucky::ContinuedPipeLog.dexter.configure(:none)

# Lucky only logs failed queries by default.
#
# Set the log to ':info' to log all queries
Avram::QueryLog.dexter.configure(:none)

# Subscribe to Pulsar events to log when queries are made,
# queries fail, or save operations fail. Remove this to
# disable these log events without disabling all logging.
Avram.initialize_logging

# Skip logging static assets requests in development
Lucky::LogHandler.configure do |settings|
  if LuckyEnv.development?
    settings.skip_if = ->(context : HTTP::Server::Context) {
      context.request.method.downcase == "get" &&
      context.request.resource.starts_with?(/\/css\/|\/js\/|\/assets\/|\/favicon\.ico/)
    }
  end
end