jellog 1.0.11

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.
@@ -0,0 +1,5 @@
1
+ == Bugs and Change Requests for Jellog
2
+
3
+ [jellog-1.0.10 21-Sep-2012]
4
+
5
+ No outstanding bugs
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # @markup ruby
2
+ # enable color output to terminals
3
+ gem 'term-ansicolor'
4
+
5
+ # a little thor for a simple command
6
+ gem 'thor'
7
+
8
+ # config file control
9
+ gem 'jeckyl'
@@ -0,0 +1,59 @@
1
+ == History
2
+
3
+ [jellog-1.0.11 21-Sep-2012]
4
+
5
+ Renamed because jelly was already in use in Gem-space.
6
+
7
+ [jelly-1.0.10 21-Sep-2012]
8
+
9
+ Tidy up documentation and tests ready for pushing to RubyGems.
10
+
11
+ [jelly-1.0.9 25-Jul-2012]
12
+
13
+ Set a default format string when none is provided
14
+
15
+ [jelly-1.0.8 25-Jul-2012]
16
+
17
+ Fix a couple of small errors in config
18
+
19
+ [jelly-1.0.7 23-Jul-2012]
20
+
21
+ Include config class for services etc that use Jelly
22
+
23
+ [jelly-1.0.6 12-Jun-2012]
24
+
25
+ Added mark method to highlight a new section in the log
26
+
27
+ [jelly-1.0.5 21-Jan-2012]
28
+
29
+ Tidy up README and correct rspec tests
30
+
31
+ jelly-1.0.4 10-Jan-2012
32
+
33
+ Change get_options to make deletion an option and not delete keys by default
34
+
35
+ jelly-1.0.3 09-Sep-2011
36
+
37
+ Change option names to comply with existing configure files.
38
+
39
+ jelly-1.0.2 09-Sep-2011
40
+
41
+ Fix close, which had not been updated to the new structure.
42
+
43
+ jelly-1.0.1 07-Sep-2011
44
+
45
+ Add get_opts class method to help pick out log-related options
46
+
47
+ jelly-1.0.0 06-Sep-2011
48
+
49
+ Introduce independent formatting and colour by option.
50
+ Tidy up logging options (making this incompatible with previous versions).
51
+ Make jelly into a local gem.
52
+
53
+ jelly-0.0.10 28-Aug-2011
54
+
55
+ Return message from error level calls to assist in keeping callers DRY
56
+
57
+ jelly-0.0.0 29-May-2011
58
+
59
+ Application generated.
@@ -0,0 +1,4 @@
1
+ A wrapper class around the standard Ruby logger that adds a simply logging level control
2
+ and the ability to log certain messages to syslog. It also adds a puts method so that the
3
+ logger can be used instead of stdout etc. Output can be coloured depending on the logging
4
+ level.
@@ -0,0 +1,159 @@
1
+ Copyright (c) 2011 Robert Sharp
2
+
3
+ This software is licensed for use under the Open Software Licence v. 3.0
4
+ The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
5
+ and below. Under the terms of this licence, all derivative works
6
+ must themselves be licensed under the Open Software Licence v. 3.0
7
+
8
+ Open Source Initiative OSI - The Open Software Licence 3.0:Licensing
9
+ [OSI Approved Licence]
10
+ Open Software Licence ("OSL") v. 3.0
11
+
12
+ This Open Software Licence (the "Licence") applies to any original work of authorship
13
+ (the "Original Work") whose owner (the "Licensor") has placed the following licensing
14
+ notice adjacent to the copyright notice for the Original Work:
15
+
16
+ Licensed under the Open Software Licence version 3.0
17
+
18
+ 1) Grant of Copyright Licence. Licensor grants You a worldwide, royalty-free, non-exclusive,
19
+ sublicensable license, for the duration of the copyright, to do the following:
20
+
21
+ a) to reproduce the Original Work in copies, either alone or as part of a collective work;
22
+
23
+ b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby
24
+ creating derivative works ("Derivative Works") based upon the Original Work;
25
+
26
+ c) to distribute or communicate copies of the Original Work and Derivative Works to
27
+ the public, with the proviso that copies of Original Work or Derivative Works that
28
+ You distribute or communicate shall be licensed under this Open Software Licence;
29
+
30
+ d) to perform the Original Work publicly; and
31
+
32
+ e) to display the Original Work publicly.
33
+
34
+ 2) Grant of Patent Licence. Licensor grants You a worldwide, royalty-free, non-exclusive,
35
+ sublicensable license, under patent claims owned or controlled by the Licensor that are
36
+ embodied in the Original Work as furnished by the Licensor, for the duration of the
37
+ patents, to make, use, sell, offer for sale, have made, and import the Original Work
38
+ and Derivative Works.
39
+
40
+ 3) Grant of Source Code Licence. The term "Source Code" means the preferred form of
41
+ the Original Work for making modifications to it and all available documentation
42
+ describing how to modify the Original Work. Licensor agrees to provide a machine-readable
43
+ copy of the Source Code of the Original Work along with each copy of the Original Work
44
+ that Licensor distributes. Licensor reserves the right to satisfy this obligation by
45
+ placing a machine-readable copy of the Source Code in an information repository reasonably
46
+ calculated to permit inexpensive and convenient access by You for as long as Licensor
47
+ continues to distribute the Original Work.
48
+
49
+ 4) Exclusions From Licence Grant. Neither the names of Licensor, nor the names of
50
+ any contributors to the Original Work, nor any of their trademarks or service marks,
51
+ may be used to endorse or promote products derived from this Original Work without
52
+ express prior permission of the Licensor. Except as expressly stated herein, nothing
53
+ in this Licence grants any license to Licensor's trademarks, copyrights, patents,
54
+ trade secrets or any other intellectual property. No patent license is granted to
55
+ make, use, sell, offer for sale, have made, or import embodiments of any patent claims
56
+ other than the licensed claims defined in Section 2. No license is granted to the
57
+ trademarks of Licensor even if such marks are included in the Original Work. Nothing
58
+ in this Licence shall be interpreted to prohibit Licensor from licensing under terms
59
+ different from this Licence any Original Work that Licensor otherwise would have a
60
+ right to license.
61
+
62
+ 5) External Deployment. The term "External Deployment" means the use, distribution,
63
+ or communication of the Original Work or Derivative Works in any way such that the
64
+ Original Work or Derivative Works may be used by anyone other than You, whether those
65
+ works are distributed or communicated to those persons or made available as an application
66
+ intended for use over a network. As an express condition for the grants of license hereunder,
67
+ You must treat any External Deployment by You of the Original Work or a Derivative Work
68
+ as a distribution under section 1(c).
69
+
70
+ 6) Attribution Rights. You must retain, in the Source Code of any Derivative Works
71
+ that You create, all copyright, patent, or trademark notices from the Source Code of
72
+ the Original Work, as well as any notices of licensing and any descriptive text identified
73
+ therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works
74
+ that You create to carry a prominent Attribution Notice reasonably calculated to inform
75
+ recipients that You have modified the Original Work.
76
+
77
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright
78
+ in and to the Original Work and the patent rights granted herein by Licensor are owned by
79
+ the Licensor or are sublicensed to You under the terms of this Licence with the permission
80
+ of the contributor(s) of those copyrights and patent rights. Except as expressly stated in
81
+ the immediately preceding sentence, the Original Work is provided under this Licence on an
82
+ "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation,
83
+ the warranties of non-infringement, merchantability or fitness for a particular purpose.
84
+ THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY
85
+ constitutes an essential part of this Licence. No license to the Original Work is granted
86
+ by this Licence except under this disclaimer.
87
+
88
+ 8) Limitation of Liability. Under no circumstances and under no legal theory, whether
89
+ in tort (including negligence), contract, or otherwise, shall the Licensor be liable
90
+ to anyone for any indirect, special, incidental, or consequential damages of any character
91
+ arising as a result of this Licence or the use of the Original Work including, without
92
+ limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction,
93
+ or any and all other commercial damages or losses. This limitation of liability shall not
94
+ apply to the extent applicable law prohibits such limitation.
95
+
96
+ 9) Acceptance and Termination. If, at any time, You expressly assented to this Licence,
97
+ that assent indicates your clear and irrevocable acceptance of this Licence and all of its
98
+ terms and conditions. If You distribute or communicate copies of the Original Work or a
99
+ Derivative Work, You must make a reasonable effort under the circumstances to obtain the
100
+ express assent of recipients to the terms of this Licence. This Licence conditions your
101
+ rights to undertake the activities listed in Section 1, including your right to create
102
+ Derivative Works based upon the Original Work, and doing so without honoring these
103
+ terms and conditions is prohibited by copyright law and international treaty. Nothing
104
+ in this Licence is intended to affect copyright exceptions and limitations (including
105
+ "fair use" or "fair dealing"). This Licence shall terminate immediately and You may no
106
+ longer exercise any of the rights granted to You by this Licence upon your failure to
107
+ honor the conditions in Section 1(c).
108
+
109
+ 10) Termination for Patent Action. This Licence shall terminate automatically and
110
+ You may no longer exercise any of the rights granted to You by this Licence as of
111
+ the date You commence an action, including a cross-claim or counterclaim, against
112
+ Licensor or any licensee alleging that the Original Work infringes a patent. This
113
+ termination provision shall not apply for an action alleging patent infringement
114
+ by combinations of the Original Work with other software or hardware.
115
+
116
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this Licence
117
+ may be brought only in the courts of a jurisdiction wherein the Licensor resides or
118
+ in which Licensor conducts its primary business, and under the laws of that jurisdiction
119
+ excluding its conflict-of-law provisions. The application of the United Nations Convention
120
+ on Contracts for the International Sale of Goods is expressly excluded. Any use of
121
+ the Original Work outside the scope of this Licence or after its termination shall be
122
+ subject to the requirements and penalties of copyright or patent law in the appropriate
123
+ jurisdiction. This section shall survive the termination of this Licence.
124
+
125
+ 12) Attorneys' Fees. In any action to enforce the terms of this Licence or seeking
126
+ damages relating thereto, the prevailing party shall be entitled to recover its costs
127
+ and expenses, including, without limitation, reasonable attorneys' fees and costs
128
+ incurred in connection with such action, including any appeal of such action. This
129
+ section shall survive the termination of this Licence.
130
+
131
+ 13) Miscellaneous. If any provision of this Licence is held to be unenforceable,
132
+ such provision shall be reformed only to the extent necessary to make it enforceable.
133
+
134
+ 14) Definition of "You" in This Licence. "You" throughout this Licence, whether in
135
+ upper or lower case, means an individual or a legal entity exercising rights under,
136
+ and complying with all of the terms of, this Licence. For legal entities, "You" includes
137
+ any entity that controls, is controlled by, or is under common control with you. For
138
+ purposes of this definition, "control" means (i) the power, direct or indirect, to cause
139
+ the direction or management of such entity, whether by contract or otherwise, or (ii)
140
+ ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
141
+ ownership of such entity.
142
+
143
+ 15) Right to Use. You may use the Original Work in all ways not otherwise restricted or
144
+ conditioned by this Licence or by law, and Licensor promises not to interfere with or be
145
+ responsible for such uses by You.
146
+
147
+ 16) Modification of This Licence. This Licence is Copyright © 2005 Lawrence Rosen.
148
+ Permission is granted to copy, distribute, or communicate this Licence without modification.
149
+ Nothing in this Licence permits You to modify this Licence as applied to the Original Work
150
+ or to Derivative Works. However, You may modify the text of this Licence and copy, distribute
151
+ or communicate your modified version (the "Modified Licence") and apply it to other original
152
+ works of authorship subject to the following conditions: (i) You may not indicate in any way
153
+ that your Modified Licence is the "Open Software Licence" or "OSL" and you may not use those
154
+ names in the name of your Modified Licence; (ii) You must replace the notice specified in the
155
+ first paragraph above with the notice "Licensed under <insert your license name here>" or
156
+ with a notice of your own that is not confusingly similar to the notice in this Licence;
157
+ and (iii) You may not claim that your original works are open source software unless your
158
+ Modified Licence has been approved by Open Source Initiative (OSI) and You comply with
159
+ its license review and certification process.
@@ -0,0 +1,146 @@
1
+ # JELLY
2
+
3
+ ### (a.k.a. Jumpin Ermin's Loquatious Logger)
4
+
5
+ Based on the standard ruby logger, Jellog provides a slightly simplified interface and
6
+ adds a few features that may be useful:
7
+
8
+ * the ability to log to syslog for certain messages, which can be disabled during
9
+ setup;
10
+ * formats its own timestamp to avoid other software from interferring under the bonnet;
11
+ * colourises logs;
12
+ * provides a 'puts' method to enable apps to output to either console or log (e.g foreground
13
+ vs background);
14
+ * returns logged messages, e.g. to cascade into exceptions
15
+ * simple log level control.
16
+
17
+ ## Installation
18
+
19
+ Distributed as a gem:
20
+
21
+ gem install jellog
22
+
23
+ Jellog comes with a single command: jellog, that provides access to the README file in the gem.
24
+
25
+ Jellog can also be downloaded from [GitHub](https://github.com/osburn-sharp/jellog).
26
+
27
+ ## Getting Started
28
+
29
+ A simple example:
30
+
31
+ require 'jellog'
32
+ @logger = Jellog::Logger.new(name, params)
33
+ begin
34
+ @logger.system("This is a system message and will be logged to syslog")
35
+ @logger.info("Just logged to local log")
36
+ @logger.warn("As above")
37
+ @logger.mark
38
+ @logger.error("As above")
39
+ @logger.fatal("Logged to syslog and prefixed with 'Jellog Alert:'")
40
+ @logger.verbose("Logged locally if log_level = :verbose or :debug")
41
+ @logger.debug("Logged locally if log_level = :debug")
42
+ # when things go wrong
43
+ rescue => err
44
+ @logger.exception(err) # logs the entire backtrace in colour
45
+ ensure
46
+ @logger.close
47
+ end
48
+
49
+ This creates a jellog logger and logs a variety of messages before closing it. The parameters required
50
+ are defined in {Jellog::Config}, which is a subclass of Jeckyl::Config, (see [Jeckyl on GitHub](https://github.com/osburn-sharp/jeckyl)
51
+ for more details):
52
+
53
+ require 'jellog/config'
54
+ options = Jellog::Config.new('path/to/config.rb')
55
+ @logger = Jellog::Logger.new('MyLogger', options)
56
+
57
+ Check out {Jellog::Config} for details about the logging parameters available for Jellog.
58
+
59
+ In addition to these conventional uses, Jellog provides the following to tailor the log:
60
+
61
+ logger = Jellog::Logger.new(name, options)
62
+ logger.colours = colour_hash
63
+ logger.log_level = :debug
64
+
65
+ The colour_hash is a hash of :method => :colour (e.g. :fatal=>:blue) where colours are as defined
66
+ in term_ansicolor. There are three log levels:
67
+
68
+ * :system - basic logging required for normal applications
69
+ * :verbose - additional logging that should help trouble-shooting during roll-out etc
70
+ * :debug - lots of logging for development and testing purposes
71
+
72
+ The {Jellog::Logger#warn warning}, {Jellog::Logger#error error} and {Jellog::Logger#fatal fatal} logging methods all return the message as
73
+ a string to make it convenient to cascade logging with exception raising:
74
+
75
+ raise MyError, @logger.error("You did something stupid")
76
+
77
+ The {Jellog::Logger#mark mark} method simply puts a mark in the log, which can be set by one of the options.
78
+
79
+ There is also a {Jellog::Logger#puts puts} method that allows you to arrange output either to a standard out/error/file or a log
80
+ if required. This allows parts of your code to be agnostic about where messages go, e.g. in cases where you may or may not
81
+ daemonize a task.
82
+
83
+ When using the logger as part of a service (or any other application), it may be useful to extract the parameters that are specific
84
+ to the logger only. Check out the Jeckyl class method #intersection to get these options:
85
+
86
+ log_opts = Jellog::Config.intersection(full_opts)
87
+ nonlog_opts = full_opts.complement(log_opts)
88
+
89
+ More details of Jeckyl can be found on [GitHub](https://github.com/osburn-sharp/jeckyl).
90
+
91
+ ## Code Walkthrough
92
+
93
+ The {Jellog::Logger} presents a public interface with a range of logging methods and fairly simple customising options. It does
94
+ not do any logging itself, but creates an instance of {Jellog::Slogger} that is a simple wrapper around the standard ruby logger
95
+ but uses its own timestamps to defeat any other part of an application from fiddling with these settings: the standard logger
96
+ time stamp format is defined in a global variable and other users can change it with impunity.
97
+
98
+ This all seems a little complicated and I suspect it may be historical, the ruby logger being wrapped in Slogger to avoid
99
+ naming conflicts with Jellog::logger. The little bit of meta-magic used in Slogger, however, makes controlling attributes such
100
+ as colour and timestamps relatively compact while preserving an easy-to-read, non-magical user interface.
101
+
102
+ ## Dependencies
103
+
104
+ See {file:Gemfile} for gem dependencies.
105
+
106
+ ## Documentation
107
+
108
+ You can read this README file with 'jellog readme', but then as you are reading it you may already know this.
109
+
110
+ Use YARD to read the full documentation, which is available online at [RubyDoc.info](http://rdoc.info/github/osburn-sharp/jellog/frames)
111
+
112
+ ## Testing/Modifying
113
+
114
+ Download Jellog from [GitHub](https://github.com/osburn-sharp/jellog) for testing. There is an rspec test that covers most of the functionality:
115
+
116
+ rspec spec/jellog_spec.rb # tests the main functions
117
+ rspec spec/jellog_logger_spec.rb # tests colours (manually) and support
118
+ rspec spec/slogger_spec.rb # manual check of underlying logger
119
+
120
+ The last two tests don't really use rspec but generate logs in ./test and ./log which can be checked manually.
121
+
122
+ ## Bugs and Issues
123
+
124
+ Details of any unresolved bugs are in {file:Bugs.rdoc}.
125
+ Issues and change requests can be posted through [GitHub](https://github.com/osburn-sharp/jellog/issues).
126
+
127
+ ## Changelog
128
+
129
+ This can be found in the {file:History.txt} file. This file is used by Jevoom to manage the
130
+ version info and create git commits.
131
+
132
+ ## Author and Contact
133
+
134
+ I am Robert Sharp and you can contact me on [GitHub](http://github.com/osburn-sharp)
135
+
136
+ ## Copyright and Licence
137
+
138
+ Copyright (c) 2011-2012 Robert Sharp.
139
+
140
+ See {file:LICENCE.rdoc LICENCE} for details of the licence under which Jeckyl is released.
141
+
142
+ ## Warranty
143
+
144
+ This software is provided "as is" and without any express or implied
145
+ warranties, including, without limitation, the implied warranties of
146
+ merchantibility and fitness for a particular purpose.
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby18
2
+ #
3
+ # Description
4
+ #
5
+ # Author:: Robert Sharp
6
+ # Copyright:: Copyright (c) 2010 Robert Sharp
7
+ # License:: Open Software Licence v3.0
8
+ #
9
+ # This software is licensed for use under the Open Software Licence v. 3.0
10
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
11
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
12
+ # must themselves be licensed under the Open Software Licence v. 3.0
13
+ #
14
+ #
15
+ # replace this to point to your config class
16
+ # require 'my_jeckyl_configurator'
17
+ require 'rubygems' # delves into gem spec to find readme
18
+ require 'thor'
19
+ require 'colored'
20
+
21
+ class JellogCLI < Thor
22
+
23
+ default_task :usage
24
+
25
+ desc "usage", "You are looking at it"
26
+ def usage
27
+ puts "Assistance with Jellog."
28
+ puts ""
29
+ help
30
+ puts ""
31
+ puts "See Also:"
32
+ puts " README.md: (see jelloga readme above)"
33
+ puts " GitHub: https://github.com/osburn-sharp/jellog"
34
+ puts " RubyDoc: http://rdoc.info/github/osburn-sharp/jellog/frames"
35
+ end
36
+
37
+ desc "readme", "display the readme file for the gem"
38
+ def readme
39
+ gem_spec = Gem::Specification.find_by_name('jellog')
40
+ readme_path = File.join(gem_spec.gem_dir, 'README.md')
41
+ unless FileTest.exists?(readme_path)
42
+ puts "Cannot find a readme file to show you. Try GitHub?".red
43
+ invoke :usage
44
+ return 0
45
+ end
46
+ File.open(readme_path) do |rfile|
47
+ rfile.each_line do |rline|
48
+ puts rline
49
+ end
50
+ end
51
+
52
+ rescue Gem::LoadError
53
+
54
+ puts "Cannot find the gem for jellog, try GitHub for the README file.".red
55
+ invoke :usage
56
+
57
+ end
58
+
59
+ end
60
+
61
+ JellogCLI.start