Module: BetterCap::Logger
- Defined in:
- lib/bettercap/logger.rb
Overview
Class responsible for console and file logging.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- L_RAW =
0- L_DBG =
1- L_INF =
2- L_WRN =
3- L_ERR =
4- @@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
messageas 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.
108 109 110 111 112 |
# File 'lib/bettercap/logger.rb', line 108 def debug() if @@debug and not @@silent @@queue.push Logger::Entry.new( , Logger::L_DBG, ) end end |
.error(message) ⇒ Object
Log an error message.
93 94 95 |
# File 'lib/bettercap/logger.rb', line 93 def error() @@queue.push Logger::Entry.new( , Logger::L_ERR, ) end |
.exception(e) ⇒ Object
Log the exception e, if this is a beta version, log it as a warning, otherwise as a debug message.
84 85 86 87 88 89 90 |
# File 'lib/bettercap/logger.rb', line 84 def exception(e) msg = "Exception : #{e.class}\n" + "Message : #{e.message}\n" + "Backtrace :\n\n #{e.backtrace.join("\n ")}\n" self.debug(msg) end |
.info(message) ⇒ Object
Log an information message.
98 99 100 |
# File 'lib/bettercap/logger.rb', line 98 def info() @@queue.push( Logger::Entry.new( , Logger::L_INF, ) ) unless @silent end |
.init(ctx) ⇒ Object
Initialize the logging system.
73 74 75 76 77 78 79 80 |
# File 'lib/bettercap/logger.rb', line 73 def init( ctx ) @@debug = ctx..core.debug @@logfile = ctx..core.logfile @@silent = ctx..core.silent = ctx..core. @@ctx = ctx @@thread = Thread.new { worker } end |
.raw(message) ⇒ Object
Log a message as it is.
115 116 117 |
# File 'lib/bettercap/logger.rb', line 115 def raw() @@queue.push( Logger::Entry.new( , Logger::L_RAW, ) ) unless @silent end |
.wait! ⇒ Object
Wait for the messages queue to be empty.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/bettercap/logger.rb', line 120 def wait! while not @@queue.empty? msg = @@queue.pop(true) rescue nil if msg emit msg.create end sleep(0.3) if msg.nil? end end |
.warn(message) ⇒ Object
Log a warning message.
103 104 105 |
# File 'lib/bettercap/logger.rb', line 103 def warn() @@queue.push Logger::Entry.new( , Logger::L_WRN, ) end |