require 'mongoid'
require 'db/mongoid/created.rb'
require 'db/mongoid/updated.rb'

require 'db/validators/categories_array.rb'
require 'db/validators/run_list_array.rb'
require 'db/validators/users_array.rb'

module Devops
  class Db

    class << self

      def init(environment)
        config = DevopsConfig.config
        DevopsLogger.logger.info "Loading mongoid in environment '#{environment}'"
        Mongoid.load!(config[:db_config], environment)
        log_level = case (config[:db_log_level] || 'debug').downcase
        when 'info'
          Logger::INFO
        when 'error'
          Logger::ERROR
        when 'warn'
          Logger::WARN
        when 'debug'
          Logger::DEBUG
        else
          Logger::INFO
        end
        Mongoid.logger.level = log_level
        Mongo::Logger.logger.level = log_level

=begin
Mongo::Logger.logger       = ::Logger.new('mongo.log')
Mongo::Logger.logger.level = ::Logger::INFO
=end
      end

    end
  end
end
