logging-odd_even 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f45ebc375e8fb4d2fe04f6c1dec2ff691287f44
4
+ data.tar.gz: b050520a0fb4bf4b381be719ceace135ee43c3f9
5
+ SHA512:
6
+ metadata.gz: c344a947bff3b08e9b200a439ac2d55a7ea8808ba7ae5bedb21a384c4c90af4454864263dfd7232f00d37cbdc28af73e564959bc77ad8880c530d1b44b2ff283
7
+ data.tar.gz: 750d3203cb7c8beafbc6617dcaf585f5f4107b88bcc9518fd97eb914a5965ff4a8ca6407cb7f653b1174abfd8cfd353c8cff51729462715a654aa2fa6a13726e
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.7, rbenv: 2.1.5) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="little-plugger (v1.1.3, rbenv: 2.1.5) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="logging (v1.8.2, rbenv: 2.1.5) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, rbenv: 2.1.5) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, rbenv: 2.1.5) [gem]" level="application" />
21
+ </component>
22
+ </module>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.1.5" project-jdk-type="RUBY_SDK" />
4
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/logging-odd_even.iml" filepath="$PROJECT_DIR$/.idea/logging-odd_even.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logging-odd_even.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Peter Schrammel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # Logging::OddEven
2
+
3
+ Adds different colors depending on even or odd lines.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'logging-odd_even'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install logging-odd_even
20
+
21
+ ## Usage
22
+
23
+ Color the lines:
24
+ ```
25
+ Logging.color_scheme('bright',
26
+ :lines => {
27
+ :debug => :white,
28
+ :debug_bright => :white_bright,
29
+ :info => :green,
30
+ :info_bright => :green_bright,
31
+ :warn => :yellow,
32
+ :warn_bright => :yellow_bright,
33
+ :error => :red,
34
+ :error_bright => :red_bright,
35
+ :fatal => [:white, :on_red],
36
+ :fatal_bright => [:white_bright, :on_red_bright]
37
+ },
38
+ :date => :white,
39
+ :date_bright => :white_bright,
40
+ :logger => :cyan,
41
+ :logger_bright => :cyan_bright,
42
+ :message => :magenta,
43
+ :message_bright => :magenta_bright
44
+ )
45
+ ```
46
+ or just the log levels:
47
+ ```
48
+ Logging.color_scheme('bright',
49
+ :levels => {
50
+ :debug => :white,
51
+ :debug_bright => :white_bright,
52
+ :info => :green,
53
+ :info_bright => :green_bright,
54
+ :warn => :yellow,
55
+ :warn_bright => :yellow_bright,
56
+ :error => :red,
57
+ :error_bright => :red_bright,
58
+ :fatal => [:white, :on_red],
59
+ :fatal_bright => [:white_bright, :on_red_bright]
60
+ },
61
+ :date => :white,
62
+ :date_bright => :white_bright,
63
+ :logger => :cyan,
64
+ :logger_bright => :cyan_bright,
65
+ :message => :magenta,
66
+ :message_bright => :magenta_bright
67
+
68
+ )
69
+
70
+ Logging.appenders.stdout('stdout',
71
+ :auto_flushing => true,
72
+ :layout => Logging.layouts.even_odd_pattern(:pattern => "[%d] %x %T %-5l %c: %m\n",
73
+ :color_scheme => 'bright')
74
+ )
75
+ ```
76
+
77
+ Start logging to standard out.
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/[my-github-username]/logging-odd_even/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,204 @@
1
+ module Logging
2
+ module Layouts
3
+ def self.even_odd_pattern( *args )
4
+ return ::Logging::Layouts::EvenOddPattern if args.empty?
5
+ ::Logging::Layouts::EvenOddPattern.new(*args)
6
+ end
7
+
8
+ class EvenOddPattern < Pattern
9
+
10
+ def initialize( opts = {} )
11
+ @created_at = Time.now
12
+
13
+ @date_pattern = opts.getopt(:date_pattern)
14
+ @date_method = opts.getopt(:date_method)
15
+ @date_pattern = ISO8601 if @date_pattern.nil? and @date_method.nil?
16
+
17
+ @pattern = opts.getopt(:pattern,
18
+ "[%d] %-#{::Logging::MAX_LEVEL_LENGTH}l -- %c : %m\n")
19
+
20
+ cs_name = opts.getopt(:color_scheme)
21
+ @color_scheme =
22
+ case cs_name
23
+ when false, nil; nil
24
+ when true; ::Logging::ColorScheme[:default]
25
+ else ::Logging::ColorScheme[cs_name] end
26
+
27
+ self.class.create_date_format_methods(self)
28
+ self.class.create_format_method(self)
29
+ end
30
+
31
+ DIRECTIVE_TABLE = {
32
+ 'c' => 'event.logger'.freeze,
33
+ 'd' => 'format_date(event.time)'.freeze,
34
+ 'F' => 'event.file'.freeze,
35
+ 'l' => '::Logging::LNAMES[event.level]'.freeze,
36
+ 'L' => 'event.line'.freeze,
37
+ 'm' => 'format_obj(event.data)'.freeze,
38
+ 'M' => 'event.method'.freeze,
39
+ 'p' => 'Process.pid'.freeze,
40
+ 'r' => 'Integer((event.time-@created_at)*1000).to_s'.freeze,
41
+ 't' => 'Thread.current.object_id.to_s'.freeze,
42
+ 'T' => 'Thread.current[:name]'.freeze,
43
+ 'X' => lambda do |var_name| "::Logging.mdc['#{var_name}']" end,
44
+ 'x' => lambda do |separator| "::Logging.ndc.context.join('#{separator}')" end,
45
+ '%' => :placeholder
46
+ }.freeze
47
+
48
+ class SprintfBag
49
+ def initialize(color_scheme,color_alias_table, directive_table)
50
+ @format_string='"'
51
+ @format_string_bright='"'
52
+ @args=[]
53
+ @name_map={}
54
+ @color_scheme=color_scheme
55
+ @color_alias_table=color_alias_table
56
+ @directive_table = directive_table
57
+
58
+ end
59
+
60
+ # @param [String] pattern_name like 'message' or 'time'
61
+ # @param [String] string the string that needs coloring
62
+ def add_colored(string,pattern_name,arg=nil)
63
+ if @color_scheme and !@color_scheme.lines?
64
+ @format_string << @color_scheme.color(string,@color_alias_table[pattern_name])
65
+ @format_string_bright << @color_scheme.color(string,"#{@color_alias_table[pattern_name]}_bright")
66
+ else
67
+ self << string
68
+ end
69
+
70
+ directive=@directive_table[pattern_name]
71
+ if @directive_table[pattern_name].respond_to?(:call)
72
+ @args << directive.call(arg)
73
+ else
74
+ @args << directive.dup
75
+ end
76
+ self
77
+ end
78
+
79
+ def add(str)
80
+ @format_string << str
81
+ @format_string_bright << str
82
+ self
83
+ end
84
+ alias :<< add
85
+
86
+ def add_arg(arg, modify=false)
87
+ if modify
88
+ @args.last << arg
89
+ else
90
+ @args << arg
91
+ end
92
+ self
93
+ end
94
+
95
+ def add_variable(value,arg="@var")
96
+ map_name="@map_name_#{@name_map.size}"
97
+ @name_map[map_name]=value
98
+ @args << arg.gsub("@var",map_name)
99
+ self
100
+ end
101
+
102
+ def set_variables(obj)
103
+ @name_map.each_pair do |name, value|
104
+ obj.instance_variable_set(name.to_sym, value)
105
+ end
106
+ end
107
+
108
+ def to_sprintf(bright=false)
109
+ format = bright ? @format_string_bright : @format_string
110
+ sprintf = "sprintf("
111
+ sprintf << format + '"'
112
+ sprintf << ', ' + @args.join(', ') unless @args.empty?
113
+ sprintf << ")"
114
+
115
+ if @color_scheme and @color_scheme.lines? #generate colors at runtime
116
+ sprintf = "color_scheme.color(#{sprintf}, event.even? ? ::Logging::LNAMES[event.level] : ::Logging::LNAMES[event.level].to_s + '_bright' )"
117
+
118
+ end
119
+
120
+ sprintf
121
+ end
122
+
123
+
124
+ end
125
+
126
+ def self.create_format_method( pf )
127
+ spf_bag=SprintfBag.new(pf.color_scheme,COLOR_ALIAS_TABLE,DIRECTIVE_TABLE)
128
+ pattern=pf.pattern.dup
129
+
130
+ while true
131
+ m = DIRECTIVE_RGXP.match(pattern)
132
+ # * $1 is the stuff before directive or "" if not applicable
133
+ # * $2 is the %#.# match within directive group
134
+ # * $3 is the directive letter
135
+ # * $4 is the precision specifier for the logger name
136
+ # * $5 is the stuff after the directive or "" if not applicable
137
+
138
+ spf_bag << m[1] unless m[1].empty?
139
+
140
+ case m[3]
141
+ when '%'; spf_bag << '%%'
142
+ when 'c'
143
+ spf_bag.add_colored(m[2]+'s',m[3])
144
+ if m[4]
145
+ precision = Integer(m[4]) rescue nil
146
+ if precision
147
+ raise ArgumentError, "logger name precision must be an integer greater than zero: #{precision}" unless precision > 0
148
+ spf_bag.add_arg(".split(::Logging::Repository::PATH_DELIMITER).last(#{m[4]}).join(::Logging::Repository::PATH_DELIMITER)",true)
149
+ else
150
+ spf_bag << "{#{m[4]}}"
151
+ end
152
+ end
153
+ when 'l' #level is dynamic
154
+ if pf.color_scheme and pf.color_scheme.levels?
155
+ name_map = ::Logging::LNAMES.map { |name| pf.color_scheme.color(("#{m[2]}s" % name), name) }
156
+ name_bright_map = ::Logging::LNAMES.map { |name| pf.color_scheme.color(("#{m[2]}s" % name), "#{name}_bright") }
157
+ the_map={0 => name_map, 1 => name_bright_map}
158
+ spf_bag.add_variable(the_map,"@var[event.odd_even][event.level]") << '%s'
159
+ spf_bag << "{#{m[4]}}" if m[4]
160
+ else
161
+ spf_bag << m[2] + 's'
162
+ spf_bag << "{#{m[4]}}" if m[4]
163
+ spf_bag.add_arg(DIRECTIVE_TABLE[m[3]])
164
+ end
165
+ when 'X'
166
+ raise ArgumentError, "MDC must have a key reference" unless m[4]
167
+ spf_bag.add_colored(m[2] + 's',m[3], m[4])
168
+
169
+ when 'x'
170
+ separator = m[4].to_s
171
+ separator = ' ' if separator.empty?
172
+ spf_bag.add_colored(m[2] + 's',m[3], separator)
173
+
174
+ when *DIRECTIVE_TABLE.keys
175
+ spf_bag.add_colored(m[2] + 's',m[3])
176
+ spf_bag << "{#{m[4]}}" if m[4]
177
+ when nil; break
178
+ else
179
+ raise ArgumentError, "illegal format character - '#{m[3]}'"
180
+ end
181
+
182
+ break if m[5].empty?
183
+ pattern = m[5]
184
+ end
185
+
186
+ sprintf=
187
+
188
+ code = "undef :format if method_defined? :format\n"
189
+ code << "def format( event )
190
+ if event.even?
191
+ #{spf_bag.to_sprintf}
192
+ else
193
+ #{spf_bag.to_sprintf(true)}
194
+ end
195
+ end"
196
+
197
+ ::Logging.log_internal(0) {code}
198
+ spf_bag.set_variables(pf)
199
+ pf._meta_eval(code, __FILE__, __LINE__)
200
+ end
201
+
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,4 @@
1
+ require 'logging'
2
+ require "logging/odd_even/version"
3
+ require "logging/odd_even/patches"
4
+ require "logging/layouts/odd_even_pattern"
@@ -0,0 +1,37 @@
1
+ module Logging
2
+ class ColorScheme
3
+
4
+ RED_BRIGHT = "\e[1;31m".freeze # Set the terminal's foreground ANSI color to red.
5
+ GREEN_BRIGHT = "\e[1;32m".freeze # Set the terminal's foreground ANSI color to green.
6
+ YELLOW_BRIGHT = "\e[1;33m".freeze # Set the terminal's foreground ANSI color to yellow.
7
+ BLUE_BRIGHT = "\e[1;34m".freeze # Set the terminal's foreground ANSI color to blue.
8
+ MAGENTA_BRIGHT = "\e[1;35m".freeze # Set the terminal's foreground ANSI color to magenta.
9
+ CYAN_BRIGHT = "\e[1;36m".freeze # Set the terminal's foreground ANSI color to cyan.
10
+ WHITE_BRIGHT = "\e[1;37m".freeze # Set the terminal's foreground ANSI color to white.
11
+
12
+ ON_RED_BRIGHT = "\e[1;41m".freeze # Set the terminal's background ANSI color to red.
13
+ ON_GREEN_BRIGHT = "\e[1;42m".freeze # Set the terminal's background ANSI color to green.
14
+ ON_YELLOW_BRIGHT = "\e[1;43m".freeze # Set the terminal's background ANSI color to yellow.
15
+ ON_BLUE_BRIGHT = "\e[1;44m".freeze # Set the terminal's background ANSI color to blue.
16
+ ON_MAGENTA_BRIGHT = "\e[1;45m".freeze # Set the terminal's background ANSI color to magenta.
17
+ ON_CYAN_BRIGHT = "\e[1;46m".freeze # Set the terminal's background ANSI color to cyan.
18
+ ON_WHITE_BRIGHT = "\e[1;47m".freeze # Set the terminal's background ANSI color to white.
19
+
20
+ end
21
+ end
22
+
23
+ module Logging
24
+ class LogEvent
25
+ @@last_odd_even=0
26
+
27
+ def odd_even
28
+ @odd_even ||= @@last_odd_even=(@@last_odd_even-1).abs
29
+ end
30
+ def even?
31
+ odd_even == 0
32
+ end
33
+ def odd?
34
+ odd_even == 1
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Logging
2
+ module OddEven
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logging/odd_even/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logging-odd_even"
8
+ spec.version = Logging::OddEven::VERSION
9
+ spec.authors = ["Peter Schrammel"]
10
+ spec.email = ["peter.schrammel@gmx.de"]
11
+ spec.summary = %q{Coloring odd and even line differently with the Logging framework.}
12
+ spec.description = %q{Coloring odd and even line differently with the Logging framework.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "logging", "~> 1.8.1"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging-odd_even
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.1
55
+ description: Coloring odd and even line differently with the Logging framework.
56
+ email:
57
+ - peter.schrammel@gmx.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/encodings.xml"
64
+ - ".idea/logging-odd_even.iml"
65
+ - ".idea/misc.xml"
66
+ - ".idea/modules.xml"
67
+ - ".idea/scopes/scope_settings.xml"
68
+ - ".idea/vcs.xml"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/logging/layouts/odd_even_pattern.rb
74
+ - lib/logging/odd_even.rb
75
+ - lib/logging/odd_even/patches.rb
76
+ - lib/logging/odd_even/version.rb
77
+ - logging-odd_even.gemspec
78
+ homepage: ''
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Coloring odd and even line differently with the Logging framework.
102
+ test_files: []