my_stuff-logger 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +64 -0
  2. data/example.rb +70 -0
  3. data/lib/my_stuff/logger.rb +2 -1
  4. metadata +4 -2
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = What is this?
2
+
3
+ A drop-in replacement for Ruby's standard Logger class, if you're just
4
+ using the basic features.
5
+
6
+ = How do I get it?
7
+
8
+ gem install my_stuff-logger
9
+
10
+ = How do I use it?
11
+
12
+ Create an instance, then just like the standard Logger class; take a look
13
+ at example.rb.
14
+
15
+ = Why would I use it instead?
16
+
17
+ http://f.cl.ly/items/1M0f083q0Q3p3u103a3o/Image%202011.08.30%2008:06:08.png
18
+
19
+ == It's got more information.
20
+
21
+ * The filename, line number, and method are *always* included
22
+ * By default, a backtrace is included for errors and fatals. This can be
23
+ tuned to any level, including even for debug, or for none at all.
24
+
25
+ File names are shown relative to a choosable root (which defaults to
26
+ File.dirname(File.expand_path($0))) — if a file isn't in that root, you
27
+ get the full path, not '../../../../../../foo/bar/baz' :p
28
+
29
+ == It's easier to see what's important.
30
+
31
+ http://f.cl.ly/items/1I0p3c3J2i1u0D1E3Q3s/Image%202011.08.30%2020:05:20.png
32
+
33
+ == You can choose what's relevant.
34
+
35
+ There's per-app settings for where output goes, what levels are logged,
36
+ and what levels get backtraces — but you can also change this per-instance,
37
+ and it'll stick that way even if the global is changed later.
38
+
39
+ == You can plug in your own filters to make the log messages more readable.
40
+
41
+ A couple of examples:
42
+
43
+ * The priority colorization is a filter
44
+ * There's also a filter shipped (but not enabled by default) for use with
45
+ {MyStuff::MultiDB}[https://github.com/fredemmott/my_stuff-multidb], which
46
+ turns 'Foo::MYSTUFF_MULTIDB_DB_aloadofhex::Bar' into
47
+ 'Foo::<localhost:3307/test>::Bar'
48
+
49
+ These filters are only enabled for log viewing; they don't affect what's
50
+ written to disk.
51
+
52
+ By default, colors are enabled if the output device (STDOUT usually) is
53
+ a TTY, but disabled otherwised — of course, this can be overidden.
54
+
55
+ == It's easier/faster to machine-process.
56
+
57
+ * The number in the second field is a unix timestamp
58
+ * The filename is always in the same place, in the same format, making it
59
+ easier to use with grep, or something more in-depth.
60
+
61
+ = What's coming soon?
62
+
63
+ * a 'msl-cat' command, applying the filters
64
+ * a 'msl-tail' command, emulating/wrapping 'tail -F'
data/example.rb ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011-present Fred Emmott. See COPYING file.
3
+
4
+ _DIR = File.dirname(File.expand_path(__FILE__))
5
+ $LOAD_PATH.push(File.join(_DIR, 'lib'))
6
+
7
+ require 'optparse'
8
+
9
+ options = {}
10
+
11
+ optparse = OptionParser.new do |opts|
12
+ opts.on(
13
+ '--level=debug|info|warn|error|fatal|disable',
14
+ 'What level of output to show',
15
+ /^debug|info|warn|error|fatal|disable$/
16
+ ) do |level|
17
+ options[:level] = level.to_sym
18
+ end
19
+
20
+ opts.on(
21
+ '--backtrace-level=debug|info|warn|error|fatal|disable',
22
+ 'What level of output to show backtraces for',
23
+ /^debug|info|warn|error|fatal|disable$/
24
+ ) do |level|
25
+ options[:backtrace_level] = level.to_sym
26
+ end
27
+
28
+ opts.on(
29
+ '--colors=yes|no|auto',
30
+ 'Colorize output',
31
+ /^yes|no|auto$/
32
+ ) do |value|
33
+ case value
34
+ when 'yes'
35
+ options[:colorize] = true
36
+ when 'no'
37
+ options[:colorize] = false
38
+ end
39
+ end
40
+ end
41
+ optparse.parse!
42
+
43
+ require 'my_stuff/logger'
44
+ require 'my_stuff/logger/reader'
45
+
46
+ require 'logger' # Ruby's standard one
47
+
48
+ # We set the output device of the logger to be the reader.
49
+ # This gives us rainbows and unicorns — well, colourized output at least.
50
+ reader = MyStuff::Logger::Reader.new(options)
51
+ options[:device] = reader
52
+ logger = MyStuff::Logger.new(options)
53
+
54
+ def compare logger
55
+ puts '=== Comparison ==='
56
+ Logger.new(STDOUT).error "This is Ruby's standard Logger"
57
+ logger.error "This is MyStuff::Logger"
58
+ end
59
+
60
+ def spam logger
61
+ puts '=== Spamming All Log Levels ==='
62
+ logger.debug 'nyan nyan nyan'
63
+ logger.info ({:what => 'cool story bro'})
64
+ logger.warn "IMA CHARGIN' MAH LAZER"
65
+ logger.error "Somebody set us up the bomb"
66
+ logger.fatal "No more kitten pictures."
67
+ end
68
+
69
+ compare logger
70
+ spam logger
@@ -1,5 +1,6 @@
1
1
  # Copyright 2011-present Fred Emmott. See COPYING file.
2
2
 
3
+ require 'my_stuff/logger/reader'
3
4
  require 'my_stuff/logger/writer'
4
5
 
5
6
  module MyStuff
@@ -12,7 +13,7 @@ module MyStuff
12
13
  attr_writer :device, :level, :backtrace_level, :root_path
13
14
 
14
15
  def device
15
- @device ||= STDOUT
16
+ @device ||= STDOUT.tty? ? MyStuff::Logger::Reader.new : STDOUT
16
17
  end
17
18
 
18
19
  def level
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_stuff-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-30 00:00:00.000000000Z
12
+ date: 2011-08-31 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: ''
15
15
  email:
@@ -19,6 +19,8 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - COPYING
22
+ - README.rdoc
23
+ - example.rb
22
24
  - lib/my_stuff/logger/levels.rb
23
25
  - lib/my_stuff/logger/reader.rb
24
26
  - lib/my_stuff/logger/reader_filter.rb