sr_log 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d88574c8ed5f2a62a8ffd9699f1690ac546d0b7d
4
- data.tar.gz: a34ca57bab1681341b5d002622db7e76aafb2e5b
3
+ metadata.gz: 1466e960b28cf99511139bf5f9c2305fd8b3b804
4
+ data.tar.gz: aefdd526b4ada8a77cf2e089601086b133a8fbe5
5
5
  SHA512:
6
- metadata.gz: 462317a7da81b57ba1e7b5daee8c2e6e8a738761192f435f7e10ca3e6e83ce3b8d3863d09205f1fd997a6e42584a4be607709d83e558a077554aaf046c5c4f3f
7
- data.tar.gz: 77e94d81f3d69dffb4394767f3c800ebc9e597e7a30ef83de099f1625746b6228631bbf9b9aac8ed70655287a93cdbdd3037c15fad1609e65f54124d65861616
6
+ metadata.gz: 80c1f636473ce50dab0fab67b9a85c9a6a273e2da049f799532ff23b2828fb83a20f0a2e4858b66d716c483dbc8a82a97091f62a5d7114a1e90d34c779ed72dc
7
+ data.tar.gz: 20599ffb7a856e227dbc372e2c26e4e443fe42ec8294f8d89374522c8c13f150ae953f1228dbbbe6064a9468d23dbd232e2edc1d140631f0bc1d80366cc32afd
data/lib/sr_log/log.rb CHANGED
@@ -1,3 +1,8 @@
1
+ require 'singleton'
2
+ require 'logger'
3
+ require 'date'
4
+ require 'fileutils'
5
+
1
6
  module SrLog
2
7
  class Log
3
8
  include Singleton
@@ -10,16 +15,20 @@ module SrLog
10
15
 
11
16
  def log log_key, msg, opts = {}
12
17
  @logfiles ||= {}
13
- log_month = Date.current.strftime '%Y.%m'
18
+ log_month = Date.today.strftime '%Y.%m'
14
19
 
15
20
  unless @logfiles.has_key?(log_key) && @logfiles[log_key][:log_month] == log_month
16
21
  filename = "#{log_month}_#{log_key.to_s}.log"
17
22
 
18
- if opts.has_key?(:dir)
19
- log_path = File.join opts[:dir], filename
23
+ log_path = if opts.has_key?(:dir)
20
24
  FileUtils.mkdir_p(opts[:dir]) unless File.directory?(opts[:dir])
25
+ File.join opts[:dir], filename
26
+ elsif defined?(Rails)
27
+ Rails.root.join 'log', filename
21
28
  else
22
- log_path = Rails.root.join 'log', filename # TODO: remove undocumented dependency of Rails
29
+ folder_path = File.expand_path File.join('.', 'log')
30
+ FileUtils.mkdir(folder_path) unless File.directory?(folder_path)
31
+ File.join folder_path, filename
23
32
  end
24
33
 
25
34
  @logfiles[log_key] = {log: SrLogger.new(log_path), log_month: log_month}
@@ -1,3 +1,3 @@
1
1
  module SrLog
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sr_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber