Module: BetterCap::Logger
- Defined in:
- lib/bettercap/logger.rb
Overview
Class responsible for console and file logging.
Constant Summary collapse
- @@ctx =
nil
- @@queue =
Queue.new
- @@debug =
false
- @@timestamp =
false
- @@silent =
false
- @@logfile =
nil
- @@thread =
nil
Class Method Summary collapse
-
.debug(message) ⇒ Object
Log a debug
message
. -
.error(message) ⇒ Object
Log an error
message
. -
.exception(e) ⇒ Object
Log the exception
e
, if this is a beta version, log it as a warning, otherwise as a debug message. -
.info(message) ⇒ Object
Log an information
message
. -
.init(ctx) ⇒ Object
Initialize the logging system.
-
.raw(message) ⇒ Object
Log a
message
as it is. -
.wait! ⇒ Object
Wait for the messages queue to be empty.
-
.warn(message) ⇒ Object
Log a warning
message
.
Class Method Details
.debug(message) ⇒ Object
Log a debug message
.
65 66 67 68 69 |
# File 'lib/bettercap/logger.rb', line 65 def debug() if @@debug and not @@silent @@queue.push (, 'D').light_black end end |
.error(message) ⇒ Object
Log an error message
.
50 51 52 |
# File 'lib/bettercap/logger.rb', line 50 def error() @@queue.push (, 'E').red end |
.exception(e) ⇒ Object
Log the exception e
, if this is a beta version, log it as a warning, otherwise as a debug message.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bettercap/logger.rb', line 37 def exception(e) msg = "Exception : #{e.class}\n" + "Message : #{e.}\n" + "Backtrace :\n\n #{e.backtrace.join("\n ")}\n" if BetterCap::VERSION.end_with?('b') self.warn(msg) else self.debug(msg) end end |
.info(message) ⇒ Object
Log an information message
.
55 56 57 |
# File 'lib/bettercap/logger.rb', line 55 def info() @@queue.push( (, 'I') ) unless @@silent end |
.init(ctx) ⇒ Object
Initialize the logging system.
26 27 28 29 30 31 32 33 |
# File 'lib/bettercap/logger.rb', line 26 def init( ctx ) @@debug = ctx..core.debug @@logfile = ctx..core.logfile @@silent = ctx..core.silent @@timestamp = ctx..core. @@ctx = ctx @@thread = Thread.new { worker } end |
.raw(message) ⇒ Object
Log a message
as it is.
72 73 74 |
# File 'lib/bettercap/logger.rb', line 72 def raw() @@queue.push( ( , nil ) ) end |
.wait! ⇒ Object
Wait for the messages queue to be empty.
77 78 79 80 81 82 83 84 85 |
# File 'lib/bettercap/logger.rb', line 77 def wait! while not @@queue.empty? if @@thread.nil? emit @@queue.pop else sleep 0.3 end end end |
.warn(message) ⇒ Object
Log a warning message
.
60 61 62 |
# File 'lib/bettercap/logger.rb', line 60 def warn() @@queue.push (, 'W').yellow end |