rails-pretty-logger 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23827aaf96db38b3eb70627797a5289d4c32a80a
4
- data.tar.gz: 5cababcc32c82eeaa43b2d8c92018782ee80c135
3
+ metadata.gz: ec5bfe4987b4c810ca8bdd90b8722914ea57c0e7
4
+ data.tar.gz: 86603f1a83fea878766fbfe55a2aa41411b6bef5
5
5
  SHA512:
6
- metadata.gz: 9daf92873de7bd2145b2d04cdc7b429784cfb9895948a425e1b742f8a3f7b332eb6007869167b4615309f9354ad4bcf6be0f4e60cd42e68ff284c9d2b9e667a7
7
- data.tar.gz: cd4fbee9be448304722a04d3f30dcb79b40404c2c9ef5ec9716412c941b775e8dcfcd46e95ef9f28e9b1b3074dd56e2190176088ec940c8965e318efd3618d9a
6
+ metadata.gz: fe8e0a1846597944e9f35628d29ae3ce55fe09ebc7ee9cc29797c0f07b2f538fe11a7048c53e60c109b1ab405d2b8636dd8b0333623d829283d279a1d31eae70
7
+ data.tar.gz: 436178bd2a9eb9b40369833be13ec39171468b7360772a183d2610e4d07ff97d1f163844255b04033ad508a1c2318864e933a442d38637599e05bedbbc0facf4
data/README.md CHANGED
@@ -28,6 +28,15 @@ config.logger = logger_file
28
28
  ```
29
29
  ![](hour.gif)
30
30
 
31
+ #### Split your old logs by hourly
32
+
33
+ If you want split your old log files by hourly you can use this rake task below at terminal
34
+
35
+ argument takes what will be new files names start with, and with the second one will take the full path of your log file which will be splitted
36
+
37
+ for bash usage ```rake app:split_log["new_log_file_name","/path/to/your/log.file"]```
38
+ for zch usage ```noglob rake app:split_log["new_log_file_name","/path/to/your/log.file"]```
39
+
31
40
  ## Installation
32
41
  Add this line to your application's Gemfile:
33
42
 
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Pretty
3
3
  module Logger
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,33 @@
1
- # desc "Explaining what the task does"
2
- # task :rails_pretty_logger do
3
- # # Task goes here
4
- # end
1
+ desc "Split log with hourly"
2
+ task :split_log, [:log_name, :log_path] do |t, arg|
3
+
4
+ start = false
5
+ new_path = nil
6
+ file_path = nil
7
+
8
+ def get_date(line)
9
+ if line.include?("Started")
10
+ date_index = line.index("at ")
11
+ date = line[date_index .. date_index + 18]
12
+ date.to_datetime
13
+ end
14
+ end
15
+
16
+ IO.foreach(arg[:log_path]) do |line|
17
+ date = get_date(line) rescue nil
18
+ if date
19
+ start = true
20
+ new_path = File.join(Rails.root, 'log', 'hourly', date.strftime('%Y'), date.strftime('%m'), date.strftime('%d'))
21
+ FileUtils.mkdir_p new_path unless File.directory?(new_path)
22
+ file_path = "#{new_path}/#{arg[:log_name]}.log.#{date.strftime('%Y%m%d_%H00')}"
23
+ File.open(file_path, 'a') do |file|
24
+ file << line
25
+ end
26
+ elsif start
27
+ File.open(file_path, 'a') do |file|
28
+ file << line
29
+ end
30
+ end
31
+ end
32
+ puts "It's done"
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pretty-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cem
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-02 00:00:00.000000000 Z
12
+ date: 2019-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails