bole 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6355de532f85d1cc039d722cff3fecb3d5c3acaf63b1483ec4e4e9783a146089
4
+ data.tar.gz: f575787cebbcda5ed2587ef2101921f36b80f4b3245d5f2d23a4017daa638222
5
+ SHA512:
6
+ metadata.gz: 5f11a2c5f2fe49008d528c4e8bee4eedb599d4c75694ecc24b04b69aa930e83b572a0956edd2f105e221cf6e51643c3fa5c14fa445a171cb26b1175d6ac010d9
7
+ data.tar.gz: cbf6310b8a242effb02360adf284c18f80ae84e838d3b7750660d5e018e2c252eeed0c5ffc3e6efd585b5ceb87cdd453cd9d7cd2cfaf0eaeba219f24a3042d0c
data/.byebug_history ADDED
@@ -0,0 +1,176 @@
1
+ continue
2
+ next
3
+ Bole::Manager.config.data.bole.file
4
+ quit
5
+ bole.logger.dev.read
6
+ bole.logger.dev.rewind
7
+ string_out.read
8
+ next
9
+ string_out
10
+ next
11
+ bole.logger.dev
12
+ bole.logger
13
+ string_out
14
+ bole.level
15
+ quit
16
+ @logdev
17
+ continue
18
+ exception
19
+ next
20
+ quit
21
+ exception
22
+ next
23
+ Bole::Manager.config.data.bole.file
24
+ continue
25
+ quit
26
+ Sycle::Hash.new
27
+ Bole::Manager.config.data
28
+ Bole::Manager.config.class
29
+ Bole::Manager.config
30
+ Bole::Manager.config[:data]
31
+ Bole::Manager.config.bole
32
+ Bole::Manager.config.data
33
+ Bole::Manager.config.class
34
+ Bole::Manager.config.data
35
+ Bole::Manager.config.data.bole
36
+ Bole::Manager.config
37
+ step
38
+ next
39
+ config
40
+ continue
41
+ next
42
+ @level
43
+ next
44
+ @enabled
45
+ next
46
+ step
47
+ next
48
+ Bole::Manager.config.data.bole.progname
49
+ Bole::Manager.config.data.bole
50
+ Bole::Manager.config.data
51
+ Bole::Manager.config
52
+ step
53
+ next
54
+ config
55
+ continue
56
+ next
57
+ config
58
+ quit
59
+ class Beef; puts name; end
60
+ Balls::name
61
+ %w$Id$
62
+ %w$Id%
63
+ continue
64
+ next
65
+ rev
66
+ next
67
+ name
68
+ next
69
+ rev
70
+ name
71
+ _
72
+ quit
73
+ file.read
74
+ file.rewind
75
+ file.read
76
+ quit
77
+ file.read
78
+ file.rewind
79
+ file.rewind.read
80
+ quit
81
+ Bole::Manager.config.data.bole.file.read
82
+ Bole::Manager.config.data.bole.file.rewind
83
+ Bole::Manager.config.data.bole.file
84
+ Bole::Manager.config.
85
+ bole.config
86
+ file.rewind
87
+ file.rewind.read
88
+ file.read
89
+ file
90
+ bole.log(:info, 'foo')
91
+ Bole::Manager.config.data.bole.level
92
+ Bole::Manager.config.data.level
93
+ bole.config
94
+ bole.level
95
+ bole.enabled
96
+ file.read
97
+ file.rewind
98
+ file
99
+ quit
100
+ Bole::Manager.config
101
+ quit
102
+ bole.config
103
+ bole
104
+ Bole::Manager.config
105
+ quit
106
+ Bole::Manager.config
107
+ bole.config
108
+ bole = Bole::Manager.new('spec/fixtures/bole.yml')
109
+ Bole::Manager.config = 'data'
110
+ Bole::Manager.config
111
+ quit
112
+ @config
113
+ continue
114
+ @config
115
+ continue
116
+ @config
117
+ continue
118
+ @config
119
+ continue
120
+ @config
121
+ continue
122
+ logger.config
123
+ Bole::Manager.config
124
+ quit
125
+ logger.config
126
+ logger
127
+ logger.config
128
+ Bole::Manager.config
129
+ quit
130
+ continue
131
+ @config
132
+ quit
133
+ Bole::Manager.config
134
+ self.config
135
+ config.nil?
136
+ config
137
+ quit
138
+ continue
139
+ @@config.data.bole.format
140
+ continue
141
+ quit
142
+ continue
143
+ step
144
+ @@config.data.bole.format
145
+ continue
146
+ have_received(:parse_custom_formatter)
147
+ step
148
+ custom_format
149
+ continue
150
+ quit
151
+ step
152
+ custom_format
153
+ continue
154
+ step
155
+ next
156
+ step
157
+ next
158
+ @@config.data.bole
159
+ step
160
+ next
161
+ nex
162
+ Bole::Manager.config
163
+ quit
164
+ @@config.nil?
165
+ @@config
166
+ !@@config.nil?
167
+ @@config
168
+ q
169
+ next
170
+ quit
171
+ exception
172
+ next
173
+ Bole::Manager.config = nil
174
+ Bole::Manager.config
175
+ Bole::Manager.config = nil
176
+ Bole::Manager.config
@@ -0,0 +1,30 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/bole
5
+ docker:
6
+ - image: circleci/ruby:2.5.1-node-browsers
7
+ steps:
8
+ - checkout
9
+
10
+ - type: cache-restore
11
+ name: Restore bundle cache
12
+ key: initrax-bundle-{{ checksum "Gemfile.lock" }}
13
+
14
+ - run:
15
+ name: Bundle Install
16
+ command: bundle install --path vendor/bundle
17
+
18
+ - type: cache-save
19
+ name: Store bundle cache
20
+ key: initrax-bundle-{{ checksum "Gemfile.lock" }}
21
+ paths:
22
+ - vendor/bundle
23
+
24
+ - run:
25
+ name: Rubocop
26
+ command: bundle exec rubocop
27
+
28
+ - run:
29
+ name: Run Rspec specs
30
+ command: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,111 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ require:
4
+ - rubocop/cop/internal_affairs
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'vendor/**/*'
10
+ - 'spec/fixtures/**/*'
11
+ - 'tmp/**/*'
12
+ TargetRubyVersion: 2.3
13
+
14
+ Naming/PredicateName:
15
+ # Method define macros for dynamically generated method.
16
+ MethodDefinitionMacros:
17
+ - define_method
18
+ - define_singleton_method
19
+ - def_node_matcher
20
+ - def_node_search
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ EnforcedStyle: always
24
+
25
+ Style/FormatStringToken:
26
+ # Because we parse a lot of source codes from strings. Percent arrays
27
+ # look like unannotated format string tokens to this cop.
28
+ Exclude:
29
+ - spec/**/*
30
+
31
+ Style/IpAddresses:
32
+ # The test for this cop includes strings that would cause offenses
33
+ Exclude:
34
+ - spec/rubocop/cop/style/ip_addresses_spec.rb
35
+
36
+ Layout/EndOfLine:
37
+ EnforcedStyle: lf
38
+
39
+ Layout/ClassStructure:
40
+ Enabled: true
41
+ Categories:
42
+ module_inclusion:
43
+ - include
44
+ - prepend
45
+ - extend
46
+ ExpectedOrder:
47
+ - module_inclusion
48
+ - constants
49
+ - public_class_methods
50
+ - initializer
51
+ - instance_methods
52
+ - protected_methods
53
+ - private_methods
54
+
55
+ Layout/IndentHeredoc:
56
+ EnforcedStyle: powerpack
57
+
58
+ # Trailing white space is meaningful in code examples
59
+ Layout/TrailingWhitespace:
60
+ AllowInHeredoc: true
61
+
62
+ Lint/AmbiguousBlockAssociation:
63
+ Exclude:
64
+ - 'spec/**/*.rb'
65
+
66
+ Lint/InterpolationCheck:
67
+ Exclude:
68
+ - 'spec/**/*.rb'
69
+
70
+ Lint/UselessAccessModifier:
71
+ MethodCreatingMethods:
72
+ - 'def_matcher'
73
+ - 'def_node_matcher'
74
+
75
+ Lint/BooleanSymbol:
76
+ Enabled: false
77
+
78
+ Metrics/AbcSize:
79
+ Max: 20
80
+
81
+ Metrics/CyclomaticComplexity:
82
+ Max: 10
83
+
84
+ Metrics/LineLength:
85
+ Enabled: false
86
+
87
+ Metrics/BlockLength:
88
+ Enabled: false
89
+
90
+ Metrics/ModuleLength:
91
+ Exclude:
92
+ - 'spec/**/*.rb'
93
+
94
+ Metrics/ParameterLists:
95
+ Max: 10
96
+
97
+ Performance/Caller:
98
+ Exclude:
99
+ - spec/rubocop/cop/performance/caller_spec.rb
100
+
101
+ RSpec/PredicateMatcher:
102
+ EnforcedStyle: inflected
103
+
104
+ RSpec/NestedGroups:
105
+ Max: 7
106
+
107
+ RSpec/MultipleExpectations:
108
+ Max: 2
109
+
110
+ RSpec/ExampleLength:
111
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ bole
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tgourley@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bole (0.1.0)
5
+ konfigyu (~> 0.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ byebug (10.0.2)
12
+ diff-lcs (1.3)
13
+ jaro_winkler (1.5.1)
14
+ konfigyu (0.1.0)
15
+ syck (~> 1.3.0)
16
+ sycl (~> 1.6)
17
+ parallel (1.12.1)
18
+ parser (2.5.1.2)
19
+ ast (~> 2.4.0)
20
+ powerpack (0.1.2)
21
+ rainbow (3.0.0)
22
+ rake (10.5.0)
23
+ rspec (3.8.0)
24
+ rspec-core (~> 3.8.0)
25
+ rspec-expectations (~> 3.8.0)
26
+ rspec-mocks (~> 3.8.0)
27
+ rspec-core (3.8.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-expectations (3.8.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-mocks (3.8.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-support (3.8.0)
36
+ rubocop (0.59.2)
37
+ jaro_winkler (~> 1.5.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.5, != 2.5.1.1)
40
+ powerpack (~> 0.1)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (~> 1.0, >= 1.0.1)
44
+ rubocop-rspec (1.29.1)
45
+ rubocop (>= 0.58.0)
46
+ ruby-progressbar (1.10.0)
47
+ syck (1.3.0)
48
+ sycl (1.6)
49
+ unicode-display_width (1.4.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bole!
56
+ bundler (~> 1.16)
57
+ byebug (~> 10.0.2)
58
+ rake (~> 10.0)
59
+ rspec (~> 3.8.0)
60
+ rubocop (~> 0.59.2)
61
+ rubocop-rspec (~> 1.29.1)
62
+
63
+ BUNDLED WITH
64
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Tim Gourley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Bole
2
+
3
+ ![CircleCI branch](https://img.shields.io/circleci/project/github/bratta/bole/master.svg)
4
+ ![GitHub](https://img.shields.io/github/license/bratta/bole.svg)
5
+ ![GitHub issues](https://img.shields.io/github/issues/bratta/bole.svg)
6
+ ![Gem](https://img.shields.io/gem/v/bole.svg)
7
+
8
+ The Ruby Logger, part of the standard library, is a pretty decent logging tool but isn't as easy to use or as configurable as I would like it to be. This gem wraps Logger with some extra love to allow it to load configuration values from a YAML file via the [Konfigyu](https://github.com/bratta/konfigyu) gem as well as giving it the ability to be enabled/disabled via a flag or by setting the logging level to `:none`.
9
+
10
+ This gem also makes it easier to swap logging devices on the fly, so you can switch between log files, StringIO instances, or STDOUT, etc. without creating a new intance of the object.
11
+
12
+ The Konfigyu data can be loaded from the YAML file when a Bole instance is created, or you can set it on the class if you have an existing config used by the rest of your application.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'bole'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install bole
29
+
30
+ ## Usage
31
+
32
+ The most basic usage is the exact same as the [Ruby Logger](https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html) class.
33
+
34
+ It gets more interesting when you set up a config file and pass that to the class. For example, you can create a configuration file that looks like this and save it as `bole.yml`:
35
+
36
+ ```yaml
37
+ bole:
38
+ file: /tmp/bole.log
39
+ level: info
40
+ progname: Bole
41
+ format: "[ {datetime} :: {severity} from {progname} ] {msg}"
42
+ ```
43
+
44
+ Then, in your code, you can instantiate the Bole logger like this:
45
+
46
+ ```ruby
47
+ require 'bole'
48
+ bole = Bole::Manager.new(STDOUT, config: 'bole.yml')
49
+
50
+ bole.info('This is a test log message')
51
+ ```
52
+
53
+ Then if you look at `/tmp/bole.log` you should see:
54
+
55
+ ```
56
+ # Logfile created on 2018-10-03 14:19:01 -0500 by logger.rb/61378
57
+ [ 2018-10-03 14:22:02 -0500 :: INFO from Bole ] This is a test log message
58
+ ```
59
+
60
+ ## Switching the logger
61
+
62
+ You can use `bole.logger` to change the logging device on the fly:
63
+
64
+ ```ruby
65
+ require 'bole'
66
+ require 'stringio'
67
+
68
+ bole = Bole::Manager.new(STDOUT)
69
+ bole.info('This goes to STDOUT')
70
+
71
+ string_out = StringIO.new
72
+ bole.logger = string_out
73
+ bole.info('This goes to StringIO')
74
+ string_out.rewind
75
+ puts string_out.read
76
+ ```
77
+
78
+ ## Configuration File Format
79
+
80
+ The format of the configuration file looks like this:
81
+
82
+ ```yaml
83
+ bole:
84
+ # (optional) If not specified, logging will go to whatever
85
+ # is passed to the constructor of the object, or STDOUT barring
86
+ # that. If you wish to use a File object, STDERR, or something
87
+ # like StringIO, then omit this value and pass it in the
88
+ # constructor, or set @logger (which this class exposes).
89
+ file: /var/log/bole.log
90
+
91
+ # (required) One of: none, fatal, error, warn, info, or debug
92
+ level: info
93
+
94
+ # (optional) The reporting program name. Defaults to 'Bole'
95
+ progname: Bole
96
+
97
+ # (optional) will default to Ruby's default Logger formatter
98
+ # This is a string with these variables replaced. If you
99
+ # wish to override the datetime format, you can always set the
100
+ # value in code, e.g.:
101
+ #
102
+ # bole = Bole::Manager.new(config_file)
103
+ # bole.datetime_format = '%Y-%m-%d %H:%M:%S'
104
+ format: "[ {datetime} :: {severity} from {progname} ] {msg}"
105
+ ```
106
+
107
+ ### bole.file
108
+
109
+ In the configuration file, if you specify a file for Bole to use for logging, it will use that instead of whatever is passed to the constructor. Note that currently this is a bit awkward as the config file is read AFTER the base logger is instantiated, so you end up with a default logger (STDOUT or whatever you pass as the first argument to the initializer), then it is switched over to whatever you specify in the file. Future versions may fix this.
110
+
111
+ You can't use an open File object, StringIO, or STDOUT/STDERR in this case. You will only be able to pass a file name via the configuration file. If you want to use something more advanced, do it when you create the logger or by using `bole.logger = STDOUT` to set the logging device.
112
+
113
+ ### bole.level
114
+
115
+ These correspond to the logging levels in the default Ruby Logger class, but we also add the "none" level, which is one way to disable logging either temporarily or permenantly. You can also pause logging in code by setting `bole.enabled = false` and then `bole.enabled = true` to re-enable logging.
116
+
117
+ ### bole.progname
118
+
119
+ This is the name of the program as displayed in the log message.
120
+
121
+ ### bole.format
122
+
123
+ If you wish to override the format, you can specify a string here with some template variables.
124
+
125
+ * **{datetime}** = The datetime
126
+ * **{severity}** = The logging level (i.e. INFO, DEBUG, etc.)
127
+ * **{progname}** = The program name
128
+ * **{msg}** = The log message itself
129
+
130
+ An example would be this string:
131
+
132
+ ```yaml
133
+ bole:
134
+ level: info
135
+ format: "-=# {datetime} -- Message from {progname} ({severity}) :: {msg} #=-"
136
+ ```
137
+
138
+ Resulting in:
139
+
140
+ ```
141
+ -=# 2018-10-03 14:22:02 -0500 -- Message from Bole (INFO) :: This is a test log message #=-
142
+ ```
143
+
144
+ Note that none of the fields are required, so omit ones you don't need. In the future filtering and transorming might be possible. For now, though, if you need something complex like formatting the timestamp to something custom, you can use the regular facilities from the Ruby Logger class to make your changes.
145
+
146
+ ## Configuration Sharing
147
+
148
+ Let's say you have an application that already has a Konfigyu YAML loaded and you want to add a section for Bole and use it. It's easy to share config by setting it on the class before instantiating it, and it will use that config:
149
+
150
+ ```ruby
151
+ # Config exists in 'config'
152
+ config = Konfigyu::Config.new('application.yml')
153
+
154
+ Bole::Manager.config = config
155
+ bole = Bole::Manager.new
156
+ bole.info('Done!')
157
+ ```
158
+
159
+ ## Development
160
+
161
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
162
+
163
+ To install this gem onto your local machine, run `bundle exec rake install`.
164
+
165
+ ## Contributing
166
+
167
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bratta/bole. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
168
+
169
+ ## License
170
+
171
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
172
+
173
+ ## Code of Conduct
174
+
175
+ Everyone interacting in the Bole project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bratta/bole/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
4
+ require 'bundler/setup'
5
+ require 'bole'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bole.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bole/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'bole'
9
+ spec.version = Bole::VERSION
10
+ spec.authors = ['Tim Gourley']
11
+ spec.email = ['tgourley@gmail.com']
12
+
13
+ spec.summary = 'Simple Ruby File Logger'
14
+ spec.description = 'Log messages to a file or stdout with a timestamp'
15
+ spec.homepage = 'https://github.com/bratta/bole'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ # Required dependencies
28
+ spec.add_dependency 'konfigyu', '~> 0.1.0'
29
+
30
+ # Development Dependencies
31
+ spec.add_development_dependency 'bundler', '~> 1.16'
32
+ spec.add_development_dependency 'byebug', '~> 10.0.2'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.8.0'
35
+ spec.add_development_dependency 'rubocop', '~> 0.59.2'
36
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.29.1'
37
+ end
data/bole.yml.example ADDED
@@ -0,0 +1,22 @@
1
+ bole:
2
+ # (optional) If not specified, logging will go to whatever
3
+ # is passed to the constructor of the object, or STDOUT barring
4
+ # that. If you wish to use a File object, STDERR, or something
5
+ # like StringIO, then omit this value and pass it in the
6
+ # constructor, or set @logger (which this class exposes).
7
+ file: /var/log/bole.log
8
+
9
+ # (required) One of: none, fatal, error, warn, info, or debug
10
+ level: info
11
+
12
+ # (optional) The reporting program name. Defaults to 'Bole'
13
+ progname: Bole
14
+
15
+ # (optional) will default to Ruby's default Logger formatter
16
+ # This is a string with these variables replaced. If you
17
+ # wish to override the datetime format, you can always set the
18
+ # value in code, e.g.:
19
+ #
20
+ # bole = Bole::Manager.new(config_file)
21
+ # bole.datetime_format = '%Y-%m-%d %H:%M:%S'
22
+ format: "[ {datetime} :: {severity} from {progname} ] {msg}"
data/lib/bole.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'konfigyu'
5
+ require 'sycl'
6
+
7
+ require 'bole/version'
8
+ require 'bole/manager'
9
+
10
+ # Define the module namespace for this gem
11
+ module Bole
12
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bole
4
+ # Logger main class
5
+ class Manager < Logger
6
+ attr_accessor :enabled
7
+
8
+ PROGNAME = 'Bole'
9
+ LOG_LEVELS = {
10
+ none: Logger::UNKNOWN,
11
+ fatal: Logger::FATAL,
12
+ error: Logger::ERROR,
13
+ warn: Logger::WARN,
14
+ info: Logger::INFO,
15
+ debug: Logger::DEBUG
16
+ }.freeze
17
+
18
+ # Class level accessibility for config
19
+ class << self
20
+ attr_accessor :config
21
+ end
22
+
23
+ # Initializer arguments:
24
+ # The first set of arguments are the exact same as the Ruby
25
+ # Standard Library's logger class. The goal of this class is to
26
+ # extend the functionality to make the class easier to work with
27
+ # so we are adding an extra argument to take an additional option:
28
+ #
29
+ # config: '/path/to/bole.yml'
30
+ #
31
+ # This is an optional argument that is the path to the Konfigyu
32
+ # config YAML file so defaults can easily be persisted as part of
33
+ # your application's configuration. Optionally you can specify an
34
+ # existing Konfigyu object in Bole::Manager.config
35
+ def initialize(logdev = STDOUT, shift_age = 0, shift_size = 1_048_576,
36
+ level: LOG_LEVELS[:debug], progname: nil, formatter: nil,
37
+ datetime_format: nil, shift_period_suffix: '%Y%m%d',
38
+ config: nil)
39
+ initialize_configuration(config)
40
+
41
+ @shift_age = shift_age
42
+ @shift_size = shift_size
43
+ @shift_period_suffix = '%Y%m%d'
44
+
45
+ super(logdev, shift_age, shift_size,
46
+ level: level, progname: progname, formatter: formatter,
47
+ datetime_format: datetime_format,
48
+ shift_period_suffix: shift_period_suffix)
49
+ initialize_logger
50
+ end
51
+
52
+ def logger
53
+ @logdev
54
+ end
55
+
56
+ def logger=(new_logdev)
57
+ @logdev = Logger::LogDevice.new(
58
+ new_logdev,
59
+ shift_age: @shift_age,
60
+ shift_size: @shift_size,
61
+ shift_period_suffix: @shift_period_suffix
62
+ )
63
+ end
64
+
65
+ def level=(severity)
66
+ if severity.to_s.casecmp('none').zero?
67
+ @level = Logger::UNKNOWN
68
+ @enabled = false
69
+ else
70
+ @enabled = true
71
+ super(severity)
72
+ end
73
+ end
74
+
75
+ def add(severity, message = nil, progname = nil)
76
+ super(severity, message, progname) if @enabled
77
+ end
78
+
79
+ private
80
+
81
+ def config_requirements
82
+ {
83
+ required_fields: ['bole', 'bole.level'],
84
+ required_values: {
85
+ 'bole.level': LOG_LEVELS.keys.map(&:to_s)
86
+ }
87
+ }
88
+ end
89
+
90
+ def initialize_configuration(config_file = nil)
91
+ return unless Bole::Manager.config.nil?
92
+
93
+ Bole::Manager.config =
94
+ if config_file
95
+ Konfigyu::Config.new(config_file, config_requirements)
96
+ else
97
+ Sycl::Hash.from_hash(
98
+ 'data' => { 'bole' => { 'level' => LOG_LEVELS.key(@level) } }
99
+ )
100
+ end
101
+ end
102
+
103
+ def initialize_logger
104
+ initialize_log_device
105
+ initialize_progname
106
+ initialize_formatter
107
+ initialize_log_level
108
+ end
109
+
110
+ def initialize_log_device
111
+ self.logger = Bole::Manager.config.data.bole.file if Bole::Manager.config.data.bole.file
112
+ end
113
+
114
+ def initialize_progname
115
+ @progname = Bole::Manager.config.data.bole.progname || PROGNAME if progname.nil?
116
+ end
117
+
118
+ def initialize_formatter
119
+ @formatter = get_custom_formatter(Bole::Manager.config.data.bole.format) if Bole::Manager.config.data.bole.format
120
+ end
121
+
122
+ def initialize_log_level
123
+ @enabled = Bole::Manager.config.data.bole.level != :none
124
+ @level = LOG_LEVELS[Bole::Manager.config.data.bole.level&.to_sym] || Logger::DEBUG
125
+ end
126
+
127
+ def get_custom_formatter(custom_format)
128
+ proc do |severity, datetime, progname, msg|
129
+ parse_custom_formatter(custom_format, severity, datetime, progname, msg)
130
+ end
131
+ end
132
+
133
+ def parse_custom_formatter(format, severity, datetime, progname, msg)
134
+ format.gsub('{severity}', severity || '')
135
+ .gsub('{datetime}', datetime.to_s || '')
136
+ .gsub('{progname}', progname || '')
137
+ .gsub('{msg}', msg || '')
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Version number
4
+ module Bole
5
+ VERSION = '0.1.0'
6
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bole
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Gourley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: konfigyu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 10.0.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.59.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.59.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.29.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.29.1
111
+ description: Log messages to a file or stdout with a timestamp
112
+ email:
113
+ - tgourley@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".byebug_history"
119
+ - ".circleci/config.yml"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-gemset"
124
+ - ".ruby-version"
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/setup
133
+ - bole.gemspec
134
+ - bole.yml.example
135
+ - lib/bole.rb
136
+ - lib/bole/manager.rb
137
+ - lib/bole/version.rb
138
+ homepage: https://github.com/bratta/bole
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.6
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Simple Ruby File Logger
162
+ test_files: []