Sha256: a5b70a658c82c1db36af61d4632e5e3c56e22f293fd2ee920d928d811d864b1c

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

# WebROaR - Ruby Application Server - http://webroar.in/
# Copyright (C) 2009  Goonj LLC
#
# This file is part of WebROaR.
#
# WebROaR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# WebROaR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WebROaR.  If not, see <http://www.gnu.org/licenses/>.

module Webroar
  module Analyzer
    class Logger
      class << self
        def set_log_file(log_file)
          @@log_file = log_file.freeze
          @@debug_msg = true
        end
        
        def info(str)
          log_to_file("Info: " + str.to_s)
        end
        
        def error(str)
          log_to_file("Error: " + str.to_s)
        end
        
        def debug(str)
          log_to_file("Debug: " + str.to_s) if @@debug_msg
        end
        
        def log_to_file(str)
          begin
            File.open(@@log_file, "a") do |f| 
              f.puts get_identifier + str
            end
          rescue Errno::ENOENT
            puts get_identifier + str
          end
        end
        
        def get_identifier
          "#{Time.now.strftime('%a %b %d %H:%M:%S %Y')}-#{Process.pid}-"
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
webroar-0.5.0 src/ruby_lib/analyzer/logger.rb
webroar-0.4.0 src/ruby_lib/analyzer/logger.rb
webroar-0.3.1 src/ruby_lib/analyzer/logger.rb
webroar-0.3.0 src/ruby_lib/analyzer/logger.rb
webroar-0.2.6 src/ruby_lib/analyzer/logger.rb
webroar-0.2.5 src/ruby_lib/analyzer/logger.rb
webroar-0.2.4 src/ruby_lib/analyzer/logger.rb
webroar-0.2.3 src/ruby_lib/analyzer/logger.rb