This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Rakefile
78 lines (71 loc) · 2.42 KB
/
Rakefile
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "bundler/gem_tasks"
require "timber"
def puts_with_level(message, level = :info)
case level
when :info
puts("\e[31m#{message}\e[0m")
when :error
puts("\e[31m#{message}\e[0m")
when :success
puts("\e[32m#{message}\e[0m")
else
puts(message)
end
end
task :test_the_pipes, [:api_key] do |t, args|
support_email = "support@timber.io"
# Do not modify below this line. It's important to keep the `Timber::Logger`
# because it provides an API for logging structured data and capturing context.
header = <<-HEREDOC
^ ^ ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^
/|\\/|\\ /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
/|\\/|\\ /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
/|\\/|\\ /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
============================================================
TIMBER.IO - TESTING THE PIPES
============================================================
HEREDOC
puts header
current_context = Timber::CurrentContext.instance.snapshot
entry = Timber::LogEntry.new(:info, Time.now, nil, "Testing the pipes (click the inspect icon to view more details)", current_context, nil)
http_device = Timber::LogDevices::HTTP.new(args.api_key, flush_continuously: false)
response = http_device.deliver_one(entry)
if response.is_a?(Exception)
message = <<~HEREDOC
Unable to deliver logs.
Here's what we received from the Timber API:
#{response.inspect}
If you continue to have trouble please contact support:
#{support_email}
HEREDOC
puts_with_level(message, :error)
elsif response.is_a?(Net::HTTPResponse)
if response.code.start_with? '2'
puts_with_level("Logs successfully sent! View them at https://app.timber.io",
:success)
else
message =
<<~HEREDOC
Unable to deliver logs.
We received a #{response.code} response from the Timber API:
#{response.body.inspect}
If you continue to have trouble please contact support:
#{support_email}
HEREDOC
puts_with_level(message, :error)
end
end
end
task :console do
require 'irb'
require 'irb/completion'
require 'timber'
$VERBOSE = nil
def reload!
files = $LOADED_FEATURES.select { |feat| feat =~ /\/timber\// }
files.each { |file| load file }
"reloaded"
end
ARGV.clear
IRB.start
end