Class: Baykit::BayServer::BayLog
- Inherits:
-
Object
- Object
- Baykit::BayServer::BayLog
- Includes:
- Util
- Defined in:
- lib/baykit/bayserver/bay_log.rb
Constant Summary collapse
- LOG_LEVEL_TRACE =
0- LOG_LEVEL_DEBUG =
1- LOG_LEVEL_INFO =
2- LOG_LEVEL_WARN =
3- LOG_LEVEL_ERROR =
4- LOG_LEVEL_FATAL =
5- LOG_LEVEL_NAME =
["TRACE", "DEBUG", "INFO ", "WARN ", "ERROR", "FATAL"]
Class Attribute Summary collapse
-
.full_path ⇒ Object
readonly
Returns the value of attribute full_path.
-
.log_level ⇒ Object
readonly
Returns the value of attribute log_level.
Class Method Summary collapse
- .debug(fmt, *args) ⇒ Object
- .debug_e(err, fmt = nil, *args) ⇒ Object
- .debug_mode? ⇒ Boolean
- .error(fmt, *args) ⇒ Object
- .error_e(err, fmt = nil, *args) ⇒ Object
- .fatal(fmt, *args) ⇒ Object
- .fatal_e(err, fmt = nil, *args) ⇒ Object
- .info(fmt, *args) ⇒ Object
- .log(lvl, stack_idx, err, fmt, args) ⇒ Object
- .print_exception(err) ⇒ Object
- .set_log_level(lvl) ⇒ Object
- .trace(fmt, *args) ⇒ Object
- .trace_mode? ⇒ Boolean
- .warn(fmt, *args) ⇒ Object
- .warn_e(err, fmt = nil, *args) ⇒ Object
Class Attribute Details
.full_path ⇒ Object (readonly)
Returns the value of attribute full_path.
19 20 21 |
# File 'lib/baykit/bayserver/bay_log.rb', line 19 def full_path @full_path end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
18 19 20 |
# File 'lib/baykit/bayserver/bay_log.rb', line 18 def log_level @log_level end |
Class Method Details
.debug(fmt, *args) ⇒ Object
50 51 52 |
# File 'lib/baykit/bayserver/bay_log.rb', line 50 def self.debug(fmt, *args) log(LOG_LEVEL_DEBUG, 3, nil, fmt, args) end |
.debug_e(err, fmt = nil, *args) ⇒ Object
54 55 56 |
# File 'lib/baykit/bayserver/bay_log.rb', line 54 def self.debug_e(err, fmt=nil, *args) log(LOG_LEVEL_DEBUG, 3, err, fmt, args) end |
.debug_mode? ⇒ Boolean
122 123 124 125 |
# File 'lib/baykit/bayserver/bay_log.rb', line 122 def self.debug_mode? @log_level <= LOG_LEVEL_DEBUG #LOG_LEVEL_TRACE < LOG_LEVEL_INFO end |
.error(fmt, *args) ⇒ Object
66 67 68 |
# File 'lib/baykit/bayserver/bay_log.rb', line 66 def self.error(fmt, *args) log(LOG_LEVEL_ERROR, 3, nil , fmt, args) end |
.error_e(err, fmt = nil, *args) ⇒ Object
70 71 72 |
# File 'lib/baykit/bayserver/bay_log.rb', line 70 def self.error_e(err, fmt=nil, *args) log(LOG_LEVEL_ERROR, 3, err, fmt, args) end |
.fatal(fmt, *args) ⇒ Object
74 75 76 |
# File 'lib/baykit/bayserver/bay_log.rb', line 74 def self.fatal(fmt, *args) log(LOG_LEVEL_FATAL, 3, nil , fmt, args) end |
.fatal_e(err, fmt = nil, *args) ⇒ Object
78 79 80 81 |
# File 'lib/baykit/bayserver/bay_log.rb', line 78 def self.fatal_e(err, fmt=nil, *args) log(LOG_LEVEL_FATAL, 3, err, fmt, args) exit(1) end |
.info(fmt, *args) ⇒ Object
42 43 44 |
# File 'lib/baykit/bayserver/bay_log.rb', line 42 def self.info(fmt, *args) log(LOG_LEVEL_INFO, 3, nil, fmt, args) end |
.log(lvl, stack_idx, err, fmt, args) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/baykit/bayserver/bay_log.rb', line 83 def self.log(lvl, stack_idx, err, fmt, args) #pos = caller[1].split("/")[-1] apos = parse_caller(caller[1]) if(!@full_path) apos[0] = File.basename(apos[0]) end pos = "#{apos[0]}:#{apos[1]}" #pos = caller[1] if fmt != nil if lvl >= @log_level begin if args == nil || args.length == 0 msg = sprintf("%s", fmt) else msg = sprintf(fmt, *args) end rescue => e puts(e.class) puts(e. + " " + pos) print_exception(e) msg = fmt end print("[#{Time.now}] #{LOG_LEVEL_NAME[lvl]}. #{msg} (at #{pos})\n") end end if err != nil if debug_mode? || lvl == LOG_LEVEL_FATAL puts(err.class) puts(err. + " " + pos) print_exception err else log(lvl, stack_idx + 1, nil, "%s", err.) end end end |
.print_exception(err) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/baykit/bayserver/bay_log.rb', line 131 def self.print_exception err for s in err.backtrace puts "\t" + s end if err.cause puts "Caused by:" puts err.cause. print_exception err.cause end end |
.set_log_level(lvl) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/baykit/bayserver/bay_log.rb', line 24 def self.set_log_level(lvl) if lvl.casecmp? "trace" @log_level = LOG_LEVEL_TRACE elsif lvl.casecmp? "debug" @log_level = LOG_LEVEL_DEBUG elsif lvl.casecmp? "info" @log_level = LOG_LEVEL_INFO elsif lvl.casecmp? "warn" @log_level = LOG_LEVEL_WARN elsif lvl.casecmp? "error" @log_level = LOG_LEVEL_ERROR elsif lvl.casecmp? "fatal" @log_level = LOG_LEVEL_FATAL else warn(BayMessage.get(:INT_UNKNOWN_LOG_LEVEL, lvl)) end end |
.trace(fmt, *args) ⇒ Object
46 47 48 |
# File 'lib/baykit/bayserver/bay_log.rb', line 46 def self.trace(fmt, *args) log(LOG_LEVEL_TRACE, 3, nil , fmt, args) end |
.trace_mode? ⇒ Boolean
127 128 129 |
# File 'lib/baykit/bayserver/bay_log.rb', line 127 def self.trace_mode? @log_level == LOG_LEVEL_TRACE end |
.warn(fmt, *args) ⇒ Object
58 59 60 |
# File 'lib/baykit/bayserver/bay_log.rb', line 58 def self.warn(fmt, *args) log(LOG_LEVEL_WARN, 3, nil, fmt, args) end |
.warn_e(err, fmt = nil, *args) ⇒ Object
62 63 64 |
# File 'lib/baykit/bayserver/bay_log.rb', line 62 def self.warn_e(err, fmt=nil, *args) log(LOG_LEVEL_WARN, 3, err, fmt, args) end |