Module: ALib::Logging::LogMethods

Defined in:
lib/alib-0.5.1/logging.rb

Overview

implementations of the methods shared by both classes and objects of classes which include Logging

Instance Method Summary collapse

Instance Method Details

#__logger_mutexObject

–{{{



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/alib-0.5.1/logging.rb', line 77

def __logger_mutex
#--{{{
  unless defined?(@__logger_mutex) and @__logger_mutex
    begin
      Thread.critical = true
      @__logger_mutex = Sync::new unless defined?(@__logger_mutex) and @__logger_mutex
    ensure
      Thread.critical = false 
    end
  end
  @__logger_mutex
#--}}}
end

#__logger_syncObject

–}}}



90
91
92
93
94
# File 'lib/alib-0.5.1/logging.rb', line 90

def __logger_sync
#--{{{
  __logger_mutex.synchronize{ yield }
#--}}}
end

#btrace(e) ⇒ Object

–}}}



141
142
143
144
145
# File 'lib/alib-0.5.1/logging.rb', line 141

def btrace e
#--{{{
  e.backtrace.join("\n")
#--}}}
end

#emsg(e) ⇒ Object

–}}}



136
137
138
139
140
# File 'lib/alib-0.5.1/logging.rb', line 136

def emsg e
#--{{{
  "#{ e.message } - (#{ e.class })"
#--}}}
end

#errmsg(e) ⇒ Object

–}}}



146
147
148
149
150
# File 'lib/alib-0.5.1/logging.rb', line 146

def errmsg e
#--{{{
  emsg(e) << "\n" << btrace(e)
#--}}}
end

#log_err(e) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/alib-0.5.1/logging.rb', line 127

def log_err e
#--{{{
  if logger.debug?
    error{ errmsg e } 
  else
    error{ emsg e } 
  end
#--}}}
end

#loggerObject Also known as: logger!

–}}}



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/alib-0.5.1/logging.rb', line 95

def logger
#--{{{
  return @logger if defined?(@logger)
  __logger_sync do          
    unless defined?(@logger)
      klass = Class === self ? self : self::class
      self.logger = klass::default_logger 
    end
  end
  @logger
#--}}}
end

#logger=(log) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/alib-0.5.1/logging.rb', line 108

def logger= log
#--{{{
  __logger_sync do          
    @logger = log
    @logger.extend LoggerExt
    @logger.logdev.dev.sync = true rescue nil 
    @logger
  end
#--}}}
end