module LapisLazuli::WorldModule::Logging

Module for easy logging

Manages the following:

@log        - TeeLogger instances

Public Instance Methods

log(msg = nil) click to toggle source

Log “singleton”

Calls superclass method
# File lib/lapis_lazuli/world/logging.rb, line 27
def log(msg = nil)
  super(msg) if msg
  return Runtime.instance.set_if(self, :logger) do
    # Make log directory
    dir = env_or_config('log_dir')
    begin
      Dir.mkdir dir
    rescue SystemCallError => ex
      # Swallow this error; it occurs (amongst other situations) when the
      # directory exists. Checking for an existing directory beforehand is
      # not concurrency safe.
    end

    # Start the logger with the config filename
    log_file = "#{dir}#{File::SEPARATOR}#{File.basename(Config.config_files[0], ".*")}.log"
    # Or a filename from the environment
    if has_env_or_config?("log_file")
      log_file = env_or_config("log_file")
    end
    l = TeeLogger::TeeLogger.new(log_file)
    l.level = env_or_config("log_level")

    l
  end
end