Browse Source

common colormap

main
pvincent 3 weeks ago
parent
commit
c493d576da
  1. 2
      app/controllers/scores_controller.rb
  2. 8
      app/views/scores/index.html.erb
  3. 15
      bin/dev
  4. 5
      bin/sprod
  5. 5
      config/command_detection.rb
  6. 12
      config/initializers/instrumentalizing.rb
  7. 11
      lib/semantic/abstract_formatter.rb
  8. 11
      lib/semantic/basic_formatter.rb
  9. 11
      lib/semantic/fancy_formatter.rb

2
app/controllers/scores_controller.rb

@ -45,7 +45,7 @@ class ScoresController < ApplicationController
end
def destroy
# zazaz
zazaz
@score.destroy!
redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other

8
app/views/scores/index.html.erb

@ -5,6 +5,14 @@
ACTION_VIEW = <%=Live::Constants::ACTION_VIEW%><br/>
ACTIVE_RECORD = <%=Live::Constants::ACTIVE_RECORD%><br/>
<div class='bg-red-300 text-pink-600'>
bg-red-950
<span class='text-black'>BLACK</span>
<span class='text-yellow-700'>WHITE</span>
<span class='text-red-200'>RED</span>
</div>
<div class="m-5 flex justify-end">
<%= link_to "New score", new_score_path, class: "border rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>

15
bin/dev

@ -1,8 +1,21 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
if ! gem list foreman -i --silent; then
echo "Installing foreman..."
gem install foreman
fi
# ----------------------------------------------------------------------
# in case of running with RAILS_ENV=production with assets precompiling!
# ----------------------------------------------------------------------
if [[ -d public/assets ]]; then
echo "You have probably precompiled assets for production purpose!"
echo "Would you like to remove these assets before running in DEV:"
echo "- Press Enter to continue"
echo "- Press Ctrl+C to cancel"
read
rm -rf public/assets
fi
exec foreman start -f Procfile.dev "$@"

5
bin/sprod

@ -1,11 +1,10 @@
#!/bin/bash
RAILS_ENV=production SECRET_KEY_BASE='toto est fluo' rails assets:precompile
# TO REMOVE PROD assets:
# rm -rf public/assets
SEMANTIC_LOGGER_APP=egr RAILS_ENV=production SECRET_KEY_BASE='toto est fluo' rails server
# journalctl --all -o cat --full -t egr
journalctl --all -o short --no-hostname -t egr -f
# TO REMOVE PROD assets
# rm -rf tmp/cache/assets

5
config/command_detection.rb

@ -4,4 +4,9 @@ module CommandDetection
def console? = !server? && defined?(Rails::Console) == 'constant'
def rake? = !server? && !console? && Rails.const_defined?('Rake')
def tailwind_watcher? = rake? && Rake.application.top_level_tasks.first == 'tailwindcss:watch'
def procfile_server?
Rails.env.development? && Rails.application.server? && File.exist?(File.join(Rails.root,
'Procfile.dev'))
end
end

12
config/initializers/instrumentalizing.rb

@ -1,4 +1,4 @@
return unless Rails.application.server?
return if Rails.application.tailwind_watcher?
Rails.application.config.x.action_controller.main_session_tag = 'toto1'
Rails.application.config.x.action_controller.main_session_tag_fixed_length = 8
@ -24,18 +24,24 @@ Rails.configuration.after_initialize do
SemanticLogger.add_appender(appender:, formatter:)
Semantic::Instrumentalizer.activate(*build_instrumentation_config)
if Rails.application.rake? || Rails.application.console?
io_formatter = Rails.application.config.x.semantic.formatter.constantize.new(time_format: '%H:%M:%S')
SemanticLogger.add_appender(io: $stdout, formatter: io_formatter)
end
else
time_format = '%H:%M:%S' unless Rails.application.procfile_server?
SemanticLogger.clear_appenders!
SemanticLogger.add_appender(
io: $stdout,
formatter: Rails.application.config.x.semantic.formatter.constantize.new
formatter: Rails.application.config.x.semantic.formatter.constantize.new(time_format:)
)
Rails.autoloaders.main.on_load('ApplicationController') do
SemanticLogger.clear_appenders!
SemanticLogger.add_appender(
io: $stdout,
formatter: Rails.application.config.x.semantic.formatter.constantize.new
formatter: Rails.application.config.x.semantic.formatter.constantize.new(time_format:)
)
Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1)

11
lib/semantic/abstract_formatter.rb

@ -6,6 +6,17 @@ module Semantic
CENTER_SIZE = 20
TAG_FIXED_LENGTH = Rails.application.config.x.action_controller.main_session_tag_fixed_length || 10
def initialize(time_format: nil)
super(color_map: ColorMap.new(
debug: CLEAR + TEXT_GRAY_400,
info: CLEAR + TEXT_GRAY_100,
warn: CLEAR + BG_YELLOW + TEXT_BLACK,
error: CLEAR + DARK_BG_RED + TEXT_WHITE,
fatal: CLEAR + BG_MAGENTA + BOLD + TEXT_WHITE
))
@time_format = time_format
end
private
def exception

11
lib/semantic/basic_formatter.rb

@ -7,15 +7,8 @@ module Semantic
PRIME = '▍'.freeze
CONTINATION = '▕'.freeze
def initialize
super(color_map: ColorMap.new(
debug: TEXT_GRAY_400,
info: TEXT_GREEN,
warn: TEXT_BROWN,
error: LIGHT_TEXT_RED,
fatal: TEXT_MAGENTA
))
@time_format = File.exist?(File.join(Rails.root, 'Procfile.dev')) ? nil : '%H:%M:%S'
def initialize(time_format: nil)
super
end
def call(log, logger)

11
lib/semantic/fancy_formatter.rb

@ -12,15 +12,8 @@ module Semantic
RENDERED_VIEW_DURATION = 100
TOTAL_RENDERED_VIEW_DURATION = RENDERED_VIEW_DURATION * 5
def initialize
super(color_map:
ColorMap.new(
debug: CLEAR + TEXT_GRAY_400,
info: CLEAR + TEXT_GRAY_100,
warn: CLEAR + BG_YELLOW + TEXT_BLACK,
error: CLEAR + BG_RED + TEXT_WHITE,
fatal: CLEAR + BG_MAGENTA + BOLD + TEXT_WHITE
))
def initialize(time_format: nil)
super
@memory = nil
end

Loading…
Cancel
Save