madvertise-logging 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0a4b6f1185e8275db0a07a0db9ad6f86446de3b
4
+ data.tar.gz: 11b02172846a65b4ae5000e41b2bff4c2753ceb3
5
+ SHA512:
6
+ metadata.gz: b2e1ded1b1116391ed7b265767f7ca91533b266743611fa043227eeacdec6808d80d1491d9422d4626bafa24aa23b73e6980d0cf4b65a20f8abe6c85670d0548
7
+ data.tar.gz: c87d53db19b474c4db8168de0e8f166e7d17e7c1e70fca07da35ff8b3c220528fe23ef8fa2f286b031c961fa9c83ff92e8f4662935484216925a56c5499694a1
data/Rakefile CHANGED
@@ -1,8 +1,3 @@
1
- #!/usr/bin/env rake
2
-
3
- require "bundler/setup"
4
1
  require "bundler/gem_tasks"
5
2
 
6
3
  Dir['tasks/**/*.rake'].each { |t| load t }
7
-
8
- task :default => [:spec]
@@ -114,6 +114,7 @@ module Madvertise
114
114
  # @param [Symbol, Fixnum] level New level as Symbol or Fixnum from Logger class.
115
115
  # @return [Fixnum] New level converted to Fixnum from Logger class.
116
116
  def level=(level)
117
+ @console.setThreshold(org.apache.log4j.Level.const_get(level.to_s.upcase.to_sym)) if @console
117
118
  logger.level = level.is_a?(Symbol) ? self.class.severities[level] : level
118
119
  define_level_methods
119
120
  end
@@ -123,7 +124,7 @@ module Madvertise
123
124
  # We do this dynamically here, so we can implement a no-op for levels
124
125
  # which are disabled.
125
126
  self.class.severities.each do |severity, num|
126
- if num >= logger.level
127
+ if num >= level
127
128
  instance_eval(<<-EOM, __FILE__, __LINE__)
128
129
  def #{severity}(*args, &block)
129
130
  if block_given?
@@ -177,7 +178,7 @@ module Madvertise
177
178
  end
178
179
 
179
180
  def add(severity, message, attribs = {})
180
- severity = severity.is_a?(Symbol) ? self.class.severities[severity] : severity
181
+ severity = severity.is_a?(Symbol) ? severity : self.class.severities.key(severity)
181
182
 
182
183
  attribs.merge!(called_from) if @log_caller
183
184
  attribs.merge!(token: @token) if @token
@@ -186,7 +187,7 @@ module Madvertise
186
187
  end.join(' ')
187
188
 
188
189
  message = "#{message} #{attribs}" if attribs.length > 0
189
- logger.add(severity) { message }
190
+ logger.send(severity) { message }
190
191
 
191
192
  return nil
192
193
  end
@@ -247,6 +248,10 @@ module Madvertise
247
248
  self.close
248
249
 
249
250
  case @backend
251
+ when :log4j
252
+ create_log4j_backend
253
+ when :ruby
254
+ create_ruby_logger(STDOUT)
250
255
  when :stdout
251
256
  create_io_backend(STDOUT)
252
257
  when :stderr
@@ -310,7 +315,40 @@ module Madvertise
310
315
  end
311
316
 
312
317
  def create_logger
313
- Logger.new(@logfile).tap do |logger|
318
+ case RUBY_PLATFORM
319
+ when 'java'
320
+ create_log4j_logger
321
+ else
322
+ create_ruby_logger(@logfile)
323
+ end
324
+ end
325
+
326
+ def create_log4j_logger
327
+ begin
328
+ require 'log4jruby'
329
+ Log4jruby::Logger.get($0, :tracing => true, :level => :debug).tap do |logger|
330
+ configure_log4j(logger)
331
+ end
332
+ rescue LoadError
333
+ self.logger = :ruby
334
+ error("Couldn't load log4jruby gem, falling back to pure ruby Logger")
335
+ end
336
+ end
337
+
338
+ def configure_log4j(logger)
339
+ @console = org.apache.log4j.ConsoleAppender.new
340
+ @console.setLayout(org.apache.log4j.PatternLayout.new(Formatter.log4j_format))
341
+ @console.setThreshold(org.apache.log4j.Level::DEBUG)
342
+ @console.activateOptions
343
+
344
+ org.apache.log4j.Logger.getRootLogger.tap do |root|
345
+ root.getLoggerRepository.resetConfiguration
346
+ root.addAppender(@console)
347
+ end
348
+ end
349
+
350
+ def create_ruby_logger(io)
351
+ Logger.new(io).tap do |logger|
314
352
  logger.formatter = Formatter.new
315
353
  logger.progname = progname
316
354
  end
@@ -325,11 +363,13 @@ module Madvertise
325
363
  class Formatter
326
364
 
327
365
  @format = "%{time} %{progname}(%{pid}) [%{severity}] %{msg}\n"
366
+ @log4j_format = "%d %c(%t) [%p] %m%n"
328
367
  @time_format = "%Y-%m-%d %H:%M:%S.%N"
329
368
 
330
369
  class << self
331
370
  # Format string for log messages.
332
371
  attr_accessor :format
372
+ attr_accessor :log4j_format
333
373
 
334
374
  # Format string for timestamps in log messages.
335
375
  attr_accessor :time_format
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "madvertise-logging"
5
- spec.version = "1.0.3"
5
+ spec.version = "1.1.0"
6
6
  spec.authors = ["madvertise Mobile Advertising GmbH"]
7
7
  spec.email = ["tech@madvertise.com"]
8
8
  spec.description = %q{Advanced logging classes with buffer backend, transactions, multi logger, etc}
data/tasks/rspec.rake CHANGED
@@ -4,6 +4,7 @@ begin
4
4
 
5
5
  desc "Run the specs"
6
6
  RSpec::Core::RakeTask.new do |t|
7
+ t.verbose = false
7
8
  t.rspec_opts = ['--options', "spec/spec.opts"]
8
9
  end
9
10
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madvertise-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - madvertise Mobile Advertising GmbH
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
11
+ date: 2013-06-19 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: Advanced logging classes with buffer backend, transactions, multi logger, etc
13
+ description: Advanced logging classes with buffer backend, transactions, multi logger,
14
+ etc
15
15
  email:
16
16
  - tech@madvertise.com
17
17
  executables: []
@@ -43,7 +43,8 @@ files:
43
43
  - tasks/yard.rake
44
44
  homepage: https://github.com/madvertise/logging
45
45
  licenses: []
46
- post_install_message:
46
+ metadata: {}
47
+ post_install_message:
47
48
  rdoc_options: []
48
49
  require_paths:
49
50
  - lib
@@ -51,29 +52,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - '>='
53
54
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
55
  version: '0'
57
- hash: 2
58
- none: false
59
56
  required_rubygems_version: !ruby/object:Gem::Requirement
60
57
  requirements:
61
58
  - - '>='
62
59
  - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
60
  version: '0'
66
- hash: 2
67
- none: false
68
61
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 1.8.24
71
- signing_key:
72
- specification_version: 3
73
- summary: Advanced logging classes with buffer backend, transactions, multi logger, etc
62
+ rubyforge_project:
63
+ rubygems_version: 2.0.3
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Advanced logging classes with buffer backend, transactions, multi logger,
67
+ etc
74
68
  test_files:
75
69
  - spec/improved_logger_spec.rb
76
70
  - spec/multi_logger_spec.rb
77
71
  - spec/spec.opts
78
72
  - spec/spec_helper.rb
79
- has_rdoc:
73
+ has_rdoc: