Class: Dakwak::LogManager
- Inherits:
-
Object
- Object
- Dakwak::LogManager
- Defined in:
- lib/dakwak/log_manager.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ LogManager
constructor
A new instance of LogManager.
-
#log(msg, level, opts = {}) ⇒ Object
Available options: => :vanilla Message will be logged with no formatting (default: false ) => :timestamp Whether to prefix the message with a timestamp (default: true) opts: deprecated, use accessors instead.
Constructor Details
#initialize ⇒ LogManager
Returns a new instance of LogManager.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dakwak/log_manager.rb', line 7 def initialize @log_mtx = Mutex.new @@opts = { timestamp: true, vanilla: false } # @sl = Syslog.open(Dakwak.app_name, Syslog::LOG_PID, Syslog::LOG_DAEMON) @sl = Syslog.open(Dakwak.app_name, 0, Syslog::LOG_DAEMON) @@levels ||= { } LogLevel.constants.each { |c| @@levels[LogLevel.const_get(c)] = c.to_s.downcase } # for syslog compatibility @@levels["W"] = "warning" @@levels["E"] = "err" super() end |
Class Method Details
.disable_timestamps ⇒ Object
21 22 23 |
# File 'lib/dakwak/log_manager.rb', line 21 def @@opts[:timestamp] = false end |
.enable_timestamps ⇒ Object
25 26 27 |
# File 'lib/dakwak/log_manager.rb', line 25 def @@opts[:timestamp] = true end |
Instance Method Details
#log(msg, level, opts = {}) ⇒ Object
Available options:
> :vanilla Message will be logged with no formatting (default: false )
> :timestamp Whether to prefix the message with a timestamp (default: true)
opts: deprecated, use accessors instead
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dakwak/log_manager.rb', line 34 def log(msg, level, opts = {}) @log_mtx.synchronize do puts "#{msg}" or return if @@opts[:vanilla] stamp = Time.now.strftime("%m-%d-%Y %H:%M:%S ") unless @@opts[:timestamp] == false puts "#{stamp}#{Socket.gethostbyname(Socket.gethostname).first} #{Dakwak.app_name} [#{level}] #{msg}" = @@levels[level] # disabling syslog support for now # if @sl.respond_to?(expanded_level) then # @sl.send :"#{expanded_level}", "[#{level}] #{msg}" # end end end |