Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Ensure development always logs to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Oct 27, 2017
1 parent 7a57cf5 commit 8051878
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed

- Remove social promotions during the installation process
- The default log device for development has been changed to a file (log/development.log)
to follow Rails defaults.

### Fixed

Expand Down
5 changes: 4 additions & 1 deletion lib/timber/cli/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def content
config = Timber::Config.instance
#{insert_hook}
# For a full list of configuration options and their explanations see:
# For common configuration options see:
# https://timber.io/docs/languages/ruby/configuration
#
# For a full list of configuration options see:
# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config
CONTENT
Expand Down
22 changes: 15 additions & 7 deletions lib/timber/cli/installers/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ def install_development_environment(app)

logger_code = <<-CODE
# Install the Timber.io logger
send_logs_to_timber = true # <---- Set to false to stop sending development logs to Timber.io.
# But do not remove the logger code below! The log_device should
# be set to STDOUT if you want to disable sending logs.
log_device = send_logs_to_timber ? Timber::LogDevices::HTTP.new(#{api_key_code}) : STDOUT
logger = Timber::Logger.new(log_device)
# ----------------------------
# Remove the `http_device` to stop sending development logs to Timber.
# Be sure to keep the `file_device` or replace it with `STDOUT`.
http_device = Timber::LogDevices::HTTP.new(#{api_key_code})
file_device = File.open("\#{Rails.root}/log/development.log", "a")
file_device.binmode
log_devices = [http_device, file_device]
# Do not modify below this line. It's important to keep the `Timber::Logger`
# because it provides an API for logging structured data and capturing context.
logger = Timber::Logger.new(*log_devices)
logger.level = config.log_level
config.logger = #{config_set_logger_code}
CODE
Expand Down Expand Up @@ -140,7 +145,10 @@ def get_environment_file_path(environment)

def install_nil(environment_file_path)
logger_code = <<-CODE
# Install the Timber.io logger, but do not send logs.
# Install the Timber.io logger
# ----------------------------
# `nil` is passed to disable logging. It's important to keep the `Timber::Logger`
# because it provides an API for logging structured data and capturing context.
logger = Timber::Logger.new(nil)
logger.level = config.log_level
config.logger = #{config_set_logger_code}
Expand Down
2 changes: 1 addition & 1 deletion spec/timber/cli/config_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:file_helper) { @file_helper = Timber::CLI::FileHelper.new(api) }
let(:path) { "config/initializers/timber.rb" }
let(:config_file) { described_class.new(path, file_helper) }
let(:initial_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For a full list of configuration options and their explanations see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }
let(:initial_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For common configuration options see:\n# https://timber.io/docs/languages/ruby/configuration\n#\n# For a full list of configuration options see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }
let(:contents_hook) { "# Add additional configuration here." }

describe ".create!" do
Expand Down
2 changes: 1 addition & 1 deletion spec/timber/cli/installers/config_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
let(:output) { StringIO.new }
let(:io) { Timber::CLI::IO.new(io_out: output, io_in: input) }
let(:installer) { described_class.new(io, api) }
let(:initial_config_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For a full list of configuration options and their explanations see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }
let(:initial_config_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For common configuration options see:\n# https://timber.io/docs/languages/ruby/configuration\n#\n# For a full list of configuration options see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }

describe ".run" do
it "should run properly" do
Expand Down
22 changes: 15 additions & 7 deletions spec/timber/cli/installers/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@

expected_code = <<-CODE
# Install the Timber.io logger
send_logs_to_timber = true # <---- Set to false to stop sending development logs to Timber.io.
# But do not remove the logger code below! The log_device should
# be set to STDOUT if you want to disable sending logs.
log_device = send_logs_to_timber ? Timber::LogDevices::HTTP.new('#{app.api_key}') : STDOUT
logger = Timber::Logger.new(log_device)
# ----------------------------
# Remove the `http_device` to stop sending development logs to Timber.
# Be sure to keep the `file_device` or replace it with `STDOUT`.
http_device = Timber::LogDevices::HTTP.new('#{app.api_key}')
file_device = File.open("\#{Rails.root}/log/development.log", "a")
file_device.binmode
log_devices = [http_device, file_device]
# Do not modify below this line. It's important to keep the `Timber::Logger`
# because it provides an API for logging structured data and capturing context.
logger = Timber::Logger.new(*log_devices)
logger.level = config.log_level
config.logger = #{logger_code}
CODE
Expand Down Expand Up @@ -314,7 +319,10 @@
env_file_path = "config/environments/development.rb"

expected_code = <<-CODE
# Install the Timber.io logger, but do not send logs.
# Install the Timber.io logger
# ----------------------------
# `nil` is passed to disable logging. It's important to keep the `Timber::Logger`
# because it provides an API for logging structured data and capturing context.
logger = Timber::Logger.new(nil)
logger.level = config.log_level
config.logger = #{logger_code}
Expand Down

0 comments on commit 8051878

Please sign in to comment.