Skip to content

Commit ddfc672

Browse files
committed
Defaults ElasticSearch log level to INFO
Our logging for ES calls was way too verbose. This defaults to INFO which seems good, but leaves the ability to easily move to DEBUG if we need the verbosity. Also clarifies how to fully disable ES logging in README.
1 parent 2ae7425 commit ddfc672

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ additional records with a standardized template.
2323
## Publishing User Facing Documentation
2424

2525
### Automatic generation from openapi specification
26+
2627
- Sign into stoplight.io with an account that has access to the MIT Libraries organization
2728
- copy the source of `openapi.json` file from this repository to the code tab in our [stoplight model](https://next.stoplight.io/mit-libraries/timdex/version%2F1.0/openapi.oas3.yml)
2829
- In [Stoplight's Publish](https://next.stoplight.io/mit-libraries/timdex/version%2F1.0/timdex.hub.yml?view=/&show=publish&domain=mitlibraries-timdex.docs.stoplight.io) section, Uncheck "set live" and then click "Build"
2930
- Once docs are built, check they are sane with the preview feature then click "set live"
3031

3132
## Required Environment Variables (all ENVs)
3233

33-
- `EMAIL_FROM`: email address to send message from, including the registration
34+
- `EMAIL_FROM`: email address to send message from, including the registration
3435
and forgot password messages.
3536
- `EMAIL_URL_HOST` - base url to use when sending emails that link back to the
3637
application. In development, often `localhost:3000`. On heroku, often
@@ -41,6 +42,7 @@ additional records with a standardized template.
4142
- `ELASTICSEARCH_URL`: defaults to `http://localhost:9200`
4243

4344
## Production required Environment Variables
45+
4446
- `AWS_ACCESS_KEY`
4547
- `AWS_ELASTICSEARCH`: boolean. Set to true to enable AWSv4 Signing
4648
- `AWS_SECRET_ACCESS_KEY`
@@ -51,7 +53,21 @@ additional records with a standardized template.
5153
- `SMTP_USER`
5254

5355
## Optional Environment Variables (all ENVs)
54-
- `ELASTICSEARCH_LOG` if `true`, verbosely logs ElasticSearch queries
56+
57+
- `ELASTICSEARCH_LOG` if `true`, verbosely logs ElasticSearch queries.
58+
59+
```text
60+
NOTE: do not set this ENV at all if you want ES logging fully disabled.
61+
Setting it to `false` is still setting it and you will be annoyed and
62+
confused.
63+
```
64+
65+
- `ES_LOG_LEVEL` set elasticsearch transport log level. Defaults to `INFO`.
66+
67+
```text
68+
NOTE: `ELASTICSEARCH_LOG` must also be set for logging to function.
69+
```
70+
5571
- `PREFERRED_DOMAIN` - set this to the domain you would like to to use. Any
5672
other requests that come to the app will redirect to the root of this domain.
5773
This is useful to prevent access to herokuapp.com domains.

config/environments/development.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
# Raises error for missing translations
5353
# config.action_view.raise_on_missing_translations = true
5454

55+
logger = ActiveSupport::Logger.new(STDOUT)
56+
logger.formatter = config.log_formatter
57+
config.logger = ActiveSupport::TaggedLogging.new(logger)
58+
5559
# Use an evented file watcher to asynchronously detect changes in source code,
5660
# routes, locales, etc. This feature depends on the listen gem.
5761
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

config/initializers/elasticsearch.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def configure_elasticsearch
99
end
1010

1111
def es_client
12-
Elasticsearch::Client.new log: ENV['ELASTICSEARCH_LOG']
12+
Elasticsearch::Client.new log: ENV.fetch('ELASTICSEARCH_LOG', false)
1313
end
1414

1515
def aws_client
16-
Elasticsearch::Client.new log: ENV['ELASTICSEARCH_LOG'],
16+
Elasticsearch::Client.new log: ENV.fetch('ELASTICSEARCH_LOG', false),
1717
url: ENV['ELASTICSEARCH_URL'] do |config|
1818
config.request :aws_sigv4,
1919
credentials: Aws::Credentials.new(
@@ -26,3 +26,6 @@ def aws_client
2626
end
2727

2828
Timdex::EsClient = configure_elasticsearch
29+
30+
return unless ENV.fetch('ELASTICSEARCH_LOG', false)
31+
Timdex::EsClient.transport.logger.level = ENV.fetch('ES_LOG_LEVEL', 'INFO')

0 commit comments

Comments
 (0)