Module: Log
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- IOBUF =
{}
Class Attribute Summary collapse
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .close(grp = nil) ⇒ Object
- .debug(*args, &block) ⇒ Object
- .disable ⇒ Object
- .error(*args, &block) ⇒ Object
- .fatal(*args, &block) ⇒ Object
- .info(*args, &block) ⇒ Object
- .init(logdev, options = {}) ⇒ Object
- .null(*args, &block) ⇒ Object
- .open(logdev) ⇒ Object
- .pp(*args) ⇒ Object
- .puts(*args) ⇒ Object
- .warn(*args, &block) ⇒ Object
- .write(grp, str, severity = nil) ⇒ Object
Instance Method Summary collapse
- #debug(*args, &block) ⇒ Object
- #error(*args, &block) ⇒ Object
- #fatal(*args, &block) ⇒ Object
- #info(*args, &block) ⇒ Object
- #init(*args) ⇒ Object
- #pp(*args) ⇒ Object
- #puts(*args) ⇒ Object
- #warn(*args, &block) ⇒ Object
- #write(grp, str, severity = nil) ⇒ Object
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/gri/log.rb', line 29 def logger @logger end |
Class Method Details
.close(grp = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gri/log.rb', line 55 def close grp=nil if @logger @logger.close else if grp if (io = IOBUF[grp]) io.close end else for io in IOBUF.values io.close end end end end |
.debug(*args, &block) ⇒ Object
117 118 119 |
# File 'lib/gri/log.rb', line 117 def debug(*args, &block) write :default, args.first, :DEBUG end |
.disable ⇒ Object
136 137 138 139 |
# File 'lib/gri/log.rb', line 136 def disable @logger = nil IOBUF.clear end |
.error(*args, &block) ⇒ Object
126 127 128 |
# File 'lib/gri/log.rb', line 126 def error(*args, &block) write :default, args.first, :ERROR end |
.fatal(*args, &block) ⇒ Object
129 130 131 |
# File 'lib/gri/log.rb', line 129 def fatal(*args, &block) write :default, args.first, :FATAL end |
.info(*args, &block) ⇒ Object
120 121 122 |
# File 'lib/gri/log.rb', line 120 def info(*args, &block) write :default, args.first, :INFO end |
.init(logdev, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gri/log.rb', line 34 def init logdev, ={} shift_age = [:log_shift_age] || 8 shift_size = [:log_shift_size] || 100_000_000 logger = Logger.new logdev, shift_age, shift_size logger.formatter = Log::Formatter.new logger.add Logger::INFO, '-' unless [:no_dash] logger = Logger.new logdev logger.formatter = Log::Formatter.new logger.level = {'fatal'=>Logger::FATAL, 'error'=>Logger::ERROR, 'warn'=>Logger::WARN, 'info'=>Logger::INFO, 'debug'=>Logger::DEBUG, }[([:log_level] || '').downcase] || Logger::INFO Log.logger = logger end |
.null(*args, &block) ⇒ Object
133 134 |
# File 'lib/gri/log.rb', line 133 def null(*args, &block) end |
.open(logdev) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/gri/log.rb', line 48 def open logdev if logdev == '-' logdev = STDOUT end init logdev end |
.pp(*args) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/gri/log.rb', line 109 def pp(*args) if args.size >= 2 and args[0].kind_of?(Symbol) self.puts args[0], args[1..-1].map {|e| e.inspect}.join(', ') else self.puts args.map {|e| e.inspect}.join(', ') end end |
.puts(*args) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/gri/log.rb', line 99 def puts(*args) if args.size >= 2 and args[0].kind_of?(Symbol) grp = args.shift else grp = :default end str = args.join('').chomp + "\n" self.write grp, str end |
.warn(*args, &block) ⇒ Object
123 124 125 |
# File 'lib/gri/log.rb', line 123 def warn(*args, &block) write :default, args.first, :WARN end |
.write(grp, str, severity = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gri/log.rb', line 71 def write grp, str, severity=nil if @logger if severity.kind_of? Symbol severity = @logger.class.const_get severity else severity ||= @logger.class::INFO end begin logger.add severity, str.chomp rescue Logger::Error disable end else io = IOBUF[grp] if io if io.kind_of? File #mtime = io.mtime tstr = Time.now.strftime("%Y-%m-%d %H:%M:%S ") gstr = (grp == :default) ? '' : "#{grp}: " io.print tstr + gstr + str else io.print str io.print "\n" if severity #XXX end end end end |
Instance Method Details
#debug(*args, &block) ⇒ Object
117 118 119 |
# File 'lib/gri/log.rb', line 117 def debug(*args, &block) write :default, args.first, :DEBUG end |
#error(*args, &block) ⇒ Object
126 127 128 |
# File 'lib/gri/log.rb', line 126 def error(*args, &block) write :default, args.first, :ERROR end |
#fatal(*args, &block) ⇒ Object
129 130 131 |
# File 'lib/gri/log.rb', line 129 def fatal(*args, &block) write :default, args.first, :FATAL end |
#info(*args, &block) ⇒ Object
120 121 122 |
# File 'lib/gri/log.rb', line 120 def info(*args, &block) write :default, args.first, :INFO end |
#init(*args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gri/log.rb', line 34 def init logdev, ={} shift_age = [:log_shift_age] || 8 shift_size = [:log_shift_size] || 100_000_000 logger = Logger.new logdev, shift_age, shift_size logger.formatter = Log::Formatter.new logger.add Logger::INFO, '-' unless [:no_dash] logger = Logger.new logdev logger.formatter = Log::Formatter.new logger.level = {'fatal'=>Logger::FATAL, 'error'=>Logger::ERROR, 'warn'=>Logger::WARN, 'info'=>Logger::INFO, 'debug'=>Logger::DEBUG, }[([:log_level] || '').downcase] || Logger::INFO Log.logger = logger end |
#pp(*args) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/gri/log.rb', line 109 def pp(*args) if args.size >= 2 and args[0].kind_of?(Symbol) self.puts args[0], args[1..-1].map {|e| e.inspect}.join(', ') else self.puts args.map {|e| e.inspect}.join(', ') end end |
#puts(*args) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/gri/log.rb', line 99 def puts(*args) if args.size >= 2 and args[0].kind_of?(Symbol) grp = args.shift else grp = :default end str = args.join('').chomp + "\n" self.write grp, str end |
#warn(*args, &block) ⇒ Object
123 124 125 |
# File 'lib/gri/log.rb', line 123 def warn(*args, &block) write :default, args.first, :WARN end |
#write(grp, str, severity = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gri/log.rb', line 71 def write grp, str, severity=nil if @logger if severity.kind_of? Symbol severity = @logger.class.const_get severity else severity ||= @logger.class::INFO end begin logger.add severity, str.chomp rescue Logger::Error disable end else io = IOBUF[grp] if io if io.kind_of? File #mtime = io.mtime tstr = Time.now.strftime("%Y-%m-%d %H:%M:%S ") gstr = (grp == :default) ? '' : "#{grp}: " io.print tstr + gstr + str else io.print str io.print "\n" if severity #XXX end end end end |