Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logger and configuration #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.0.30
* Add Logger to Trailblazer Developer

# 0.0.20
* Ruby 2.7 support

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018-2020 Trailblazer GmbH
Copyright (c) 2018-2021 Trailblazer GmbH

Trailblazer is an Open Source project licensed under the terms of
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
Expand Down
5 changes: 4 additions & 1 deletion lib/trailblazer/developer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require "trailblazer/developer/version"
require "dry-configurable"
require "logger"

module Trailblazer
module Developer
# Your code goes here...
extend Dry::Configurable
setting(:logger, Logger.new($stdout), reader: true )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of a global var, that logger could sit in flow_options!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sitting inside Trailblazer::Developer

end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/trailblazer/developer/wtf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def invoke(activity, (ctx, flow_options), **circuit_options)

return signal, [ctx, flow_options], circuit_options
ensure
puts Trace::Present.(
Trailblazer::Developer.logger.info Trace::Present.(
flow_options[:stack],
renderer: Wtf::Renderer,
color_map: Wtf::Renderer::DEFAULT_COLOR_MAP.merge( flow_options[:color_map] || {} ),
Expand Down
6 changes: 3 additions & 3 deletions test/docs/developer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create(ctx, input:, **)
_(signal.inspect).must_equal %{#<Trailblazer::Activity::End semantic=:success>}
_(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}}

output, _ = capture_io do
output, _ = capture_subprocess_io do
#:wtf-focus-steps
Dev.wtf?(Memo::Create, [ctx, { focus_on: { steps: [:validate, :create_memo] } }])
#:wtf-focus-steps end
Expand All @@ -67,7 +67,7 @@ def create(ctx, input:, **)
`-- End.success
}

output, _ = capture_io do
output, _ = capture_subprocess_io do
#:wtf-focus-steps-with-variables
Dev.wtf?(Memo::Create, [ctx, { focus_on: { variables: [:params], steps: :validate } }])
#:wtf-focus-steps-with-variables end
Expand All @@ -84,7 +84,7 @@ def create(ctx, input:, **)
`-- End.success
}

output, _ = capture_io do
output, _ = capture_subprocess_io do
#:wtf-default-inspector
Dev.wtf?(
Memo::Create,
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
require "trailblazer/activity/dsl/linear"
puts "Running in Ruby #{RUBY_VERSION}"

Trailblazer::Developer.config.logger = Logger.new($stdout, formatter: proc do |severity, datetime, progname, msg|
"#{msg}\n"
end)

T = Trailblazer::Activity::Testing

Minitest::Spec.class_eval do
Expand Down
20 changes: 10 additions & 10 deletions test/trace/wtf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def <<(value)
end

it "traces until charlie, 3-level and exception occurs" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
assert_raises RuntimeError do
Trailblazer::Developer.wtf?(alpha, [{ seq: Raiser.new(raise_in: :c) }])
end
Expand All @@ -58,7 +58,7 @@ def <<(value)
end

it "traces until charlie, 3-level and step takes left track" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(alpha, [{ seq: [], c: false }])
end

Expand All @@ -78,7 +78,7 @@ def <<(value)
end

it "traces alpha and it's subprocesses, for successful execution" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(alpha, [{ seq: [] }])
end

Expand All @@ -101,7 +101,7 @@ def <<(value)
end

it "overrides default color map of entities" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -158,7 +158,7 @@ def <<(value)
end

it "captures input & output for given step and ctx (captures whole ctx by default)" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -200,7 +200,7 @@ def <<(value)
step method(:b)
end

output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -256,7 +256,7 @@ def <<(value)
end

it "captures input & output inspect for given step and variable within ctx" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -294,7 +294,7 @@ def <<(value)
end

it "captures input & output for given 1/more steps and selected variables witin ctx" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -337,7 +337,7 @@ def <<(value)
end

it "allows passing custom inspector" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down Expand Up @@ -377,7 +377,7 @@ def <<(value)
flow_options = { flow: true }
circuit_options = { circuit: true }

capture_io do
capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[ctx, flow_options],
Expand Down
11 changes: 6 additions & 5 deletions trailblazer-developer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ Gem::Specification.new do |spec|
end
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler"
spec.add_development_dependency "minitest"
spec.add_development_dependency "minitest-line"
spec.add_development_dependency "rake"

spec.add_dependency "trailblazer-activity", ">= 0.11.0", "< 1.0.0"
spec.add_dependency "trailblazer-activity-dsl-linear"
spec.add_dependency "representable"
spec.add_dependency "hirb"
spec.add_dependency "dry-configurable", "~> 0.11"

spec.add_development_dependency "bundler"
spec.add_development_dependency "minitest"
spec.add_development_dependency "minitest-line"
spec.add_development_dependency "rake"
end