Commit 644e8e33 authored by Terence Lee's avatar Terence Lee Committed by GitHub

Merge pull request #68 from heroku/disable-access-logs

Option to disable disable access logs
parents 4c40e66b 703a4110
...@@ -53,6 +53,24 @@ For SEO purposes, you can drop the `.html` extension from URLs for say a blog si ...@@ -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`. 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 #### 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: 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:
......
...@@ -9,7 +9,11 @@ class NginxConfig ...@@ -9,7 +9,11 @@ class NginxConfig
clean_urls: false, clean_urls: false,
https_only: false, https_only: false,
worker_connections: 512, worker_connections: 512,
resolver: "8.8.8.8" resolver: "8.8.8.8",
logging: {
"access" => true,
"error" => "error"
}
} }
def initialize(json_file) def initialize(json_file)
...@@ -50,7 +54,10 @@ class NginxConfig ...@@ -50,7 +54,10 @@ class NginxConfig
end end
json["error_page"] ||= nil json["error_page"] ||= nil
json["debug"] ||= ENV['STATIC_DEBUG'] json["debug"] = ENV['STATIC_DEBUG']
logging = json["logging"] || {}
json["logging"] = DEFAULT[:logging].merge(logging)
nameservers = [] nameservers = []
if File.exist?("/etc/resolv.conf") if File.exist?("/etc/resolv.conf")
......
...@@ -17,12 +17,17 @@ http { ...@@ -17,12 +17,17 @@ http {
server_tokens off; server_tokens off;
<% if logging['access'] %>
access_log logs/access.log; access_log logs/access.log;
<% else %>
access_log off;
<% end %>
<% if debug %> <% if debug %>
error_log stderr debug; error_log stderr debug;
rewrite_log on; rewrite_log on;
<% else %> <% else %>
error_log stderr; error_log stderr <%= logging['error'] %>;
<% end %> <% end %>
include mime.types; include mime.types;
......
{
"logging": {
"error": "info"
}
}
{
"logging": {
"access": false
}
}
{
"logging": {
"error": "warn"
}
}
...@@ -10,7 +10,7 @@ require_relative "support/path_helper" ...@@ -10,7 +10,7 @@ require_relative "support/path_helper"
RSpec.describe "Simple" do RSpec.describe "Simple" do
before(:all) do before(:all) do
@debug = true @debug = false
BuildpackBuilder.new(@debug, ENV['CIRCLECI']) BuildpackBuilder.new(@debug, ENV['CIRCLECI'])
RouterBuilder.new(@debug, ENV['CIRCLECI']) RouterBuilder.new(@debug, ENV['CIRCLECI'])
ProxyBuilder.new(@debug, ENV["CIRCLECI"]) ProxyBuilder.new(@debug, ENV["CIRCLECI"])
...@@ -814,23 +814,44 @@ STATIC_JSON ...@@ -814,23 +814,44 @@ STATIC_JSON
end end
end end
describe "debug" do describe "logs" do
let(:name) { "debug" } 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 it "should display debug info" do
_, io_stream = app.get("/", true) _, io_stream = app.get("/", true)
expect(io_stream.string).to include("[info]") expect(io_stream.string).to include("[info]")
end end
end end
context "when debug isn't set" do context "should default to normal logging" do
let(:name) { "hello_world" } 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 skip if @debug
_, io_stream = app.get("/", true) _, io_stream = app.get("/", true)
expect(io_stream.string).not_to include("[info]") 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 end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment