Skip to content

Commit

Permalink
Enable clogger again, with an option to only send to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Feb 3, 2021
1 parent 092e2d9 commit ad99a8c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem "redis"
gem "addressable"
gem "rack-ssl-enforcer"
gem "secure_headers"
# gem "clogger"
gem "clogger"
gem "heroku-env"
gem "tzinfo"
gem "nokogiri"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ GEM
airbrake-ruby (~> 5.1)
airbrake-ruby (5.2.0)
rbtree3 (~> 0.5)
clogger (2.3.0)
rack (>= 1.0, < 3.0)
coderay (1.1.3)
concurrent-ruby (1.1.8)
crass (1.0.6)
Expand Down Expand Up @@ -91,6 +93,7 @@ PLATFORMS
DEPENDENCIES
addressable
airbrake
clogger
dotenv
feedjira
github-release-party
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $env = <<SCRIPT
PATH=/home/vagrant/.rbenv/bin:/home/vagrant/.rbenv/versions/global/bin:/home/vagrant/.rbenv/versions/global/lib/ruby/gems/version/bin:$PATH
APP_ENV=production
LOG_ENABLED=1
LOGFILE=1
REDIS_URL=redis://localhost:6379/3
#TWITTER_ACCESS_TOKEN=
Expand Down
26 changes: 17 additions & 9 deletions config/initializers/05-logging.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# frozen_string_literal: true

# disable Sinatra's logger
if defined?(Clogger) || ENV["DISABLE_ACCESS_LOG"]
if ENV.has_key?("CLOGGER")
# disable Sinatra's logger
disable :logging
end

# https://bogomips.org/clogger/
# this format is similar to "Combined", but without $time_local and $http_user_agent (and using $ip instead of $remote_addr)
# removing time and user-agent saves ~50% on log filesize
# the purpose of ~ is to allow for easier grepping with -E '^~' (i.e. filtering out exceptions and other crap)
if defined?(Clogger) && !ENV["DISABLE_ACCESS_LOG"]
use Clogger, logger: $stdout, reentrant: true, format: '~ $ip "$request" $status $response_length "$http_referer"'
# https://yhbt.net/clogger/
# this format is similar to "Combined", but without $time_local and $http_user_agent (and using $ip instead of $remote_addr)
# Combined: $remote_addr - $remote_user [$time_local] $request" $status $response_length "$http_referer" "$http_user_agent"
# removing time and user-agent saves ~50% on log filesize
# the purpose of ~ is to allow for easier grepping with -E '^~' (i.e. filtering out exceptions and other crap)
opts = {
reentrant: true,
format: ENV["CLOGGER_FORMAT"] || '~ $ip "$request" $status $response_length "$http_referer"',
}
if ENV.has_key?("CLOGGER_FILE")
opts[:path] = ENV["CLOGGER_FILE"]
else
opts[:logger] = $stdout
end
use Clogger, opts
end
2 changes: 1 addition & 1 deletion config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
port(ENV["PORT"])
end

if ENV["LOG_ENABLED"]
if ENV.has_key?("LOGFILE")
stdout_redirect("#{app_path}/log/puma-stdout.log", "#{app_path}/log/puma-stderr.log", true)
end

Expand Down

0 comments on commit ad99a8c

Please sign in to comment.