tlogger 0.1

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: 472e400235e05ad0f6a0f77658d7558e4ac7cf75943eef77a86f0f303389be56
4
+ data.tar.gz: c2f663fd046d7bd2e4cd7f2ffbd357b5abe4698cc0fd569defa2ced00b4e50db
5
+ SHA512:
6
+ metadata.gz: cad7b5fb283038e2faeb0119770b273ed19fc971931a37f63d1c9cc1487682b14462ed688d4131ccca88d992034a93ffb0b952ce96833aed5bb7e79e4338b4ed
7
+ data.tar.gz: 1996d63685a208a60dd34de0badad0c1921a1eccdbba8178fb1dcecbcc9f4ad78a87ad5541a88c1321e1ad0cc056a8150e5acca962b6536ebac7380f12f5a15d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tlogger.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tlogger (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.0.1)
10
+ coderay (1.1.2)
11
+ method_source (0.9.2)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ pry-byebug (3.7.0)
16
+ byebug (~> 11.0)
17
+ pry (~> 0.10)
18
+ rake (10.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 2.0)
25
+ pry
26
+ pry-byebug
27
+ rake (~> 10.0)
28
+ tlogger!
29
+
30
+ BUNDLED WITH
31
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Chris Liaw
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,37 @@
1
+ # Tlogger
2
+
3
+
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tlogger'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tlogger
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tlogger.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tlogger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ #require "irb"
14
+ #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/lib/tlogger.rb ADDED
@@ -0,0 +1,186 @@
1
+
2
+
3
+ require 'logger'
4
+ require 'singleton'
5
+
6
+ require "tlogger/version"
7
+
8
+ module Tlogger
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+
12
+ #
13
+ # Singleton object to facilitate tag management
14
+ #
15
+ class TloggerConf
16
+ include Singleton
17
+ attr_reader :active_tags, :scoped_tag, :disabled_tags, :auto_tag
18
+ GLOBAL_TAG = :global
19
+
20
+ def initialize
21
+ @active_tags = [:global]
22
+ @disabled_tags = []
23
+ @disable_all_tags = false
24
+ @auto_tag = false
25
+ end
26
+
27
+ def auto_tag_on
28
+ @auto_tag = true
29
+ end
30
+
31
+ def auto_tag_off
32
+ @auto_tag = false
33
+ end
34
+
35
+ def is_auto_tag_on?
36
+ @auto_tag
37
+ end
38
+
39
+ def activate_tag(tag)
40
+ @active_tags << tag
41
+ end
42
+
43
+ def deactivate_tag(tag)
44
+ @active_tags.delete(tag)
45
+ end
46
+
47
+ def disable_tag(tag)
48
+ if tag.is_a?(Array)
49
+ @disabled_tags += tag
50
+ else
51
+ @disabled_tags << tag
52
+ end
53
+ end
54
+
55
+ def all_tags_off
56
+ @disable_all_tags = true
57
+ end
58
+
59
+ def enable_tag(tag)
60
+ if tag.is_a?(Array)
61
+ tag.each do |t|
62
+ @disabled_tags.delete(t)
63
+ end
64
+ else
65
+ @disabled_tags.delete(tag)
66
+ end
67
+ end
68
+
69
+ def is_tag_active?(tag)
70
+ if @disable_all_tags
71
+ false
72
+ else
73
+ @active_tags.include?(tag) and not @disabled_tags.include?(tag)
74
+ end
75
+ end
76
+
77
+ def remove_all_active_tags
78
+ @active_tags.clear
79
+ end
80
+
81
+ def remove_all_disabled_tags
82
+ @disabled_tags.clear
83
+ end
84
+
85
+ def set_scoped_tag(tag)
86
+ @scoped_tag = tag
87
+ end
88
+
89
+ def clear_scoped_tag
90
+ @scoped_tag = nil
91
+ end
92
+
93
+ def has_scoped_tag?
94
+ if @disable_all_tags
95
+ false
96
+ else
97
+ not @scoped_tag.nil? and not @scoped_tag.empty?
98
+ end
99
+ end
100
+
101
+ def self.method_missing(mtd,*args,&block)
102
+ if TloggerConf.instance.respond_to?(mtd)
103
+ TloggerConf.instance.send(mtd,*args,&block)
104
+ else
105
+ super
106
+ end
107
+ end
108
+ end
109
+ #
110
+ # end TloggerConf singleton
111
+ #
112
+
113
+ #
114
+ # add object like methods to make module a class
115
+ #
116
+ class << self
117
+ attr_accessor :tag
118
+
119
+ PROXY_MTD = [:debug, :info, :error, :warn]
120
+ def new(*args)
121
+ @tlogger = Logger.new(*args)
122
+ @tag = TloggerConf::GLOBAL_TAG
123
+ self
124
+ end
125
+
126
+ def tag=(val)
127
+ @tag = val
128
+ TloggerConf.activate_tag(@tag)
129
+ end
130
+
131
+ def method_missing(mtd,*args,&block)
132
+ if @tlogger.respond_to?(mtd)
133
+ if TloggerConf.is_tag_active?(@tag) or TloggerConf.has_scoped_tag?
134
+ if PROXY_MTD.include?(mtd)
135
+ if TloggerConf.has_scoped_tag?
136
+ args[0] = "[#{TloggerConf.scoped_tag}] #{args[0]}"
137
+ else
138
+ if not @tag.nil? and not @tag.empty?
139
+ if @tag == TloggerConf::GLOBAL_TAG
140
+ if TloggerConf.is_auto_tag_on?
141
+ args = tag_class(*args)
142
+ end
143
+ else
144
+ args[0] = "[#{@tag}] #{args[0]}"
145
+ end
146
+ elsif TloggerConf.is_auto_tag_on?
147
+ args = tag_class(*args)
148
+ end
149
+ end
150
+
151
+ end
152
+
153
+ @tlogger.send(mtd,*args,&block)
154
+ end
155
+ elsif TloggerConf.respond_to?(mtd)
156
+ TloggerConf.send(mtd, *args, &block)
157
+ else
158
+ super
159
+ end
160
+ end
161
+
162
+ private
163
+ def tag_class(*args)
164
+ caller.each do |c|
165
+ next if c =~ /tlogger.rb/
166
+ @cal = c
167
+ break
168
+ end
169
+ args[0] = "[#{@cal}] #{args[0]}"
170
+ end
171
+
172
+ end
173
+ #
174
+ # end class definition
175
+ #
176
+
177
+
178
+ def with_tag(tag,&block)
179
+ if block
180
+ TloggerConf.instance.set_scoped_tag(tag)
181
+ block.call
182
+ TloggerConf.instance.clear_scoped_tag
183
+ end
184
+ end
185
+
186
+ end
@@ -0,0 +1,3 @@
1
+ module Tlogger
2
+ VERSION = "0.1"
3
+ end
data/release.job ADDED
@@ -0,0 +1,53 @@
1
+
2
+
3
+ job :release do
4
+
5
+ include_job :prompt_version
6
+ #ver = prompt "Please provide version for this release:", required: true
7
+ #set :releasing_version, ver
8
+
9
+ include_job :build
10
+ include_job :check_in
11
+
12
+ end
13
+
14
+ job :prompt_version do
15
+ if get(:releasing_version) == nil
16
+ ver = prompt "Please provide version for this release:", required: true
17
+ set :releasing_version, ver
18
+ end
19
+ end
20
+
21
+ job :build do
22
+
23
+ dir '/Volumes/Stash/08.Dev/01.Workspaces/incu-2019/tlogger'
24
+
25
+ include_job :prompt_version
26
+
27
+ rubygem do
28
+ #publish build('alog.gemspec'), ignore_status: true #do |res|
29
+ build('tlogger.gemspec') do |res|
30
+ publish(res, ignore_status: true)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+
37
+ job :check_in do
38
+ dir '/Volumes/Stash/08.Dev/01.Workspaces/incu-2019/tlogger'
39
+ git do
40
+ commit
41
+ tag
42
+ push 'origin', 'master'
43
+ push 'git','master'
44
+ end
45
+ end
46
+
47
+ job :reinstall do
48
+ rubygem do
49
+ uninstall 'tlogger'
50
+ install 'tlogger'
51
+ end
52
+ end
53
+
data/samples/basic.rb ADDED
@@ -0,0 +1,44 @@
1
+
2
+
3
+ #
4
+ # basic use case
5
+ #
6
+
7
+ class Cls
8
+
9
+ # to get the with_tag()
10
+ include Tlogger
11
+
12
+ def initialize
13
+ @log = Tlogger.new(STDOUT)
14
+ @log.tag = :cls
15
+ end
16
+
17
+ def bark
18
+ @log.debug "wuf wof"
19
+ end
20
+
21
+ def say
22
+ with_tag(:say) do
23
+ @log.debug "inside say"
24
+ puts "Say hello world!"
25
+ @log.warn "after hello!"
26
+ end
27
+
28
+ @log.error "Error here..."
29
+ end
30
+ end
31
+
32
+ #if $0 == __FILE__
33
+
34
+ #Tlogger::TloggerConf.auto_tag_on
35
+ #Tlogger::TloggerConf.disable_all_tags
36
+ #Tlogger::TloggerConf.disable_tag([:cls])
37
+
38
+ c = Cls.new
39
+ c.bark
40
+ c.say
41
+
42
+ #end
43
+
44
+
data/tlogger.gemspec ADDED
@@ -0,0 +1,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tlogger/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tlogger"
8
+ spec.version = Tlogger::VERSION
9
+ spec.authors = ["Chris Liaw"]
10
+ spec.email = ["chrisliaw@antrapol.com"]
11
+
12
+ spec.summary = ""
13
+ spec.description = ""
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ #else
26
+ # raise "RubyGems 2.0 or newer is required to protect against " \
27
+ # "public gem pushes."
28
+ #end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.required_ruby_version = '~> 1.8.6'
40
+
41
+ spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "pry"
44
+ spec.add_development_dependency "pry-byebug"
45
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tlogger
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Chris Liaw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - chrisliaw@antrapol.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/tlogger.rb
85
+ - lib/tlogger/version.rb
86
+ - release.job
87
+ - samples/basic.rb
88
+ - tlogger.gemspec
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.6
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.7.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: ''
113
+ test_files: []