Permalink
Browse files

added example program

  • Loading branch information...
1 parent 029385a commit a5726543d608b17ce94b3ad06433624788bf50b1 Ryan R. Smith committed Aug 24, 2011
Showing with 62 additions and 1 deletion.
  1. +59 −0 example.rb
  2. +3 −1 readme.md
View
@@ -0,0 +1,59 @@
+DB = Sequel.sqlite(:logger => Logger.new('sql.log'))
+
+DB.create_table :events do
+ primary_key :id
+end
+
+DB.create_table :event_logs do
+ primary_key :id
+ foreign_key :event_id, :events
+ String :message
+end
+
+DB.create_table :accounts do
+ primary_key :id
+end
+
+DB.create_table :account_logs do
+ primary_key :id
+ foreign_key :account_id, :accounts
+ String :message
+end
+
+
+class Event < Sequel::Model
+ one_to_many :event_logs
+end
+
+class EventLog < Sequel::Model
+ many_to_one :event
+end
+
+class Account < Sequel::Model
+ one_to_many :account_logs
+end
+
+class AccountLog < Sequel::Model
+ many_to_one :account
+end
+
+
+Event.create
+Account.create
+
+class Provider < Sinatra::Application
+
+ get "/events" do
+ event = Event.first
+ account = Account.first
+
+ splunk_logger = Logger.new("splunk.log")
+ LogJam.setup_logger(splunk_logger, :info)
+
+ LogJam.priorities(:account, :event)
+ LogJam.puts("event=#{event.id} account=#{account.id} time=#{Time.now.to_i}")
+ LogJam.write_to_disk
+ event.event_logs.map(&:message).join("<br />")
+ end
+
+end
View
@@ -32,9 +32,11 @@ better way to query your data set than SQL.
### API
+**Also, checkout example.rb**
+
```ruby
require 'log_jam'
-
+
# log_jam will pass along log messages in real time. log_jam will not wait for
# you to call drain before it sends messages to the default logger.
LogJam.setup_logger(Rails.logger, :info)

0 comments on commit a572654

Please sign in to comment.