lager 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/MANIFEST.txt +5 -0
  2. data/README.md +3 -0
  3. data/VERSION +1 -0
  4. data/lib/lager.rb +40 -0
  5. data/rakefile.rb +126 -0
  6. metadata +82 -0
data/MANIFEST.txt ADDED
@@ -0,0 +1,5 @@
1
+ MANIFEST.txt
2
+ VERSION
3
+ README.md
4
+ rakefile.rb
5
+ lib/lager.rb
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Lager
2
+ =====
3
+ Lager is a logging mixin. It is designed to add class methods for logging
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1.1
data/lib/lager.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'logger'
2
+
3
+ module Lager
4
+ def self.log_to dest=nil
5
+ case dest
6
+ when nil, 'stderr', 'STDERR'
7
+ dest = $stderr
8
+ when 'stdout', 'STDOUT'
9
+ dest = $stdout
10
+ when IO
11
+ # do nothing
12
+ when String
13
+ # assume file path, do nothing
14
+ else
15
+ raise "unable to log_to #{dest} (#{dest.class})"
16
+ end
17
+ if defined?(@@log)
18
+ l = Logger.new dest
19
+ l.formatter = @@log.formatter
20
+ l.level = @@log.level
21
+ @@log = l
22
+ else
23
+ @@log = Logger.new dest
24
+ @@log.formatter = proc { |sev, time, progname, msg|
25
+ line = "[#{time.strftime('%Y-%m-%d %H:%M:%S')}] #{sev.to_s.upcase}: "
26
+ line << "(#{progname}) " if progname
27
+ line << msg << "\n"
28
+ }
29
+ @@log.level = Logger::WARN
30
+ end
31
+ @@log
32
+ end
33
+
34
+ def self.log_level=(sym)
35
+ log_to unless defined?(@@log)
36
+ level = Logger.const_get(sym.to_s.upcase)
37
+ raise "unknown log level #{sym}" unless level
38
+ @@log.level = level
39
+ end
40
+ end
data/rakefile.rb ADDED
@@ -0,0 +1,126 @@
1
+ require 'rubygems/package_task'
2
+
3
+ PROJECT_ROOT = File.dirname(__FILE__)
4
+ PROJECT_NAME = File.split(PROJECT_ROOT).last
5
+ VERSION_FILE = File.join(PROJECT_ROOT, 'VERSION')
6
+ MANIFEST_FILE = File.join(PROJECT_ROOT, 'MANIFEST.txt')
7
+
8
+ def version
9
+ File.read(VERSION_FILE).chomp
10
+ end
11
+
12
+ task :version do
13
+ puts "#{PROJECT_NAME} #{version}"
14
+ end
15
+
16
+ task :tag do
17
+ tagname = "v#{version}"
18
+ sh "git tag -a #{tagname} -m 'auto-tagged #{tagname} by Rake'"
19
+ sh "git push origin --tags"
20
+ end
21
+
22
+ def manifest
23
+ File.readlines(MANIFEST_FILE).map { |line| line.chomp }
24
+ end
25
+
26
+ task :manifest do
27
+ puts manifest.join("\n")
28
+ end
29
+
30
+ task :build => [:bump_build] do
31
+ spec = Gem::Specification.new do |s|
32
+ # Static assignments
33
+ s.name = PROJECT_NAME
34
+ s.summary = "FIX"
35
+ s.description = "FIX"
36
+ s.authors = ["FIX"]
37
+ s.email = "FIX@FIX.COM"
38
+ s.homepage = "http://FIX.COM/"
39
+ s.licenses = ['FIX']
40
+
41
+ # Dynamic assignments
42
+ s.files = manifest
43
+ s.version = version
44
+ s.date = Time.now.strftime("%Y-%m-%d")
45
+
46
+ # s.add_runtime_dependency "rest-client", ["~> 1"]
47
+ # s.add_runtime_dependency "json", ["~> 1"]
48
+ s.add_development_dependency "minitest", [">= 0"]
49
+ s.add_development_dependency "rake", [">= 0"]
50
+ end
51
+
52
+ # we're definining the task at runtime, rather than requiretime
53
+ # so that the gemspec will reflect any version bumping since requiretime
54
+ #
55
+ Gem::PackageTask.new(spec).define
56
+ Rake::Task["package"].invoke
57
+ end
58
+
59
+ # e.g. bump(:minor, '1.2.3') #=> '1.3.0'
60
+ # only works for integers delimited by periods (dots)
61
+ #
62
+ def bump(position, version)
63
+ pos = [:major, :minor, :patch, :build].index(position) || position
64
+ places = version.split('.')
65
+ raise "bad position: #{pos} (for version #{version})" unless places[pos]
66
+ places.map.with_index { |place, i|
67
+ if i < pos
68
+ place
69
+ elsif i == pos
70
+ place.to_i + 1
71
+ else
72
+ 0
73
+ end
74
+ }.join('.')
75
+ end
76
+
77
+ def write_version new_version
78
+ File.open(VERSION_FILE, 'w') { |f| f.write(new_version) }
79
+ end
80
+
81
+ [:major, :minor, :patch, :build].each { |v|
82
+ task "bump_#{v}" do
83
+ old_version = version
84
+ new_version = bump(v, old_version)
85
+ puts "bumping #{old_version} to #{new_version}"
86
+ write_version new_version
87
+ sh "git add VERSION"
88
+ sh "git commit -m 'rake bump_#{v}'"
89
+ end
90
+ }
91
+ task :bump => [:bump_patch]
92
+
93
+ task :verify_publish_credentials do
94
+ creds = '~/.gem/credentials'
95
+ fp = File.expand_path(creds)
96
+ raise "#{creds} does not exist" unless File.exists?(fp)
97
+ raise "can't read #{creds}" unless File.readable?(fp)
98
+ end
99
+
100
+ task :publish => [:verify_publish_credentials] do
101
+ fragment = "-#{version}.gem"
102
+ pkg_dir = File.join(PROJECT_ROOT, 'pkg')
103
+ Dir.chdir(pkg_dir) {
104
+ candidates = Dir.glob "*#{fragment}"
105
+ case candidates.length
106
+ when 0
107
+ raise "could not find .gem matching #{fragment}"
108
+ when 1
109
+ sh "gem push #{candidates.first}"
110
+ else
111
+ raise "multiple candidates found matching #{fragment}"
112
+ end
113
+ }
114
+ end
115
+
116
+ task :gitpush do
117
+ # may prompt
118
+ sh "git push origin"
119
+ # this kills the automation
120
+ # consider a timeout?
121
+ end
122
+
123
+ task :release => [:build, :tag, :publish, :gitpush]
124
+ task :release_patch => [:bump_patch, :release]
125
+ task :release_minor => [:bump_minor, :release]
126
+ task :release_major => [:bump_major, :release]
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - FIX
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: FIX
47
+ email: FIX@FIX.COM
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - MANIFEST.txt
53
+ - VERSION
54
+ - README.md
55
+ - rakefile.rb
56
+ - lib/lager.rb
57
+ homepage: http://FIX.COM/
58
+ licenses:
59
+ - FIX
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.23
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: FIX
82
+ test_files: []