module Rsrb::Internal::Utils
Public Instance Methods
class_name()
click to toggle source
Gets this class' name.
# File lib/rsrb/internal/utils.rb, line 4 def class_name self.class.name.split('::').last.to_sym end
err(*lines)
click to toggle source
Log error lines @param lines [Array] lines of text that are passed to the logger.
# File lib/rsrb/internal/utils.rb, line 63 def err(*lines) return unless ENV['LOGGING'].to_i.positive? lines.each do |line| @e_logfile.error(line) if @pastel @log.error(@pastel.magenta.bold("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}")) else @log.error("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}") end end nil end
err!(*lines)
click to toggle source
Log fatal lines @param lines [Array] lines of text that are passed to the logger.
# File lib/rsrb/internal/utils.rb, line 80 def err!(*lines) return unless ENV['LOGGING'].to_i.positive? lines.each do |line| @e_logfile.fatal(line) if @pastel @log.error(@pastel.red.bold("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}")) else @log.error("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}") end end nil end
init_loggers()
click to toggle source
Initialize loggers.
# File lib/rsrb/internal/utils.rb, line 10 def init_loggers return unless ENV['LOGGING'].to_i.positive? FileUtils.mkdir_p("#{FileUtils.pwd}/assets/log") FileUtils.mkdir_p("#{FileUtils.pwd}/assets/log/err") file_names = %W[#{FileUtils.pwd}/assets/log/#{class_name}-#{Time.now.strftime('%Y-%m-%d-%s').chomp}.log #{FileUtils.pwd}/assets/log/err/#{class_name}-#{Time.now.strftime('%Y-%m-%d-%s').chomp}.log] file_names.each { |f| File.write(f, '') } @e_logfile = Logger.new(file_names[0]) @logfile = Logger.new(file_names[1]) @pastel = Pastel.new if ENV['LESS_BORING'].to_i > 1 @log = Console.logger rescue StandardError => e puts 'An error occurred while initializing loggers!' puts e end
log(*lines)
click to toggle source
Log info lines @param lines [Array] lines of text that are passed to the logger.
# File lib/rsrb/internal/utils.rb, line 30 def log(*lines) return unless ENV['LOGGING'].to_i.positive? lines.each do |line| @logfile.info(line) if @pastel @log.info(@pastel.green("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}")) else @log.info("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}") end end nil end
log!(*lines)
click to toggle source
Log warning lines @param lines [Array] lines of text that are passed to the logger.
# File lib/rsrb/internal/utils.rb, line 47 def log!(*lines) return unless ENV['LOGGING'].to_i.positive? lines.each do |line| @logfile.warn(line) if @pastel @log.warn(@pastel.yellow("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}")) else @log.warn("[#{Time.now.strftime('[%H:%M:%S')}]:[#{class_name}] ~> #{line}") end end end
symbolize_file(string)
click to toggle source
Returns the file name as a symbol. @param string [String] The path to the file.
# File lib/rsrb/internal/utils.rb, line 95 def symbolize_file(string) File.basename(string, '*.rb').to_sym end