-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirbrc
More file actions
55 lines (47 loc) · 1.48 KB
/
irbrc
File metadata and controls
55 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if ENV['RAILS_ENV']
IRB.conf[:IRB_RC] = Proc.new do
class LogFormatter
SEVERITY_TO_COLOR_MAP = {
"DEBUG" => "\e[33m", # yellow
"INFO" => "\e[32m", # green
"WARN" => "\e[34m", # blue
"ERROR" => "\e[31m", # red
"FATAL" => "\e[35m", # magenta
"UNKNOWN" => "\e[37m" # white
}.freeze
def call(severity, time, progname, msg)
formatted_severity = format("%-5s", severity)
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S")
color = SEVERITY_TO_COLOR_MAP[severity] || "\e[37m"
reset = "\e[0m"
"#{color}[#{formatted_time}] #{formatted_severity} : #{msg}#{reset}\n"
end
end
module ExtraLogMethods
def log_append(**args)
info(**args)
rescue => e
puts(**args)
end
def log_append_error(exception, extra = {})
error_hash = {}
error_hash[:name] = exception.class.to_s
error_hash[:message] = exception.to_s
log_append(errors: [error_hash.merge({extra: extra.inspect})])
end
end
puts "👉 Enabling Rails Console log..."
logger = ActiveSupport::Logger.new(STDOUT)
logger.extend(ExtraLogMethods)
logger.formatter = LogFormatter.new
ActiveRecord::Base.logger = logger
Rails.logger = logger
begin
puts "👉 Including FactoryBot methods..."
include FactoryBot::Syntax::Methods
rescue
puts "👎 Factorybot not available..."
end
puts "✅ Done!"
end
end