Module: ALib::Logging::LogMethods

Included in:
ALib::Logging
Defined in:
lib/alib.rb,
lib/alib-0.3.1.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

–{{{



970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'lib/alib.rb', line 970

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

–}}}



983
984
985
986
987
# File 'lib/alib.rb', line 983

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

#btrace(e) ⇒ Object

–}}}



1031
1032
1033
1034
1035
# File 'lib/alib.rb', line 1031

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

#emsg(e) ⇒ Object

–}}}



1026
1027
1028
1029
1030
# File 'lib/alib.rb', line 1026

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

#errmsg(e) ⇒ Object

–}}}



1036
1037
1038
1039
1040
# File 'lib/alib.rb', line 1036

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

#log_err(e) ⇒ Object



1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/alib.rb', line 1017

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

#loggerObject

–}}}



988
989
990
991
992
993
994
995
996
997
998
999
# File 'lib/alib.rb', line 988

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

–}}}



1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'lib/alib.rb', line 1000

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