Kouhei Sutou
null+****@clear*****
Thu Aug 7 23:47:42 JST 2014
Kouhei Sutou 2014-08-07 23:47:42 +0900 (Thu, 07 Aug 2014) New Revision: da4665a87d36edb2f0de793d1d28cf20b28ed432 https://github.com/groonga/groonga/commit/da4665a87d36edb2f0de793d1d28cf20b28ed432 Message: mruby: add logger Added files: lib/mrb/scripts/logger.rb lib/mrb/scripts/logger/level.rb Modified files: lib/mrb/mrb_logger.c lib/mrb/scripts/sources.am Modified: lib/mrb/mrb_logger.c (+3 -0) =================================================================== --- lib/mrb/mrb_logger.c 2014-08-07 23:46:44 +0900 (f42d2a7) +++ lib/mrb/mrb_logger.c 2014-08-07 23:47:42 +0900 (4917694) @@ -69,5 +69,8 @@ grn_mrb_logger_init(grn_ctx *ctx) mrb_define_method(mrb, klass, "need_log?", logger_need_log_p, MRB_ARGS_REQ(1)); mrb_define_method(mrb, klass, "log", logger_log, MRB_ARGS_REQ(5)); + + grn_mrb_load(ctx, "logger/level.rb"); + grn_mrb_load(ctx, "logger.rb"); } #endif Added: lib/mrb/scripts/logger.rb (+14 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/logger.rb 2014-08-07 23:47:42 +0900 (4a6c99a) @@ -0,0 +1,14 @@ +module Groonga + class Logger + def log_error(error) + log_level = Level::ERROR.to_i + error.backtrace.each do |entry| + match_data = /:(\d+):/.match(entry) + file = match_data.pre_match + line = match_data[1].to_i + method = match_data.post_match.gsub(/^in /, "") + log(log_level, file, line, method, match_data.post_match) + end + end + end +end Added: lib/mrb/scripts/logger/level.rb (+32 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/logger/level.rb 2014-08-07 23:47:42 +0900 (b766099) @@ -0,0 +1,32 @@ +module Groonga + class Logger + class Level + @@names = {} + def self.find(name) + @@names[name] + end + + attr_reader :name + def initialize(name, level) + @@names[name] = self + @name = name + @level = level + end + + def to_i + @level + end + + NONE = new(:none, 0) + EMERG = new(:emerg, 1) + ALERT = new(:alert, 2) + CRIT = new(:crit, 3) + ERROR = new(:error, 4) + WARNING = new(:warning, 5) + NOTICE = new(:notice, 6) + INFO = new(:info, 7) + DEBUG = new(:debug, 8) + DUMP = new(:dump, 9) + end + end +end Modified: lib/mrb/scripts/sources.am (+2 -0) =================================================================== --- lib/mrb/scripts/sources.am 2014-08-07 23:46:44 +0900 (c7d4966) +++ lib/mrb/scripts/sources.am 2014-08-07 23:47:42 +0900 (0e64f7e) @@ -5,5 +5,7 @@ RUBY_SCRIPT_FILES = \ eval_context.rb \ expression.rb \ index_info.rb \ + logger.rb \ + logger/level.rb \ scan_info.rb \ scan_info_builder.rb -------------- next part -------------- HTML����������������������������... Télécharger