Browse Source

basic_formatter tag

main
pvincent 3 months ago
parent
commit
a7a17bcf2b
  1. 2
      app/controllers/hot_controller.rb
  2. 1
      app/controllers/scores_controller.rb
  3. 3
      config/initializers/instrumentalizing.rb
  4. 16
      lib/semantic/abstract_formatter.rb
  5. 7
      lib/semantic/basic_formatter.rb
  6. 14
      lib/semantic/fancy_formatter.rb
  7. 3
      lib/semantic/instrumentalizer.rb
  8. 5
      lib/semantic/subscribers/action_controller.rb

2
app/controllers/hot_controller.rb

@ -6,6 +6,6 @@ class HotController < ApplicationController
logger.info(__method__)
# logger.info(ActiveSupport::LogSubscriber.subscribers.map(&:patterns))
logger.info(ActiveSupport::Notifications.notifier.listeners_for('.*\.action_controller'))
# logger.info(ActiveSupport::Notifications.notifier.listeners_for('.*\.action_controller'))
end
end

1
app/controllers/scores_controller.rb

@ -6,6 +6,7 @@ class ScoresController < ApplicationController
def index
logger.info('inside controller2')
logger.info("multiline1\nmultiline2\nmultiline3")
@q = Score.all.ransack(q_params)
@pagy, @scores = pagy(@q.result)
end

3
config/initializers/instrumentalizing.rb

@ -1,5 +1,8 @@
return unless Rails.application.server?
Rails.application.config.x.action_controller.main_session_tag = 'toto1'
Rails.application.config.x.action_controller.main_session_tag_fixed_length = 8
def build_instrumentation_config
{
action_controller: true,

16
lib/semantic/abstract_formatter.rb

@ -2,6 +2,9 @@ module Semantic
# Abstract colorized formatter
class AbstractFormatter < SemanticLogger::Formatters::Color
include AnsiColors
TAG_NONE = ''.freeze
CENTER_SIZE = 20
TAG_FIXED_LENGTH = Rails.application.config.x.action_controller.main_session_tag_fixed_length || 10
private
@ -41,5 +44,18 @@ module Semantic
traces = items.map { |item| ansi_trace(item, '➟') }
"\n#{traces.join("\n")}"
end
def tags
first_tag, taint = log.tags.empty? ? [TAG_NONE, CLEAR] : [log.tags.first, BG_GRAY + DARK_TEXT_YELLOW]
colorize(centerize(first_tag, TAG_FIXED_LENGTH), taint)
end
def named_tags
return if log.named_tags.empty?
log.named_tags
end
def centerize(text, max_length = CENTER_SIZE) = text.reverse.truncate(max_length).reverse.center(max_length)
end
end

7
lib/semantic/basic_formatter.rb

@ -15,6 +15,11 @@ module Semantic
@time_format = nil if File.exist?(File.join(Rails.root, 'Procfile.dev'))
end
def exception
super_exception = super
"EXCEPTION -- #{super_exception}" if super_exception
end
def time
"#{color}#{format_time(log.time)}#{color_map.clear}" if time_format
end
@ -46,8 +51,6 @@ module Semantic
end
end
def tags; end
def process_info
fname = file_name_and_line
"#{color}[#{fname}]#{color_map.clear}" if fname

14
lib/semantic/fancy_formatter.rb

@ -5,8 +5,6 @@ require 'json'
module Semantic
# wraps meanwhile takes care of ansi colors
class FancyFormatter < AbstractFormatter
TAG_NONE = ''.freeze
CENTER_SIZE = 20
FOREMAN_PREFIX_LENGTH = 18
FAILOVER_WRAP = 80
CHAR_FATAL = '⯶'.freeze
@ -52,17 +50,6 @@ module Semantic
private
def tags
first_tag, taint = log.tags.empty? ? [TAG_NONE, CLEAR] : [log.tags.first, BG_GRAY + DARK_TEXT_YELLOW]
colorize(centerize(first_tag, 10), taint)
end
def named_tags
return if log.named_tags.empty?
log.named_tags
end
def build_regex_redirected
dev_port = Rails.application.routes.default_url_options[:port]
dev_hosts = ['127.0.0.1', 'localhost', Rails.application.routes.default_url_options[:host]].uniq.join('|')
@ -121,7 +108,6 @@ module Semantic
def draw_fatal(char = CHAR_FATAL) = BG_MAGENTA + BOLD + TEXT_WHITE + char + CLEAR
def build_prefix(char) = "#{tags} #{origin}#{colorize(char)}"
def build_terminus = "#{tags} #{origin} #{TERMINUS_STRING} "
def centerize(text, max_length = CENTER_SIZE) = text.reverse.truncate(max_length).reverse.center(max_length)
def origin
true_class = log.name == log.name.upcase_first

3
lib/semantic/instrumentalizer.rb

@ -64,9 +64,10 @@ module Semantic
def build_log_subscriber_from(event_group)
classname = event_group.to_s.camelize
options = Rails.application.config.x.send(event_group).to_h
case classname
when 'ActionController'
Semantic::Subscribers.const_get(classname).new('toto1') # FIXME: externalize session_key
Semantic::Subscribers.const_get(classname).new(**options)
else
Semantic::Subscribers.const_get(classname).new
end

5
lib/semantic/subscribers/action_controller.rb

@ -8,9 +8,10 @@ module Semantic
DEFAULT_DEV_HOSTS = ['127.0.0.1', 'localhost'].freeze
TERMINUS_STRING = '╙─╜'.freeze
def initialize(session_key)
# options = { main_session_tag: 'ANY_SESSION_KEY' }
def initialize(**options)
super(:controller)
@session_key = session_key
@session_key = options[:main_session_tag]
@transactions = {}
end

Loading…
Cancel
Save