sixarm_ruby_pro_logger 2.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34a5a270bef744bb89bc22bec7c69356dc0f5774
4
+ data.tar.gz: dba64dbde5d2c794a1b437640f9e9531df33b05b
5
+ SHA512:
6
+ metadata.gz: 6d78fa563f69873550d86c308633363c284dfdcf5155ed11fdca21a3f4dad88fd03d2699ccb2335a88b555d6528b5790ea5a9f361e7fbe9993feb40c1afdc8a9
7
+ data.tar.gz: 43c65006a33b2c97680ccd66d3717211e49a637dcfa2db5a5257116783e480cbd4ae827626169526a137c52d720099520efcf041ed45619f79f565419369ddcc
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,4 @@
1
+ X}&b�$�{PF�w�o��ٰ�/~=x\���5m�)2�t�=�l���;��fR��ZR�S7u�%����nGH���K+���w;S���)?X�?Y���(5�&LK�9r�+J!W��л��WE�[�`�|4���V�
2
+ k�]���l�>�S �8ܥ>ҷ)�s��xJ��^�߯9>�`s��z�u��� (gs$��(
3
+ ��q��,æS�/�q�)��q��(-������V
4
+ @��%�)�0��B
data/.gemtest ADDED
File without changes
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # Contributing
2
+
3
+ Thank you for contributing!
4
+
5
+ If you would like to contribute a donation, an easy way is to use PayPal to sixarm@sixarm.com.
6
+
7
+ If you would like to contribute help, the next section is for you.
8
+
9
+
10
+ ## Contributing to the source
11
+
12
+ We love pull requests for improvments to the source code and documentation.
13
+
14
+ There are three easy steps:
15
+
16
+ 1. Fork the repo.
17
+
18
+ * Before you do any work please run our existing tests to make sure the code runs cleanly.
19
+
20
+ 2. Work as you like.
21
+
22
+ * Please create tests. This helps us know that all your code runs cleanly.
23
+
24
+ 3. Push to your fork and submit a pull request.
25
+
26
+ * We'll take a look as soon as we can; this is typically within a business day.
27
+
28
+ Thank you again!
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # SixArm.com » Ruby » <br> ProLogger custom logger with better information
2
+
3
+ * Doc: <http://sixarm.com/sixarm_ruby_pro_logger/doc>
4
+ * Gem: <http://rubygems.org/gems/sixarm_ruby_pro_logger>
5
+ * Repo: <http://github.com/sixarm/sixarm_ruby_pro_logger>
6
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
7
+
8
+
9
+ ## Introduction
10
+
11
+ ProLogger is a custom logger formatter for Rails that prints these:
12
+
13
+ * Time stamp
14
+ * Hostname
15
+ * Process Id
16
+ * Severity: Rails defines these as debug, info, warn, error, and fatal.
17
+ * Message: a string, exception, array, or any object that has a .inspect method)
18
+
19
+ Example setup:
20
+
21
+ Rails.logger.formatter = ProLogger.new
22
+
23
+ Example use:
24
+
25
+ logger.info("Hello")
26
+ => "2011-12-31T12:59:59Z my_program my.example.com 1000 Hello"
27
+
28
+ For docs go to <http://sixarm.com/sixarm_ruby_pro_logger/doc>
29
+
30
+ Want to help? We're happy to get pull requests.
31
+
32
+
33
+ ## Install quickstart
34
+
35
+ Install:
36
+
37
+ gem install sixarm_ruby_pro_logger
38
+
39
+ Bundler:
40
+
41
+ gem "sixarm_ruby_pro_logger", "~>2.0.0"
42
+
43
+ Require:
44
+
45
+ require "sixarm_ruby_pro_logger"
46
+
47
+
48
+ ## Install with security (optional)
49
+
50
+ To enable high security for all our gems:
51
+
52
+ wget http://sixarm.com/sixarm.pem
53
+ gem cert --add sixarm.pem
54
+ gem sources --add http://sixarm.com
55
+
56
+ To install with high security:
57
+
58
+ gem install sixarm_ruby_pro_logger --test --trust-policy HighSecurity
59
+
60
+
61
+ ## Options
62
+
63
+ Intialize options:
64
+
65
+ * time_format: A format string for the `time.strftime` method.
66
+ Defaults to `"%Y-%m-%dT%H:%M:%SZ"` which is ISO 8601 format.
67
+
68
+ * progname: The running program name.
69
+ Default is `$PROGRAM_NAME`.
70
+
71
+ * hostname: The server host name.
72
+ Default is `Socket.gethostname`.
73
+
74
+ * pid: The process id number.
75
+ Default is `Process.pid`.
76
+
77
+ * message_separator: Text to use to join mutiple messages.
78
+ Default is " ... ".
79
+
80
+ * backtrace_separator: Print this between exception backtrace lines.
81
+ Default is " ... ".
82
+
83
+ * line_separator: Change any message newlines to this text.
84
+ Default is " ... ".
85
+
86
+ Example:
87
+
88
+ Rails.logger.formatter = ProLogger.new(
89
+ strftime: "%Y-%m-%dT%H:%M:%SZ",
90
+ progname: "my_program"
91
+ hostname: "my.example.com",
92
+ pid: 1000,
93
+ line_separator: " / "
94
+ backtrace_separator " \"
95
+ message_separator: " | "
96
+ )
97
+
98
+ The message can be:
99
+
100
+ * a string: print the string, with leading whitespace stripped, and newlines replaced by line_separator.
101
+
102
+ * an exception: print the class, message, and backtrace items separated by backtrace_separator.
103
+
104
+ * an array of messages: print the items in the array, separated by message_separator.
105
+
106
+ * any object: first convert it to a string using object.inspect, then print it as a string as above.
107
+
108
+
109
+ ## Thanks
110
+
111
+ Thanks to topfunky for the open source custom logger at:
112
+ https://github.com/topfunky/hodel_3000_compliant_logger/
113
+
114
+
115
+ ## Changes
116
+
117
+ * 2014-03-15 2.0.0 Upgrades to be a formatter plus new options
118
+ * 2012-03-14 1.1.0 Update docs, tests
119
+ * 2011-11-27 1.0.0 Publish
120
+
121
+
122
+ ## License
123
+
124
+ You may choose any of these open source licenses:
125
+
126
+ * Apache License
127
+ * BSD License
128
+ * CreativeCommons License, Non-commercial Share Alike
129
+ * GNU General Public License Version 2 (GPL 2)
130
+ * GNU Lesser General Public License (LGPL)
131
+ * MIT License
132
+ * Perl Artistic License
133
+ * Ruby License
134
+
135
+ The software is provided "as is", without warranty of any kind,
136
+ express or implied, including but not limited to the warranties of
137
+ merchantability, fitness for a particular purpose and noninfringement.
138
+
139
+ In no event shall the authors or copyright holders be liable for any
140
+ claim, damages or other liability, whether in an action of contract,
141
+ tort or otherwise, arising from, out of or in connection with the
142
+ software or the use or other dealings in the software.
143
+
144
+ This license is for the included software that is created by SixArm;
145
+ some of the included software may have its own licenses, copyrights,
146
+ authors, etc. and these do take precedence over the SixArm license.
147
+
148
+ Copyright (c) 2005-2014 Joel Parker Henderson
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,116 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+ require 'logger'
7
+
8
+ class ProLogger < Logger
9
+
10
+ attr_accessor :time_format
11
+ attr_accessor :progname
12
+ attr_accessor :hostname
13
+ attr_accessor :pid
14
+ attr_accessor :message_separator
15
+ attr_accessor :backtrace_separator
16
+ attr_accessor :line_separator
17
+
18
+ # Initialize the Rails logger formatter.
19
+ #
20
+ # Options:
21
+ #
22
+ # * time_format: A format string for the `time.strftime` method.
23
+ # Default is `"%Y-%m-%dT%H:%M:%SZ"` which is ISO 8601 format.
24
+ #
25
+ # * progname: The running program name.
26
+ # Default is `$PROGRAM_NAME`.
27
+ #
28
+ # * hostname: The server host name.
29
+ # Default is `Socket.gethostname`.
30
+ #
31
+ # * pid: The process id number.
32
+ # Default is `Process.pid`.
33
+ #
34
+ # * message_separator: Text to use to join mutiple messages.
35
+ # Default is " ... ".
36
+ #
37
+ # * backtrace_separator: Print this between exception backtrace lines.
38
+ # Default is " ... ".
39
+ #
40
+ # * line_separator: Change any message newlines to this text.
41
+ # Default is " ... ".
42
+ #
43
+ # @param [Hash] options
44
+ #
45
+ def initialize(options={})
46
+ @time_format = (options[:time_format] || "%Y-%m-%dT%H:%M:%SZ").to_s
47
+ @progname = (options[:progname] || $PROGRAM_NAME).to_s
48
+ @hostname = (options[:hostname] || (require('socket') && Socket.gethostname)).to_s
49
+ @pid = (options[:pid] || Process.pid).to_s
50
+ @message_separator = (options[:message_separator] || " ... ").to_s
51
+ @backtrace_separator = (options[:backtrace_separator] || " ... ").to_s
52
+ @line_separator = (options[:line_separator] || " ... ").to_s
53
+ end
54
+
55
+ # Call the formatter.
56
+ #
57
+ # All of the params will be converted to strings;
58
+ # it's fine to send objects instead of strings.
59
+ #
60
+ # We strip the message of extraneous whitespace.
61
+ #
62
+ # See #initialize for the defaults.
63
+ #
64
+ # @param severity [String] the severity object, such as `"INFO"`.
65
+ # @param time [Time] the time, typically `Time.now.utc`.
66
+ # @param progname [String] the program name, which is anything you like.
67
+ # @param msg [String] the message.
68
+ #
69
+ def call(severity, time, progname, msg)
70
+ "#{time_string(time)} #{progname_string(progname)} #{hostname} #{pid} #{severity_string(severity)} #{message_string(msg)}\n"
71
+ end
72
+
73
+ def time_string(time)
74
+ time.utc.strftime(time_format)
75
+ end
76
+
77
+ def progname_string(progname)
78
+ (progname || self.progname).to_s
79
+ end
80
+
81
+ def severity_string(severity)
82
+ (severity || self.severity).to_s
83
+ end
84
+
85
+ def message_string(msg)
86
+ s = \
87
+ case msg
88
+ when ::String
89
+ message_string_when_string(msg)
90
+ when ::Exception
91
+ message_string_when_exception(msg)
92
+ when ::Array
93
+ message_string_when_array(msg)
94
+ else
95
+ message_string_when_object(msg)
96
+ end
97
+ return s.gsub(/\n/, line_separator).lstrip
98
+ end
99
+
100
+ def message_string_when_string(msg)
101
+ msg
102
+ end
103
+
104
+ def message_string_when_array(msg)
105
+ msg.map{|item| message_string(item)}.join(message_separator)
106
+ end
107
+
108
+ def message_string_when_exception(msg)
109
+ "#{msg.class} #{msg.message}: " + (msg.backtrace || []).join(backtrace_separator)
110
+ end
111
+
112
+ def message_string_when_object(msg)
113
+ msg.inspect
114
+ end
115
+
116
+ end
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_pro_logger'
6
+
7
+ class ProLoggerTest < Minitest::Test
8
+
9
+ def test_initialize
10
+ x = ProLogger.new(
11
+ :time_format => "my_time_format",
12
+ :progname => "my_progname",
13
+ :hostname => "my_hostname",
14
+ :pid => "my_pid",
15
+ :message_separator => "my_message_separator",
16
+ :backtrace_separator => "my_backtrace_separator",
17
+ :line_separator => "my_line_separator",
18
+ )
19
+ assert_equal("my_time_format", x.time_format)
20
+ assert_equal("my_progname", x.progname)
21
+ assert_equal("my_hostname", x.hostname)
22
+ assert_equal("my_pid", x.pid)
23
+ assert_equal("my_message_separator", x.message_separator)
24
+ assert_equal("my_backtrace_separator", x.backtrace_separator)
25
+ assert_equal("my_line_separator", x.line_separator)
26
+ end
27
+
28
+ LOGGER = ProLogger.new
29
+
30
+ def test_format_message
31
+ LOGGER.hostname = "my_hostname"
32
+ LOGGER.pid = "my_pid"
33
+ severity = "my_severity"
34
+ time = Time.now
35
+ progname = "my_progname"
36
+ msg = "my_msg"
37
+ s = LOGGER.call(severity, time, progname, msg)
38
+ assert(s=~/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ my_progname my_hostname my_pid my_severity my_msg\n$/, s)
39
+ end
40
+
41
+ def test_time_string
42
+ assert_match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/, LOGGER.time_string(Time.now))
43
+ end
44
+
45
+ def test_message_string_when_string
46
+ msg = "foo"
47
+ assert_equal("foo", LOGGER.message_string(msg))
48
+ end
49
+
50
+ def test_message_string_when_string_with_leading_whitespace
51
+ msg = " foo"
52
+ assert_equal("foo", LOGGER.message_string(msg))
53
+ end
54
+
55
+ def test_message_string_when_string_with_multiple_lines
56
+ sep = LOGGER.line_separator
57
+ msg = "abc\ndef\nghi"
58
+ assert_equal("abc#{sep}def#{sep}ghi", LOGGER.message_string(msg))
59
+ end
60
+
61
+ def test_message_string_when_array
62
+ sep = LOGGER.message_separator
63
+ msg = ['abc','def','ghi']
64
+ assert_equal("abc#{sep}def#{sep}ghi", LOGGER.message_string(msg))
65
+ end
66
+
67
+ def test_message_string_when_exception
68
+ msg = RuntimeError.new("hello")
69
+ msg.set_backtrace(['abc:1','def:2','ghi:3'])
70
+ sep = LOGGER.backtrace_separator
71
+ assert_equal("RuntimeError hello: abc:1#{sep}def:2#{sep}ghi:3", LOGGER.message_string_when_exception(msg))
72
+ end
73
+
74
+ def test_message_string_when_object_using_inspect_on_a_number
75
+ msg = 123
76
+ assert_equal("123", LOGGER.message_string_when_object(msg))
77
+ end
78
+
79
+ def test_message_string_when_object_using_inspect_on_a_hash
80
+ msg = {:a => :b}
81
+ assert_equal("{:a=>:b}", LOGGER.message_string_when_object(msg))
82
+ end
83
+
84
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_pro_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - SixArm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQ8wDQYDVQQDDAZzaXhh
14
+ cm0xFjAUBgoJkiaJk/IsZAEZFgZzaXhhcm0xEzARBgoJkiaJk/IsZAEZFgNjb20w
15
+ HhcNMTQwMzEzMDQyMjE4WhcNMTUwMzEzMDQyMjE4WjA+MQ8wDQYDVQQDDAZzaXhh
16
+ cm0xFjAUBgoJkiaJk/IsZAEZFgZzaXhhcm0xEzARBgoJkiaJk/IsZAEZFgNjb20w
17
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC5MZYB72Amo9DyeqBdJeEx
18
+ r4togM0+diNuL1nCH2FSO/+LX5L9mTPEEW5gexYCasmlOfmk5255EToJNtu1JUM/
19
+ dMqUbNS5LZ1srFVcyDzIe/wQ9f2OSmb+lAGmlnFLfYSpduMv9fPNISlcs5nFYSR9
20
+ mpS0kTWcXQPLNDl2cfnkYYjDsuyJ8FmDyG7TTF0c4OWJNLxNDE8To2n8GmmDSwr3
21
+ 0K71F278CJlFoIaSSjnhKxkH8/l+z/Vs58KkjX/7M6nwNgNZMQaFBIO02UDtCi2F
22
+ ICVtDuWdK0YLv3JnIzvSQPQsfArrw2s8RVKjXlelPMeHJIcCEZcS4K6HIg7vQCkP
23
+ AgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQrbLvF
24
+ TNv9r72z+hpCl3BkTPbzwTAcBgNVHREEFTATgRFzaXhhcm1Ac2l4YXJtLmNvbTAc
25
+ BgNVHRIEFTATgRFzaXhhcm1Ac2l4YXJtLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEA
26
+ H08J7cTJyfm4mXpdM0FFr/f/syQSl2ymJWtcosuKA79A/vYMZ+n9B1gpuJmegjNt
27
+ lmYByeU50jJJ7JNdkvkTagHCZaxtzclWx6AR5gTd8V/sBKbTWtHe72pOWz/stQs2
28
+ xD8tQZvdAuBtRXx4ys6e3vigvYjdmTHUR9tT/NGCwmWj7KTk3mwNKBmuQGWTVWrV
29
+ h6r4cFMt3X5Zu+euYxHqDuwWyub9hp4s30/ea38CoYNdIZcSFtpGuvhwVDU0x5dg
30
+ sWRVEyjnjnNuAeLP9zv43IDXjS22L2efhap7IOinYjcecpfXJgQaU+6BFAY4sdkQ
31
+ S1STYSfs3qySBxxAeEyZTw==
32
+ -----END CERTIFICATE-----
33
+ date: 2014-03-15 00:00:00.000000000 Z
34
+ dependencies: []
35
+ description: Logs more information than the typical Ruby logger.
36
+ email: sixarm@sixarm.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - ".gemtest"
42
+ - CONTRIBUTING.md
43
+ - README.md
44
+ - Rakefile
45
+ - VERSION
46
+ - lib/sixarm_ruby_pro_logger.rb
47
+ - test/sixarm_ruby_pro_logger_test.rb
48
+ homepage: http://sixarm.com/
49
+ licenses:
50
+ - BSD
51
+ - GPL
52
+ - MIT
53
+ - PAL
54
+ - Various
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.2.0
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: SixArm.com » Ruby » ProLogger custom logger for Rails
76
+ test_files:
77
+ - test/sixarm_ruby_pro_logger_test.rb
78
+ has_rdoc: true
metadata.gz.sig ADDED
Binary file