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

Allow to use configurable logger to render wtf message #48

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
10 changes: 10 additions & 0 deletions lib/trailblazer/developer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
require "trailblazer/developer/version"
require "logger"

module Trailblazer
module Developer
# Your code goes here...
class << self
attr_writer :logger

def logger
@logger ||= Logger.new($stdout, formatter: proc { |*, msg| "#{msg}\n" }).tap do |log|
log.progname = self.name
end
end
end
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 @@ -60,7 +60,7 @@ def invoke(activity, (ctx, flow_options), present_options: {}, **circuit_options
&local_present_options_block
)

puts output
Trailblazer::Developer.logger.debug(output)

raise raise_exception if raise_exception
return signal, [ctx, flow_options], circuit_options, output, returned_args
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 @@ -71,7 +71,7 @@ class Create < Trailblazer::Operation


it "#wtf?" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
result = Memo::Operation::Create.wtf?(seq: [], params: {})
end

Expand All @@ -95,7 +95,7 @@ class Create < Trailblazer::Operation
=end

#@ exception
output, _ = capture_io do
output, _ = capture_subprocess_io do
assert_raises ArgumentError do
result = Memo::Operation::Create.wtf?(seq: [], raise_exception: true)
end
Expand Down Expand Up @@ -138,7 +138,7 @@ class Create < Trailblazer::Activity::Railway # Note that this is not an {Operat
end

it "{#wtf?} with {Activity}" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
result = Trailblazer::Developer.wtf?(B::Memo::Operation::Create, [{seq: [], params: {}}, {}])
end

Expand Down
10 changes: 5 additions & 5 deletions test/trace/wtf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def <<(value)
exception = nil
returned_args = nil

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

output, _ = capture_io do
output, _ = capture_subprocess_io do
returned_args = Trailblazer::Developer.wtf?(alpha, [{ seq: [], c: false }])
end

Expand Down Expand Up @@ -96,7 +96,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 Down Expand Up @@ -125,7 +125,7 @@ def <<(value)

signal, ctx, flow_options, circuit_options, output, returned_present_args = nil

captured_output, _ = capture_io do
captured_output, _ = capture_subprocess_io do
signal, (ctx, flow_options), circuit_options, output, returned_present_args = Trailblazer::Developer.wtf?(alpha, [{seq: []}],
present_options: {render_method: my_renderer})
end
Expand Down Expand Up @@ -153,7 +153,7 @@ class PresentCreate < Trailblazer::Activity::Railway
end

it "overrides default color map of entities" do
output, _ = capture_io do
output, _ = capture_subprocess_io do
Trailblazer::Developer.wtf?(
alpha,
[
Expand Down