Browse Source

efficient logging in dark theme

main
pvincent 2 years ago
parent
commit
d03391bdf9
  1. 29
      app/controllers/welcome_controller.rb
  2. 2
      config/application.rb
  3. 6
      config/environments/development.rb
  4. 4
      config/environments/production.rb
  5. 2
      lib/formatters/basic_formatter.rb

29
app/controllers/welcome_controller.rb

@ -1,22 +1,23 @@
class WelcomeController < ApplicationController
def index
logger.measure_error "Took too long to complete", min_duration: 3000 do
logger.debug("Debugging information to aid with problem determination")
logger.info("Informational message such as request received\nline 2\nline3")
logger.warn("Warn about something in the system")
logger.error("An error occurred during processing")
logger.fatal("Oh no something really bad happened")
# logger.measure_error "Took too long to complete", min_duration: 3000 do
# logger.debug("Debugging information to aid with problem determination")
# logger.info("Informational message such as request received\nline 2\nline3")
# logger.warn("Warn about something in the system")
# logger.error("An error occurred during processing")
# logger.fatal("Oh no something really bad happened")
logger.measure_info "Called external interface" do
sleep 0.1 # Code to call external service ...
end
# logger.measure_info "Called external interface" do
# sleep 0.1 # Code to call external service ...
# end
SemanticLogger.tagged(user: "Jack", zip_code: 12345) do
# All log entries in this block will include the above named tags
logger.debug("Hello World")
end
# SemanticLogger.tagged(user: "Jack", zip_code: 12345) do
# # All log entries in this block will include the above named tags
# logger.debug("Hello World")
# end
logger.info("efficient logging in practice works better on dark theme")
# raise "exception"
end
# end
end
end

2
config/application.rb

@ -11,8 +11,6 @@ class Application < Rails::Application
config.load_defaults 7.0
# Efficient logging with Semantic Logger
require_relative "../lib/formatters/basic_formatter"
config.semantic_logger.add_appender(io: $stdout, formatter: BasicFormatter.new)
config.rails_semantic_logger.add_file_appender = false
config.rails_semantic_logger.semantic = false
config.rails_semantic_logger.started = true

6
config/environments/development.rb

@ -25,7 +25,7 @@ Rails.application.configure do
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
"Cache-Control" => "public, max-age=#{2.days.to_i}",
}
else
config.action_controller.perform_caching = false
@ -67,4 +67,8 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
# Semantic Logger in console log only!
require_relative "../../lib/formatters/basic_formatter"
config.semantic_logger.add_appender(io: $stdout, formatter: BasicFormatter.new)
end

4
config/environments/production.rb

@ -90,4 +90,8 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# Semantic Logger in console log only!
require_relative "../../lib/formatters/basic_formatter"
config.semantic_logger.add_appender(file_name: "log/production.log", formatter: BasicFormatter.new)
end

2
lib/formatters/basic_formatter.rb

@ -31,7 +31,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color
log.message
end
if log.name == "Rails" || log.name == "ActionView::Base"
"#{prefix} #{color}#{message}#{color_map.clear}"
"#{prefix} #{ANSI_GRAY}#{message}#{color_map.clear}"
else
"#{prefix} #{SemanticLogger::AnsiColors::WHITE}#{message}#{color_map.clear}"
end

Loading…
Cancel
Save