log-block 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ log-block :: Automatic indenting of ruby log messages
2
+ Copyright (C) 2009 Jon Moses
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along
15
+ with this program; if not, write to the Free Software Foundation, Inc.,
16
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+
@@ -0,0 +1,25 @@
1
+ = log-block
2
+
3
+ Simply library to allow logging with indenting for ease of reading.
4
+
5
+ = Example
6
+
7
+ @logger = Logger.new( STDOUT )
8
+ @logger.debug("Trying something new")
9
+ @logger.with "-> " do |log|
10
+ log.debug "First step"
11
+ # Do something
12
+
13
+ log.debug "Second step"
14
+ end
15
+
16
+ Produces the following in your log:
17
+
18
+ D, [2009-03-27T20:50:16.910769 #29567] DEBUG -- : Trying something new
19
+ D, [2009-03-27T20:50:16.911328 #29567] DEBUG -- : -> First step
20
+ D, [2009-03-27T20:50:16.911421 #29567] DEBUG -- : -> Second step
21
+
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2009 Jon Moses. See LICENSE for details.
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,32 @@
1
+ require 'logger'
2
+
3
+ class Logger
4
+ def with( prefix, indent_size = 2 )
5
+ yield get_block_logger( prefix, indent_size )
6
+ end
7
+
8
+ def get_block_logger( prefix, indent_size = 2)
9
+ BlockLogger.new( self, prefix, indent_size )
10
+ end
11
+ end
12
+
13
+ class BlockLogger
14
+ def initialize( logger, prefix, indent_size = 2 )
15
+ @logger = logger
16
+ @indent_size = indent_size
17
+ @prefix = prefix
18
+ end
19
+
20
+ def method_missing( meth, *args )
21
+ if [:debug, :info, :warn, :error, :fatal, :unknown].include?(meth)
22
+ @logger.send(meth, message(args.first))
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ def message( msg )
29
+ "#{' ' * @indent_size}#{@prefix}#{msg}"
30
+ end
31
+
32
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class LogBlockTest < Test::Unit::TestCase
4
+ context "using a default logger" do
5
+ setup do
6
+ @output = Tempfile.new("logblocktest")
7
+ @logger = Logger.new( @output )
8
+ @logger.datetime_format = "%Y-%m-%d"
9
+ end
10
+
11
+ should "not indent" do
12
+ @logger.debug("Testing")
13
+ assert_last_line @output, "Testing"
14
+ end
15
+
16
+ context "with one level" do
17
+ setup do
18
+ @block_logger = @logger.get_block_logger "Block:"
19
+ end
20
+ should "indent by one level" do
21
+ @block_logger.debug("123Testing")
22
+ assert_last_line @output, " Block:123Testing"
23
+ end
24
+ end
25
+
26
+ should "return a block logger for `with`" do
27
+ @logger.with "Block" do |block_logger|
28
+ block_logger.debug("In Block")
29
+ assert_last_line @output, " Block:In Block"
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'tempfile'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'log_block'
9
+
10
+ class Test::Unit::TestCase
11
+ def last_line( file )
12
+ file.rewind
13
+ file.read.split("\n").last
14
+ end
15
+
16
+ def assert_last_line( file, message, level = 'DEBUG' )
17
+ line = last_line(file)
18
+ assert "#{level[0]}, \[#{Time.now.strftime('%Y-%m-%d')}#\d+\] #{level} -- : #{message}"
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log-block
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jon Moses
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-27 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jon@burningbush.us
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - VERSION.yml
27
+ - README.rdoc
28
+ - lib/log_block.rb
29
+ - test/test_helper.rb
30
+ - test/log_block_test.rb
31
+ - LICENSE
32
+ has_rdoc: true
33
+ homepage: http://github.com/jmoses/log-block
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --inline-source
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: Automatic indenting of ruby log messages
61
+ test_files: []
62
+