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 +4 -4
- data/lib/sr_log/log.rb +13 -4
- data/lib/sr_log/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1466e960b28cf99511139bf5f9c2305fd8b3b804
|
|
4
|
+
data.tar.gz: aefdd526b4ada8a77cf2e089601086b133a8fbe5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
|
-
|
|
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}
|
data/lib/sr_log/version.rb
CHANGED