-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
L-147 Add documentation and example project
- Loading branch information
Showing
6 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
.ruby-version | ||
coverage | ||
Gemfile.lock | ||
!/example-project/Gemfile.lock | ||
*.swp | ||
*.gem | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "rack", "~> 3.0" | ||
|
||
gem "rackup", "~> 2.1" | ||
|
||
gem "logtail-rack", "~> 0.2.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
logtail (0.1.12) | ||
msgpack (~> 1.0) | ||
logtail-rack (0.2.4) | ||
logtail (~> 0.1) | ||
rack (>= 1.2, < 4.0) | ||
msgpack (1.7.2) | ||
rack (3.0.0) | ||
rackup (2.1.0) | ||
rack (>= 3) | ||
webrick (~> 1.8) | ||
webrick (1.8.1) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
|
||
DEPENDENCIES | ||
logtail-rack (~> 0.2.4) | ||
rack (~> 3.0) | ||
rackup (~> 2.1) | ||
|
||
BUNDLED WITH | ||
2.3.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'logtail-rack' | ||
require './logging_app' | ||
|
||
# Initialization of logging middlewares | ||
use Logtail::Integrations::Rack::HTTPContext | ||
use Logtail::Integrations::Rack::HTTPEvents | ||
use Logtail::Integrations::Rack::ErrorEvent | ||
|
||
# HTTP IO device sends logs to Better Stack, replace <SOURCE_TOKEN> with your real source token | ||
http_io_device = Logtail::LogDevices::HTTP.new("<SOURCE_TOKEN>") | ||
|
||
# STDOUT IO device sends logs to console output | ||
stdout_io_device = STDOUT | ||
|
||
# Logger initialization, you can use any number of IO devices | ||
logger = Logtail::Logger.new(http_io_device, stdout_io_device) | ||
Logtail::Config.instance.logger = logger | ||
|
||
# App initialization | ||
logging_app = LoggingApp.new(logger) | ||
run do |env| | ||
logging_app.run(env) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'logtail-rack' | ||
|
||
class LoggingApp | ||
def initialize(logger) | ||
@logger = logger | ||
end | ||
|
||
def run(env) | ||
@logger.info("I am using Better Stack! 🚀") | ||
|
||
# You can also provide additional information when logging | ||
@logger.debug("Logging structured data...", | ||
name: { | ||
first: "John", | ||
last: "Smith" | ||
}, | ||
id: 123456 | ||
) | ||
|
||
raise RuntimeError.new("Visiting /error raises an error. You should see it in Better Stack.") if env["REQUEST_PATH"].start_with?("/error") | ||
|
||
[200, {}, ["All done!\nLog into your Logtail account to check your logs."]] | ||
end | ||
end |