require "logger"

class DevopsLogger

  def self.create out, level=Logger::INFO, format='%a %d-%m-%Y %H:%M:%S'
    logger = Logger.new out
    logger.level = level
    logger.datetime_format = format
    logger.debug("Logger has been created")
    logger
  end

  def self.access_logger out, level=Logger::INFO, format='%d-%m-%Y %H:%M:%S'
    logger = Logger.new out
    logger.level = level
    logger.datetime_format = format
    logger.formatter = proc do |severity, datetime, progname, msg|
      date_format = datetime.strftime(format)
      "[#{date_format}] #{msg}\n"
    end
    logger.debug("Logger has been created")
    logger
  end

  def self.logger
    @_logger ||= DevopsLogger.create($stdout)
  end

  def self.logger= logger
    @_logger = logger
  end

  def self.level= level
    @level = level
  end

  def self.level
    @level || Logger::INFO
  end
end
