semantic_logger 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.
data/FUTURE.rb ADDED
@@ -0,0 +1,211 @@
1
+
2
+ # Return the logger for a specific class, supports class specific log levels
3
+ # Clarity::Logger.logger(MyClass)
4
+ # # OR
5
+ # Clarity::Logger.logger('MyClass')
6
+ #
7
+ # # Switch to slf4j as the underlying implementation
8
+ # Clarity::Logger.impl = slf4j
9
+ #
10
+ # logging.yml
11
+ #
12
+ # # Replace the Rails Logger
13
+ # Rails.logger = Clarity::Logger.logger(Rails)
14
+ #
15
+ #
16
+ #
17
+ # # Thread specific context information to be logged with every log entry
18
+ # #
19
+ # # Add metadata information within a block to all log calls on This Thread
20
+ # logger.with_metadata(:tracking_number=>12345) do
21
+ # # Any log entries within this block will have this metadata added to it
22
+ # logger.debug('Hello World', :result => 'blah')
23
+ # end
24
+ #
25
+ # # If a block cannot be used to set the scope of context
26
+ # # Set global metadata for every log entry on this machine
27
+ # logger['host_name'] = 'blah'
28
+ # logger.metadata = { 'host_name' => 'blah' }
29
+ #
30
+ # # Add metadata information to all log entries with this logger name
31
+ # logger = SymanticLogger.logger('com.app.myclass')
32
+ # logger.metadata = { 'target_host' => 'vendorX' }
33
+ #
34
+ # # Clear out the current thread logging context
35
+ # logger.clear_metadata
36
+ # # OR
37
+ # logger.metadata = nil
38
+ #
39
+ # # Note: It is important to remove context information when no longer applicable:
40
+ # begin
41
+ # logger['tracking_number'] = 12345
42
+ # ensure
43
+ # logger.clear_context
44
+ # end
45
+ #
46
+ # # Benchmark and log in ms the time taken to process supplied.
47
+ # # Additional context can be added
48
+ # # On completion of the block, a log entry will be written adding
49
+ # # 'duration' as a context variable set to the ms taken to process the block
50
+ # # Parameters
51
+ # # Takes either a text message, or a context hash for that block
52
+ # # Benchmarking is only performed and logged if the supplied log level is active
53
+ # # - The code block is always executed
54
+ # logger.benchmark(:info, message, 'tracking_number'=>12345) do
55
+ # # Any log entries within this block will have this context added to it
56
+ # logger.debug('Hello World', :result => 'blah')
57
+ # end
58
+ #
59
+ # Example:
60
+ #
61
+ # logger.debug('hello world', exc) { }
62
+ #
63
+ # # Add to initializer:
64
+ # new_logger = Logger.new(File.join(RAILS_ROOT, "log", "new_logger_#{RAILS_ENV}.log"), 'daily')
65
+ # new_logger.formatter = Logger::Formatter.new
66
+ #
67
+ # # In environment.rb:
68
+ # Rails::Initializer.run do |config|
69
+ #
70
+ # config.active_record.logger = new_logger
71
+ # config.action_controller.logger = new_logger
72
+ #
73
+ # ....
74
+ # end
75
+ #
76
+ # Log and benchmark the workings of a single block and silence whatever logging that may have happened inside it
77
+ # (unless <tt>use_silence</tt> is set to false).
78
+ #
79
+ # The benchmark is only recorded if the current level of the logger matches the <tt>log_level</tt>, which makes it
80
+ # easy to include benchmarking statements in production software that will remain inexpensive because the benchmark
81
+ # will only be conducted if the log level is low enough.
82
+ #
83
+ # def benchmark(title, log_level = Logger::DEBUG, use_silence = true)
84
+ # if logger && logger.level == log_level
85
+ # result = nil
86
+ # ms = Benchmark.ms { result = use_silence ? silence { yield } : yield }
87
+ # logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)")
88
+ # result
89
+ # else
90
+ # yield
91
+ # end
92
+ # end
93
+ #
94
+
95
+
96
+
97
+
98
+
99
+ # Research results of looking into other loggers:
100
+ #
101
+ # Central Logger: - Request level logging only, not per log call - Not Threadsafe!
102
+ # {
103
+ # 'action' : action_name,
104
+ # 'application_name' : application_name (rails root),
105
+ # 'controller' : controller_name,
106
+ # 'ip' : ip_address,
107
+ # 'messages' : {
108
+ # 'info' : [ ],
109
+ # 'debug' : [ ],
110
+ # 'error' : [ ],
111
+ # 'warn' : [ ],
112
+ # 'fatal' : [ ]
113
+ # },
114
+ # 'params' : { },
115
+ # 'path' : path,
116
+ # 'request_time' : date_of_request,
117
+ # 'runtime' : elapsed_execution_time_in_milliseconds,
118
+ # 'url' : full_url
119
+ # }
120
+ # Rails.logger.add_metadata
121
+ #
122
+ # log4mongo:
123
+ #{{
124
+ # "_id" : ObjectId("4c60e21be54744706960af09"),
125
+ # "timestamp" : "Mon Aug 09 2010 22:22:35 GMT-0700 (PDT)",
126
+ # "level" : "ERROR",
127
+ # "thread" : "main",
128
+ # "message" : "Don't panic",
129
+ # "fileName" : "LogTest.java",
130
+ # "method" : "main",
131
+ # "lineNumber" : "8",
132
+ # "class" : {
133
+ # "fullyQualifiedClassName" : "LogTest",
134
+ # "package" : [
135
+ # ""
136
+ # ],
137
+ # "className" : "LogTest"
138
+ # }
139
+ # "loggerName" : {
140
+ # "fullyQualifiedClassName" : "LogTest",
141
+ # "package" : [
142
+ # ""
143
+ # ],
144
+ # "className" : "LogTest"
145
+ # }
146
+ #}
147
+ #
148
+ # slf4j:
149
+ #{
150
+ # "_id" : ObjectId("4d9cbcbf7abb3abdaf9679cd"),
151
+ # "timeStamp" : ISODate("2011-04-06T19:19:27.006Z"),
152
+ # "level" : "ERROR",
153
+ # "thread" : "main",
154
+ # "logger" : "ch.qos.logback.classic.db.mongo.MongoDBAppenderTest",
155
+ # "message" : "D"
156
+ #}
157
+ #
158
+ #
159
+ # slf4j Access Logs:
160
+ #{
161
+ # "_id" : ObjectId("4d98cc4f7abb95e59279e183"),
162
+ # "timeStamp" : ISODate("2011-04-03T19:36:47.339Z"),
163
+ # "server" : "localhost",
164
+ # "remote" : {
165
+ # "host" : "0:0:0:0:0:0:0:1",
166
+ # "user" : "tomcat",
167
+ # "addr" : "0:0:0:0:0:0:0:1"
168
+ # },
169
+ # "request" : {
170
+ # "uri" : "/manager/images/tomcat.gif",
171
+ # "protocol" : "HTTP/1.1",
172
+ # "method" : "GET",
173
+ # "sessionId" : "1C6357816D9EEFD31F6D9D154D87308A",
174
+ # "userAgent" : "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16",
175
+ # "referer" : "http://localhost:8080/manager/html"
176
+ # },
177
+ # "response" : {
178
+ # "contentLength" : NumberLong(1934),
179
+ # "statusCode" : 200
180
+ # }
181
+ #}
182
+ #
183
+ # Logging:
184
+ #
185
+ # 'logger' Used to output the name of the logger that generated the
186
+ # log event.
187
+ # 'timestamp' Used to output the timestamp of the log event.
188
+ # 'level' Used to output the level of the log event.
189
+ # 'message' Used to output the application supplied message
190
+ # associated with the log event.
191
+ # 'file' Used to output the file name where the logging request
192
+ # was issued.
193
+ # 'line' Used to output the line number where the logging request
194
+ # was issued.
195
+ # 'method' Used to output the method name where the logging request
196
+ # was issued.
197
+ # 'pid' Used to output the process ID of the currently running
198
+ # program.
199
+ # 'millis' Used to output the number of milliseconds elapsed from
200
+ # the construction of the Layout until creation of the log
201
+ # event.
202
+ # 'thread_id' Used to output the object ID of the thread that generated
203
+ # the log event.
204
+ # 'thread' Used to output the name of the thread that generated the
205
+ # log event. Name can be specified using Thread.current[:name]
206
+ # notation. Output empty string if name not specified. This
207
+ # option helps to create more human readable output for
208
+ # multithread application logs.
209
+
210
+
211
+
data/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2012 Clarity Services, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ semantic-logger-ruby
2
+ ====================
3
+
4
+ * http://github.com/ClarityServices/semantic-logger-ruby
5
+
6
+ Feedback is welcome and appreciated :)
7
+
8
+ ### Introduction
9
+
10
+ SemanticLogger is a Logger that supports logging of meta-data, not only text messages
11
+
12
+ Machines can understand the logged data without having to use
13
+ complex Regular Expressions or other text parsing techniques
14
+
15
+ SemanticLogger, sits on top of existing logger implementations and can also
16
+ be used as a drop in replacement for existing Ruby loggers.
17
+ This allows the existing logging to be replaced immediately with the
18
+ SemanticLogger Appenders, and over time the calls can be replaced with ones
19
+ that contain the necessary meta-data.
20
+
21
+ Example of current calls:
22
+
23
+ logger.info("Queried users table in #{duration} ms, with a result code of #{result}")
24
+
25
+ For a machine to find all queries for table 'users' that took longer than
26
+ 100 ms, would require using a regular expression just to extract the table name
27
+ and duration, then apply the necessary logic. It also assumes that the text
28
+ is not changed and that matches will not be found when another log entry has
29
+ similar text output.
30
+
31
+ This can be changed over time to:
32
+
33
+ Rails.logger.info("Queried table",
34
+ :duration => duration,
35
+ :result => result,
36
+ :table => "users",
37
+ :action => "query")
38
+
39
+ Using this semantic example, a machine can easily find all queries for table
40
+ 'users' that took longer than 100 ms.
41
+
42
+ db.logs.find({"data.table":"users", "data.action":"query"})
43
+
44
+ Since SemanticLogger can call existing Loggers, it does not force end-users
45
+ to have to adopt a Semantic aware adapter. Although, such adapters create
46
+ tremendous value in the problem monitoring and determination processes.
47
+
48
+ For ease of use each Appender can be used directly if required. It is preferred
49
+ however to use the SemanticLogger interface and supply the configuration to it.
50
+ In this way the adapter can be changed without modifying the application
51
+ source code.
52
+
53
+ # Future
54
+ - Web Interface to view and search log information
55
+ - Override the log level at the appender level
56
+
57
+ # Configuration
58
+
59
+ The Semantic Logger follows the principle where multiple appenders can be active
60
+ at the same time. This allows one to log to MongoDB and the Rails
61
+ ActiveResource::BufferedLogger at the same time.
62
+
63
+ ### Dependencies
64
+
65
+ - Ruby MRI 1.8.7 (or above) Or, JRuby 1.6.3 (or above)
66
+ - Optional: Rails 3.0.10 (or above)
67
+ - Optional: To log to MongoDB, Mongo Ruby Driver 1.5.2 or above
68
+
69
+ ### Install
70
+
71
+ gem install semantic-logger
72
+
73
+ Development
74
+ -----------
75
+
76
+ Want to contribute to Semantic Logger?
77
+
78
+ First clone the repo and run the tests:
79
+
80
+ git clone git://github.com/ClarityServices/semantic-logger.git
81
+ cd semantic-logger
82
+ jruby -S rake test
83
+
84
+ Feel free to ping the mailing list with any issues and we'll try to resolve it.
85
+
86
+ Contributing
87
+ ------------
88
+
89
+ Once you've made your great commits:
90
+
91
+ 1. [Fork](http://help.github.com/forking/) semantic-logger
92
+ 2. Create a topic branch - `git checkout -b my_branch`
93
+ 3. Push to your branch - `git push origin my_branch`
94
+ 4. Create an [Issue](http://github.com/ClarityServices/semantic-logger/issues) with a link to your branch
95
+ 5. That's it!
96
+
97
+ We are looking for volunteers to create implementations in other languages such as:
98
+ * Java, C# and Go
99
+
100
+ Meta
101
+ ----
102
+
103
+ * Code: `git clone git://github.com/ClarityServices/semantic-logger.git`
104
+ * Home: <https://github.com/ClarityServices/semantic-logger>
105
+ * Docs: TODO <http://ClarityServices.github.com/semantic-logger/>
106
+ * Bugs: <http://github.com/reidmorrison/semantic-logger/issues>
107
+ * Gems: <http://rubygems.org/gems/semantic-logger>
108
+
109
+ This project uses [Semantic Versioning](http://semver.org/).
110
+
111
+ Authors
112
+ -------
113
+
114
+ Reid Morrison :: reidmo@gmail.com :: @reidmorrison
115
+
116
+ License
117
+ -------
118
+
119
+ Copyright 2011 Clarity Services, Inc.
120
+
121
+ Licensed under the Apache License, Version 2.0 (the "License");
122
+ you may not use this file except in compliance with the License.
123
+ You may obtain a copy of the License at
124
+
125
+ http://www.apache.org/licenses/LICENSE-2.0
126
+
127
+ Unless required by applicable law or agreed to in writing, software
128
+ distributed under the License is distributed on an "AS IS" BASIS,
129
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130
+ See the License for the specific language governing permissions and
131
+ limitations under the License.