Skip to content

Commit ad99a8c

Browse files
committed
Enable clogger again, with an option to only send to a file.
1 parent 092e2d9 commit ad99a8c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ gem "redis"
1313
gem "addressable"
1414
gem "rack-ssl-enforcer"
1515
gem "secure_headers"
16-
# gem "clogger"
16+
gem "clogger"
1717
gem "heroku-env"
1818
gem "tzinfo"
1919
gem "nokogiri"

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ GEM
1414
airbrake-ruby (~> 5.1)
1515
airbrake-ruby (5.2.0)
1616
rbtree3 (~> 0.5)
17+
clogger (2.3.0)
18+
rack (>= 1.0, < 3.0)
1719
coderay (1.1.3)
1820
concurrent-ruby (1.1.8)
1921
crass (1.0.6)
@@ -91,6 +93,7 @@ PLATFORMS
9193
DEPENDENCIES
9294
addressable
9395
airbrake
96+
clogger
9497
dotenv
9598
feedjira
9699
github-release-party

Vagrantfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $env = <<SCRIPT
1313
PATH=/home/vagrant/.rbenv/bin:/home/vagrant/.rbenv/versions/global/bin:/home/vagrant/.rbenv/versions/global/lib/ruby/gems/version/bin:$PATH
1414
1515
APP_ENV=production
16-
LOG_ENABLED=1
16+
LOGFILE=1
1717
1818
REDIS_URL=redis://localhost:6379/3
1919
#TWITTER_ACCESS_TOKEN=

config/initializers/05-logging.rb

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# frozen_string_literal: true
22

3-
# disable Sinatra's logger
4-
if defined?(Clogger) || ENV["DISABLE_ACCESS_LOG"]
3+
if ENV.has_key?("CLOGGER")
4+
# disable Sinatra's logger
55
disable :logging
6-
end
76

8-
# https://bogomips.org/clogger/
9-
# this format is similar to "Combined", but without $time_local and $http_user_agent (and using $ip instead of $remote_addr)
10-
# removing time and user-agent saves ~50% on log filesize
11-
# the purpose of ~ is to allow for easier grepping with -E '^~' (i.e. filtering out exceptions and other crap)
12-
if defined?(Clogger) && !ENV["DISABLE_ACCESS_LOG"]
13-
use Clogger, logger: $stdout, reentrant: true, format: '~ $ip "$request" $status $response_length "$http_referer"'
7+
# https://yhbt.net/clogger/
8+
# this format is similar to "Combined", but without $time_local and $http_user_agent (and using $ip instead of $remote_addr)
9+
# Combined: $remote_addr - $remote_user [$time_local] $request" $status $response_length "$http_referer" "$http_user_agent"
10+
# removing time and user-agent saves ~50% on log filesize
11+
# the purpose of ~ is to allow for easier grepping with -E '^~' (i.e. filtering out exceptions and other crap)
12+
opts = {
13+
reentrant: true,
14+
format: ENV["CLOGGER_FORMAT"] || '~ $ip "$request" $status $response_length "$http_referer"',
15+
}
16+
if ENV.has_key?("CLOGGER_FILE")
17+
opts[:path] = ENV["CLOGGER_FILE"]
18+
else
19+
opts[:logger] = $stdout
20+
end
21+
use Clogger, opts
1422
end

config/puma.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
port(ENV["PORT"])
1919
end
2020

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

0 commit comments

Comments
 (0)