log_jam 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/log_jam.rb +8 -1
  2. data/log_jam_test.rb +8 -0
  3. data/readme.md +33 -2
  4. metadata +1 -1
data/log_jam.rb CHANGED
@@ -3,13 +3,20 @@ module LogJam
3
3
 
4
4
  @@logs = []
5
5
 
6
+ def setup_logger(logger, level)
7
+ @@default_logger = logger
8
+ @@default_level = level
9
+ end
10
+
6
11
  def priorities(*list)
7
12
  @@priorities = list
8
13
  end
9
14
 
10
15
  def puts(msg)
11
16
  @@logs << msg
12
- Rails.logger.info(msg)
17
+ if defined? @@default_logger
18
+ @@default_logger.send(@@default_level, msg)
19
+ end
13
20
  end
14
21
 
15
22
  def write_to_disk
@@ -21,6 +21,14 @@ class InvoiceLog < Log; end
21
21
 
22
22
  class LogJamTest < MiniTest::Unit::TestCase
23
23
 
24
+ def test_setup_default_logger
25
+ log_msg = "invoice=123 account=123"
26
+ LogJam.setup_logger(Rails.logger, :info)
27
+ LogJam.priorities(:invoice, :account)
28
+ LogJam.puts(log_msg)
29
+ LogJam.drain
30
+ end
31
+
24
32
  def test_write_to_disk
25
33
  log_msg = "invoice=123 account=123"
26
34
  LogJam.priorities(:invoice, :account)
data/readme.md CHANGED
@@ -1,10 +1,41 @@
1
- # LogJam
1
+ # log_jam
2
2
 
3
3
  A proxy that persists log messages to a database.
4
4
 
5
+ ## Requirements
6
+
7
+ log_jam also will call ActiveRecord like classes. `AccountLog.create({})`
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ $ gem install log_jam
13
+ ```
14
+
5
15
  ## Usage
6
16
 
7
17
  ```ruby
18
+ # log_jam will pass along log messages in real time. log_jam will not wait for
19
+ # you to call drain before it sends messages to the default logger.
20
+ LogJam.setup_logger(Rails.logger, :info)
21
+
22
+ # the order of our priorities determines which table the log will be stored in.
23
+ LogJam.priorities(:invoice, :account)
24
+
25
+ # log_jam will also pass this message to Rails.logger.info
8
26
  LogJam.puts("account=123 invoice=456 invoice created")
9
- LogJam.puts("account=123 page=true core services off-line")
27
+
28
+ # This message drains the logs and figures out how to write to the database.
29
+ # Since we defined our first priority as :invoice, LogJam will ask the kernel
30
+ # for the InvoiceLog class. It will then send the create message to the class
31
+ # with parameters that look like this: {:invoice_id => 456, :message => "account=123 invoice=456 invoice created"}
32
+ LogJam.write_to_disk
33
+ ```
34
+
35
+ ## Hacking on log_jam
36
+
37
+ I think this lib is feature complete; however, if you find a bug please add a test. To run the tests:
38
+
39
+ ```bash
40
+ $ ruby log_jam_test.rb
10
41
  ```
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: log_jam
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Smith