Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #68 from heroku/disable-access-logs
Browse files Browse the repository at this point in the history
Option to disable disable access logs
  • Loading branch information
hone committed Apr 4, 2017
2 parents 4c40e66 + 703a411 commit 644e8e3
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 13 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ For SEO purposes, you can drop the `.html` extension from URLs for say a blog si

By default this is set to `false`.


#### Logging
You can disable the access log and change the severity level for the error log.

```json
{
"logging": {
"access": false,
"error": "warn"
}
}
```

By default `access` is set to `true` and `error` is set to `error`.

The environment variable `STATIC_DEBUG` can be set, to override the `error` log level to `error`.


#### Custom Routes
You can define custom routes that combine to a single file. This allows you to preserve routing for a single page web application. The following operators are supported:

Expand Down
11 changes: 9 additions & 2 deletions scripts/config/lib/nginx_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class NginxConfig
clean_urls: false,
https_only: false,
worker_connections: 512,
resolver: "8.8.8.8"
resolver: "8.8.8.8",
logging: {
"access" => true,
"error" => "error"
}
}

def initialize(json_file)
Expand Down Expand Up @@ -50,7 +54,10 @@ def initialize(json_file)
end

json["error_page"] ||= nil
json["debug"] ||= ENV['STATIC_DEBUG']
json["debug"] = ENV['STATIC_DEBUG']

logging = json["logging"] || {}
json["logging"] = DEFAULT[:logging].merge(logging)

nameservers = []
if File.exist?("/etc/resolv.conf")
Expand Down
9 changes: 7 additions & 2 deletions scripts/config/templates/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ http {

server_tokens off;

access_log logs/access.log;
<% if logging['access'] %>
access_log logs/access.log;
<% else %>
access_log off;
<% end %>
<% if debug %>
error_log stderr debug;
rewrite_log on;
<% else %>
error_log stderr;
error_log stderr <%= logging['error'] %>;
<% end %>

include mime.types;
Expand Down
3 changes: 0 additions & 3 deletions spec/fixtures/debug/static.json

This file was deleted.

5 changes: 5 additions & 0 deletions spec/fixtures/info/static.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"logging": {
"error": "info"
}
}
1 change: 1 addition & 0 deletions spec/fixtures/logging_access_off/public_html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
5 changes: 5 additions & 0 deletions spec/fixtures/logging_access_off/static.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"logging": {
"access": false
}
}
1 change: 1 addition & 0 deletions spec/fixtures/logging_error_level/public_html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
5 changes: 5 additions & 0 deletions spec/fixtures/logging_error_level/static.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"logging": {
"error": "warn"
}
}
33 changes: 27 additions & 6 deletions spec/simple_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

RSpec.describe "Simple" do
before(:all) do
@debug = true
@debug = false
BuildpackBuilder.new(@debug, ENV['CIRCLECI'])
RouterBuilder.new(@debug, ENV['CIRCLECI'])
ProxyBuilder.new(@debug, ENV["CIRCLECI"])
Expand Down Expand Up @@ -814,23 +814,44 @@
end
end

describe "debug" do
let(:name) { "debug" }
describe "logs" do
let(:name) { "info" }

context "when error log is set to info" do
it "should display info logs" do
_, io_stream = app.get("/", true)
expect(io_stream.string).to include("[info]")
end
end

context "override debug when env var is set" do
let(:app) { AppRunner.new(name, proxy, env, true, !ENV['CIRCLECI']) }
let(:name) { "hello_world" }

context "when debug is set" do
it "should display debug info" do
_, io_stream = app.get("/", true)
expect(io_stream.string).to include("[info]")
end
end

context "when debug isn't set" do
context "should default to normal logging" do
let(:name) { "hello_world" }

it "should not display debug info" do
it "should not display debug info and display access logs" do
skip if @debug
_, io_stream = app.get("/", true)
expect(io_stream.string).not_to include("[info]")
expect(io_stream.string).to include("GET /")
end
end

context "turn off all logging" do
let(:name) { "logging_access_off" }

it "should not log access" do
_, io_stream = app.get("/", true)
expect(io_stream.string).not_to include("[info]")
expect(io_stream.string).not_to include("GET /")
end
end
end
Expand Down

0 comments on commit 644e8e3

Please sign in to comment.