Skip to content

Commit

Permalink
Merge branch 'master' into freezing_by_default
Browse files Browse the repository at this point in the history
  • Loading branch information
tilfin authored May 24, 2018
2 parents 770fe02 + 50f2351 commit 5584cd0
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rvm:
- 2.4.1
- 2.5.0
- 2.6.0-preview1
- jruby
before_install: gem install bundler -v 1.11.2
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
Expand Down
1 change: 1 addition & 0 deletions lib/ougai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
require 'ougai/formatters/bunyan'
require 'ougai/formatters/readable'
require 'ougai/formatters/pino'
require 'ougai/serializer'
require 'ougai/child_logger'
require 'ougai/logger'
8 changes: 2 additions & 6 deletions lib/ougai/formatters/for_json.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'oj'

module Ougai
# The features for JSON formatter
# @attr [Boolean] jsonize Whether log should converts JSON
Expand All @@ -14,6 +12,7 @@ module Formatters::ForJson
def init_opts_for_json(opts)
@jsonize = opts.fetch(:jsonize, true)
@with_newline = opts.fetch(:with_newline, true)
@serializer = Ougai::Serializer.for_json
end

def to_level(severity)
Expand All @@ -35,14 +34,11 @@ def to_level(severity)
end
end

OJ_OPTIONS = { mode: :custom, time_format: :xmlschema,
use_as_json: true, use_to_hash: true, use_to_json: true }

# requires convert_time(data) method
def dump(data)
return data unless @jsonize
convert_time(data)
str = Oj.dump(data, OJ_OPTIONS)
str = @serializer.serialize(data)
str << "\n" if @with_newline
str
end
Expand Down
13 changes: 13 additions & 0 deletions lib/ougai/serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Ougai
class Serializer
def self.for_json
if RUBY_PLATFORM =~ /java/
require 'ougai/serializers/json_jr_jackson'
Serializers::JsonJrJackson.new
else
require 'ougai/serializers/json_oj'
Serializers::JsonOj.new
end
end
end
end
9 changes: 9 additions & 0 deletions lib/ougai/serializers/json_jr_jackson.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'jrjackson'

module Ougai::Serializers
class JsonJrJackson < Ougai::Serializer
def serialize(data)
JrJackson::Json.dump(data)
end
end
end
12 changes: 12 additions & 0 deletions lib/ougai/serializers/json_oj.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'oj'

module Ougai::Serializers
class JsonOj < Ougai::Serializer
OJ_OPTIONS = { mode: :custom, time_format: :xmlschema,
use_as_json: true, use_to_hash: true, use_to_json: true }

def serialize(data)
Oj.dump(data, OJ_OPTIONS)
end
end
end
2 changes: 1 addition & 1 deletion lib/ougai/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Ougai
VERSION = '1.6.5'
VERSION = '1.6.6'
end
9 changes: 8 additions & 1 deletion ougai.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.1.2'
spec.add_dependency "oj", "~> 3.4"

if RUBY_PLATFORM =~ /java/
spec.platform = 'java'
spec.add_dependency 'jrjackson', '~> 0.4'
else
spec.add_dependency "oj", "~> 3.4"
end

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
2 changes: 1 addition & 1 deletion spec/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
err = actual[:err]
err[:message] == expected \
&& err[:name] = 'StandardError' \
&& err[:stack].include?('ougai/spec')
&& err[:stack].include?('<main>')
end
end

Expand Down

0 comments on commit 5584cd0

Please sign in to comment.