-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.rb
49 lines (40 loc) · 1.12 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('./lib', __dir__))
require 'klogger'
def example
$stdout.print ' '
yield
end
def print_examples(logger)
example { logger.info('Hello world!', name: 'Adam') }
example { logger.debug('Debug message', age: 30, ip_address: 1.234) }
example { logger.error('This should not happen', number: 4) }
example { logger.warn('Something bad will happen soon if you are not careful') }
begin
1 / 0
rescue StandardError => e
example { logger.exception(e, backtrace: nil) }
end
end
puts
puts <<-'ART'
_
/\ /\ | ___ __ _ __ _ ___ _ __
/ //_/ |/ _ \ / _` |/ _` |/ _ \ '__|
/ __ \| | (_) | (_| | (_| | __/ |
\/ \/|_|\___/ \__, |\__, |\___|_|
|___/ |___/
ART
puts "JSON output\n\n"
logger = Klogger.new('example', formatter: :json, highlight: true)
print_examples(logger)
puts
puts "Simple output\n\n"
logger = Klogger.new('example', formatter: :simple, highlight: true)
print_examples(logger)
puts
puts "Go-style output\n\n"
logger = Klogger.new('example', formatter: :go, highlight: true)
print_examples(logger)
puts
puts