tagged: expects not an array anymore. list your tags naturaly: tagged(:a,:b). CustomType: attr logger and severity-methods added for simplier custom loglines: logger.custom( :conn, ip, port).info
This commit is contained in:
parent
d4dd5dfd0e
commit
6c9b038de0
|
@ -28,6 +28,8 @@ end
|
||||||
|
|
||||||
class Semlogger < ::Logger
|
class Semlogger < ::Logger
|
||||||
class CustomType
|
class CustomType
|
||||||
|
attr_accessor :logger
|
||||||
|
|
||||||
def initialize name, *obj
|
def initialize name, *obj
|
||||||
@name, @obj = name.to_s.to_sym, obj
|
@name, @obj = name.to_s.to_sym, obj
|
||||||
end
|
end
|
||||||
|
@ -35,19 +37,26 @@ class Semlogger < ::Logger
|
||||||
def to_semlogger
|
def to_semlogger
|
||||||
[@name] + @obj
|
[@name] + @obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add severity, progname = nil, &block
|
||||||
|
@logger.add severity, self, progname = nil, &block
|
||||||
|
end
|
||||||
|
::Semlogger::Severity.constants.each do |severity|
|
||||||
|
module_eval "def #{severity.downcase}( *a, &e) add #{::Semlogger::Severity.const_get severity}, *a, &e end", __FILE__, __LINE__
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :logdev, :level, :progname
|
attr_accessor :logdev, :level, :progname
|
||||||
class <<self
|
class <<self
|
||||||
attr_accessor :progname
|
attr_accessor :progname
|
||||||
|
|
||||||
def custom *a
|
def custom( *a) CustomType.new *a end
|
||||||
CustomType.new *a
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom *a
|
def custom *a
|
||||||
CustomType.new *a
|
r = CustomType.new *a
|
||||||
|
r.logger = self
|
||||||
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
@@progname = nil
|
@@progname = nil
|
||||||
|
@ -60,7 +69,7 @@ class Semlogger < ::Logger
|
||||||
@level, @data, @tags, @logdev = DEBUG, {}, [], logdev
|
@level, @data, @tags, @logdev = DEBUG, {}, [], logdev
|
||||||
end
|
end
|
||||||
|
|
||||||
def tagged tags, &e
|
def tagged *tags, &e
|
||||||
@tags += tags
|
@tags += tags
|
||||||
tags = tags.size
|
tags = tags.size
|
||||||
yield
|
yield
|
||||||
|
|
Loading…
Reference in a new issue