term-ansicolor-logger 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 1.0.0
@@ -0,0 +1,30 @@
1
+ require("../lib/term/ansicolor/logger");
2
+
3
+ log = Term::ANSIColor::Logger.new(STDOUT);
4
+ log.progname = "sample1";
5
+
6
+ # decorated logger output
7
+ log.debug("decorated logger output:");
8
+ log.debug_cyan("debug_cyan");
9
+ log.info_green("info_green");
10
+ log.warn_magenta("warn_magenta");
11
+ log.error_yellow_bold("error_yellow_bold");
12
+ log.fatal_red_bold("fatal_red_bold");
13
+
14
+ # prefix and suffix
15
+ log.debug("setting prefix and suffix:");
16
+ log.debug_prefix = " '";
17
+ log.debug_suffix = "'";
18
+ log.debug("test1");
19
+ log.debug("test2");
20
+ log.debug("test3");
21
+
22
+ # automatic decoration
23
+ log.debug_decorate(:yellow, :bold);
24
+ log.debug("automatic decoration:");
25
+ log.debug("this debug message decorated automatically yellow & bold.");
26
+ log.debug("prefix & suffix is overwritten, be aware!");
27
+
28
+ # that's all!
29
+ log.debug_decorate();
30
+ log.debug("that's all!!");
@@ -0,0 +1,114 @@
1
+ require("logger");
2
+ require("term/ansicolor");
3
+
4
+ module Term
5
+ module ANSIColor
6
+ class Logger < ::Logger
7
+ SEVERITIES = {
8
+ Logger::Severity::DEBUG => :debug,
9
+ Logger::Severity::INFO => :info,
10
+ Logger::Severity::WARN => :warn,
11
+ Logger::Severity::ERROR => :error,
12
+ Logger::Severity::FATAL => :fatal,
13
+ Logger::Severity::UNKNOWN => :unknown,
14
+ };
15
+ SEVERITY_NAMES = SEVERITIES.values;
16
+
17
+ attr_accessor :prefix, :suffix;
18
+ SEVERITY_NAMES.each { |severity|
19
+ eval %Q{
20
+ attr_accessor :#{severity}_prefix, :#{severity}_suffix;
21
+ }
22
+ }
23
+
24
+ alias_method :base_add, :add;
25
+ alias_method :base_log, :log;
26
+ SEVERITY_NAMES.each { |severity|
27
+ eval %Q{
28
+ alias_method :base_#{severity}, :#{severity};
29
+ }
30
+ }
31
+
32
+ COLORS = [
33
+ nil,
34
+ :black,
35
+ :red,
36
+ :green,
37
+ :yellow,
38
+ :blue,
39
+ :magenta,
40
+ :cyan,
41
+ :white,
42
+ ];
43
+
44
+ DECORATIONS = [
45
+ nil,
46
+ :bold,
47
+ :dark,
48
+ :italic,
49
+ :underline,
50
+ :underscore,
51
+ :blink,
52
+ :rapid_blink,
53
+ :negative,
54
+ :concealed,
55
+ :strikethrough,
56
+ ];
57
+
58
+ def initialize(dst)
59
+ super;
60
+ @prefix = "";
61
+ @suffix = "";
62
+ end
63
+
64
+ def add(severity, message = nil, progname = nil)
65
+ if (message.nil? && progname.nil?)
66
+ super(severity, message, progname);
67
+ else
68
+ prefix = eval("(!@#{SEVERITIES[severity]}_prefix.nil?) ? @#{SEVERITIES[severity]}_prefix:@prefix");
69
+ suffix = eval("(!@#{SEVERITIES[severity]}_suffix.nil?) ? @#{SEVERITIES[severity]}_suffix:@suffix");
70
+ if (message.nil?)
71
+ super(severity, message, prefix + progname + suffix);
72
+ else
73
+ super(severity, prefix + message + suffix, progname);
74
+ end
75
+ end
76
+ end
77
+
78
+ def log(severity, message = nil, progname = nil)
79
+ add(severity, message, progname);
80
+ end
81
+
82
+ SEVERITY_NAMES.each { |s|
83
+ eval %Q{
84
+ def #{s}_decorate(*args)
85
+ @#{s}_prefix = args.inject("") { |f,arg| f + eval("Term::ANSIColor::\#{arg}") };
86
+ @#{s}_suffix = Term::ANSIColor::reset;
87
+ end
88
+ }
89
+ }
90
+
91
+ SEVERITY_NAMES.each { |s|
92
+ COLORS.each { |c|
93
+ DECORATIONS.each { |d|
94
+ next if (c.nil? && d.nil?);
95
+
96
+ f = s.to_s();
97
+ f += "_#{c}" if (c);
98
+ f += "_#{d}" if (d);
99
+ x = "";
100
+ x += eval("Term::ANSIColor::#{c}") if (c);
101
+ x += eval("Term::ANSIColor::#{d}") if (d);
102
+
103
+ eval %Q{
104
+ def #{f}(message = nil)
105
+ # This method can use prefix/suffix
106
+ #{s}("#{x}" + message + Term::ANSIColor::reset);
107
+ end
108
+ }
109
+ }
110
+ }
111
+ }
112
+ end
113
+ end
114
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{term-ansicolor-logger}
8
- s.version = "0.0.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["lpm11"]
12
- s.date = %q{2011-09-16}
12
+ s.date = %q{2011-09-17}
13
13
  s.description = %q{logger with term-ansicolor. That's all!}
14
14
  s.email = %q{lpm11r@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "examples/sample1.rb",
28
29
  "lib/term/ansicolor/logger.rb",
29
30
  "spec/spec_helper.rb",
30
31
  "spec/term-ansicolor-logger_spec.rb",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: term-ansicolor-logger
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - lpm11
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-16 00:00:00 +09:00
13
+ date: 2011-09-17 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ files:
86
86
  - README.rdoc
87
87
  - Rakefile
88
88
  - VERSION
89
+ - examples/sample1.rb
89
90
  - lib/term/ansicolor/logger.rb
90
91
  - spec/spec_helper.rb
91
92
  - spec/term-ansicolor-logger_spec.rb
@@ -104,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
105
  requirements:
105
106
  - - ">="
106
107
  - !ruby/object:Gem::Version
107
- hash: 1882280947418685667
108
+ hash: 691445643208458628
108
109
  segments:
109
110
  - 0
110
111
  version: "0"