Skip to content

Commit a28adf7

Browse files
committed
feat: Adds logging to example service
1 parent 9254934 commit a28adf7

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

examples/echo_endpoint.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@
77
class EchoService
88
include Rubyists::Leopard::NatsApiServer
99

10+
config.logger = SemanticLogger[:EchoService]
1011
def initialize(a_var: 1)
1112
logger.info "EchoService initialized with a_var: #{a_var}"
1213
end
1314

14-
endpoint(:echo) { |msg| Success(msg.data) }
15-
endpoint(:echo_fail) { |msg| Failure({ failure: '*boom*', data: msg.data }) }
15+
endpoint(:echo) do |msg|
16+
data = msg.data
17+
logger.trace('Received message', data:)
18+
Success(data)
19+
end
20+
endpoint(:echo_fail) do |msg|
21+
data = msg.data
22+
logger.trace('Received message', data:)
23+
Failure({ failure: '*boom*', data: msg.data })
24+
end
1625
end
1726

1827
if __FILE__ == $PROGRAM_NAME
1928
SemanticLogger.default_level = :info
29+
SemanticLogger.add_signal_handler
2030
SemanticLogger.add_appender(io: $stdout, formatter: :color)
2131
EchoService.run(
2232
nats_url: 'nats://localhost:4222',
@@ -25,6 +35,6 @@ def initialize(a_var: 1)
2535
version: '1.0.0',
2636
instance_args: { a_var: 2 },
2737
},
28-
instances: 1,
38+
instances: ENV.fetch('ECHO_INSTANCES', '1').to_i,
2939
)
3040
end

0 commit comments

Comments
 (0)