Skip to content

Commit 45968d2

Browse files
authored
Create main.rb
1 parent b1c1f1e commit 45968d2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

example-project/main.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This file showcases usage of logtail on Ruby projects
2+
# For more information visit https://github.com/logtail/logtail-ruby
3+
4+
# SETUP
5+
6+
# Include logtail library
7+
require "logtail"
8+
9+
# Check for program arguments
10+
if ARGV.length != 1
11+
puts "Program needs source token to run. Run the program as followed\nruby main.rb <source-token>"
12+
exit
13+
end
14+
# Create logger
15+
http_device = Logtail::LogDevices::HTTP.new(ARGV[0])
16+
logger = Logtail::Logger.new(http_device)
17+
18+
# LOGGING
19+
20+
# Send debug logs messages using the debug() method
21+
logger.debug("Logtail is ready!")
22+
23+
# Send informative messages about interesting events using the info() method
24+
logger.info("I am using Logtail!")
25+
26+
# Send messages about worrying events using the warn() method
27+
# You can also log additional structured data
28+
logger.warn(
29+
"log structured data",
30+
item: {
31+
url: "https://fictional-store.com/item-123",
32+
price: 100.00
33+
}
34+
)
35+
36+
# Send error messages using the error() method
37+
logger.error("Oops! An error occurred!")
38+
39+
# Send messages about fatal events that caused the app to crash using the fatal() method
40+
logger.fatal("Application crash! Needs to be fixed ASP!")
41+
42+
puts "All done! You can check your logs now."

0 commit comments

Comments
 (0)