Top Level Namespace

Defined Under Namespace

Modules: BDB, DottedIndex, Enumerable, Irc, MonitorMixin, Net, Singleton, TokyoCabinet Classes: Array, ArrayOf, AuthModule, BasicsModule, ConditionVariable, ConfigModule, Exception, FiltersModule, GetTextVersionError, HttpUtilPlugin, IrcLogModule, Module, Numeric, Object, Range, Regexp, RemoteModule, ServerError, String, Symbol, Timer, UnicodePlugin, UrlLinkError, UserDataModule, WordlistModule

Instance Method Summary collapse

Instance Method Details

#debug(message = nil, who_pos = 1) ⇒ Object



107
108
109
# File 'lib/rbot/ircbot.rb', line 107

def debug(message=nil, who_pos=1)
  rawlog(Logger::Severity::DEBUG, message, who_pos)
end

#error(message = nil, who_pos = 1) ⇒ Object



119
120
121
# File 'lib/rbot/ircbot.rb', line 119

def error(message=nil, who_pos=1)
  rawlog(Logger::Severity::ERROR, message, who_pos)
end

#fatal(message = nil, who_pos = 1) ⇒ Object



123
124
125
# File 'lib/rbot/ircbot.rb', line 123

def fatal(message=nil, who_pos=1)
  rawlog(Logger::Severity::FATAL, message, who_pos)
end

#halt_loggerObject



72
73
74
75
76
77
78
# File 'lib/rbot/ircbot.rb', line 72

def halt_logger
  if $log_thread && $log_thread.alive?
    $log_queue << nil
    $log_thread.join
    $log_thread = nil
  end
end

#log(message = nil, who_pos = 1) ⇒ Object



111
112
113
# File 'lib/rbot/ircbot.rb', line 111

def log(message=nil, who_pos=1)
  rawlog(Logger::Severity::INFO, message, who_pos)
end

#log_session_endObject



102
103
104
105
# File 'lib/rbot/ircbot.rb', line 102

def log_session_end
  $logger << "\n\n=== #{botclass} session ended on #{Time.now.strftime($dateformat)} ===\n\n"
  $log_queue << nil
end

#log_session_startObject



97
98
99
100
# File 'lib/rbot/ircbot.rb', line 97

def log_session_start
  $logger << "\n\n=== #{botclass} session started on #{Time.now.strftime($dateformat)} ===\n\n"
  restart_logger
end

#pretty_inspectObject



27
28
29
# File 'lib/rbot/ircbot.rb', line 27

def pretty_inspect
  PP.pp(self, '')
end

#rawlog(level, message = nil, who_pos = 1) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rbot/ircbot.rb', line 47

def rawlog(level, message=nil, who_pos=1)
  call_stack = caller
  if call_stack.length > who_pos
    who = call_stack[who_pos].sub(%r{(?:.+)/([^/]+):(\d+)(:in .*)?}) { "#{$1}:#{$2}#{$3}" }
  else
    who = "(unknown)"
  end
  # Output each line. To distinguish between separate messages and multi-line
  # messages originating at the same time, we blank #{who} after the first message
  # is output.
  # Also, we output strings as-is but for other objects we use pretty_inspect
  case message
  when String
    str = message
  else
    str = message.pretty_inspect
  end
  qmsg = Array.new
  str.each_line { |l|
    qmsg.push [level, l.chomp, who]
    who = ' ' * who.size
  }
  $log_queue.push qmsg
end

#restart_logger(newlogger = false) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rbot/ircbot.rb', line 82

def restart_logger(newlogger = false)
  halt_logger

  $logger = newlogger if newlogger

  $log_thread = Thread.new do
    ls = nil
    while ls = $log_queue.pop
      ls.each { |l| $logger.add(*l) }
    end
  end
end

#warning(message = nil, who_pos = 1) ⇒ Object



115
116
117
# File 'lib/rbot/ircbot.rb', line 115

def warning(message=nil, who_pos=1)
  rawlog(Logger::Severity::WARN, message, who_pos)
end