Sha256: 3b2bdfad536111d1617ef36093b77898963fa5f98722a99ea1837948652dffee

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require 'logger'

module Chatterbot

  #
  # routines for outputting log messages, as well as logging tweets
  # to the database if desired.
  module Logging

    #
    # log a message
    def debug(s)
      puts s if verbose?
      logger.debug s unless ! logging?
    end

    #
    # something really bad happened, print it out and log it
    def critical(s)
      puts s
      debug s
    end
    
    #
    # log a tweet to the database
    def log(txt, source=nil)
      return unless log_tweets?

      data = {:txt => txt, :bot => botname, :created_at => Time.now}
      if source != nil
        data = data.merge(:user => source[:from_user],
                          :source_id => source[:id],
                          :source_tweet => source[:text])
      end

      # populate the table
      db[:tweets].insert(data)
    end

protected
    #
    # initialize a Logger object, writing to log_dest
    def logger
      # log to the dest specified in the config file, rollover after 10mb of data
      @_logger ||= Logger.new(log_dest, 0, 1024 * 1024)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chatterbot-0.2.6 lib/chatterbot/logging.rb
chatterbot-0.2.5 lib/chatterbot/logging.rb
chatterbot-0.2.4 lib/chatterbot/logging.rb
chatterbot-0.2.3 lib/chatterbot/logging.rb