Module: ALib::Logging::LogMethods

Included in:
ALib::Logging
Defined in:
lib/alib-0.4.0/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

–{{{



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/alib-0.4.0/logging.rb', line 27

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

–}}}



40
41
42
43
44
# File 'lib/alib-0.4.0/logging.rb', line 40

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

#btrace(e) ⇒ Object

–}}}



88
89
90
91
92
# File 'lib/alib-0.4.0/logging.rb', line 88

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

#emsg(e) ⇒ Object

–}}}



83
84
85
86
87
# File 'lib/alib-0.4.0/logging.rb', line 83

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

#errmsg(e) ⇒ Object

–}}}



93
94
95
96
97
# File 'lib/alib-0.4.0/logging.rb', line 93

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

#log_err(e) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/alib-0.4.0/logging.rb', line 74

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

#loggerObject

–}}}



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/alib-0.4.0/logging.rb', line 45

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

–}}}



57
58
59
60
61
62
63
64
65
66
# File 'lib/alib-0.4.0/logging.rb', line 57

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