rails-pretty-logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +22 -0
- data/app/assets/config/rails_pretty_logger_manifest.js +2 -0
- data/app/assets/javascripts/rails/pretty/logger/application.js +14 -0
- data/app/assets/javascripts/rails/pretty/logger/dashboards.js +2 -0
- data/app/assets/stylesheets/rails/pretty/logger/application.css +15 -0
- data/app/assets/stylesheets/rails/pretty/logger/dashboards.css +166 -0
- data/app/controllers/rails/pretty/logger/application_controller.rb +9 -0
- data/app/controllers/rails/pretty/logger/dashboards_controller.rb +21 -0
- data/app/helpers/rails/pretty/logger/application_helper.rb +8 -0
- data/app/helpers/rails/pretty/logger/dashboards_helper.rb +40 -0
- data/app/models/rails/pretty/logger/application_record.rb +9 -0
- data/app/views/layouts/rails/pretty/logger/application.html.erb +20 -0
- data/app/views/rails/pretty/logger/dashboards/index.html.erb +23 -0
- data/app/views/rails/pretty/logger/dashboards/logs.html.erb +66 -0
- data/config/routes.rb +8 -0
- data/lib/rails/pretty/logger.rb +156 -0
- data/lib/rails/pretty/logger/engine.rb +16 -0
- data/lib/rails/pretty/logger/version.rb +7 -0
- data/lib/tasks/rails/pretty/logger_tasks.rake +4 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 660193f3dbcb7817fc4acafa17d4bb2f12844535
|
4
|
+
data.tar.gz: 4119a9861929400d6059ae175fbcb027d3438e6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6aa0c67ff1f1b49a0ffe298ad747bd6b3a74bf536975e85a55ca65a2d3bc6d23f4ba8544a5b01c0bcec72f509222119a7cb1ab325a44a5cfe84764091b4b557f
|
7
|
+
data.tar.gz: db4a242b278a2b8a7348af8b59f6a5e52695c41a9161b55e2222601764ec5369407092880a2e23c849e57c78451fe541d0d70ef1c0448530f1be4d8bd44adc37
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Cem
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Rails::Pretty::Logger
|
2
|
+
Pretty Logger is a logging framework which can be checked from its page, and also you can also debug easily with highlight method.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
visit http://your-webpage/rails-pretty-logger/dashboards/ then choose your environment, which you want to check and also you can set date range for narrowing down your logs.
|
6
|
+
![](log_file.gif)
|
7
|
+
|
8
|
+
#### How to use debug Highlighter
|
9
|
+
|
10
|
+
```
|
11
|
+
PrettyLogger.highlight("lorem ipsum")
|
12
|
+
```
|
13
|
+
![](highlight.gif)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```
|
19
|
+
gem 'rails-pretty-logger'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
```bash
|
24
|
+
$ bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
```bash
|
29
|
+
$ gem install rails-pretty-logger
|
30
|
+
```
|
31
|
+
Mount the engine in your config/routes.rb:
|
32
|
+
|
33
|
+
```
|
34
|
+
mount Rails::Pretty::Logger::Engine => "/rails-pretty-logger"
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. [Fork][fork] the [official repository][repo].
|
40
|
+
2. [Create a topic branch.][branch]
|
41
|
+
3. Implement your feature or bug fix.
|
42
|
+
4. Add, commit, and push your changes.
|
43
|
+
5. [Submit a pull request.][pr]
|
44
|
+
|
45
|
+
## License
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
47
|
+
|
48
|
+
|
49
|
+
[repo]: https://github.com/kekik/rails-pretty-logger/tree/master
|
50
|
+
[fork]: https://help.github.com/articles/fork-a-repo/
|
51
|
+
[branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
|
52
|
+
[pr]: https://help.github.com/articles/using-pull-requests/
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Rails::Pretty::Logger'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,166 @@
|
|
1
|
+
/*
|
2
|
+
Place all the styles related to the matching controller here.
|
3
|
+
They will automatically be included in application.css.
|
4
|
+
*/
|
5
|
+
|
6
|
+
/*
|
7
|
+
Place all the styles related to the matching controller here.
|
8
|
+
They will automatically be included in application.css.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* colors:
|
12
|
+
#000000 - black
|
13
|
+
#ac0010 - red
|
14
|
+
#484848 - dark grey
|
15
|
+
#ffb62a - yellow
|
16
|
+
#dadada - grey
|
17
|
+
#f1f1f1 - light grey
|
18
|
+
#20283e - dark blue
|
19
|
+
#559FAF - light blue
|
20
|
+
#488a99 - blue
|
21
|
+
#ffffff - white
|
22
|
+
*/
|
23
|
+
body {
|
24
|
+
color: #000000;
|
25
|
+
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
|
26
|
+
font-size:16px;
|
27
|
+
padding: 0;
|
28
|
+
margin: 0;
|
29
|
+
background-color: #f1f1f1;
|
30
|
+
}
|
31
|
+
|
32
|
+
body div:first-child {
|
33
|
+
padding: 20px;
|
34
|
+
background: #ac0010;
|
35
|
+
color: #dadada;
|
36
|
+
}
|
37
|
+
|
38
|
+
body div:first-child > a {
|
39
|
+
display:inline-block;
|
40
|
+
text-decoration: none;
|
41
|
+
background-color: #ac0010;
|
42
|
+
color: #dadada;
|
43
|
+
padding: 8px;
|
44
|
+
margin: 3px;
|
45
|
+
border-radius: 5px;
|
46
|
+
border: #dadada 1px solid;
|
47
|
+
}
|
48
|
+
|
49
|
+
body div:first-child > a:hover {
|
50
|
+
background-color: #559FAF;
|
51
|
+
color: #ffffff;
|
52
|
+
border: #ffffff 1px solid;
|
53
|
+
}
|
54
|
+
|
55
|
+
a {
|
56
|
+
display: inline-block;
|
57
|
+
text-decoration: none;
|
58
|
+
background-color: #f1f1f1;
|
59
|
+
color: #484848;
|
60
|
+
padding: 8px 10px;
|
61
|
+
margin-left: 1px;
|
62
|
+
border-radius: 5px;
|
63
|
+
border: #484848 1px solid;
|
64
|
+
}
|
65
|
+
|
66
|
+
a:hover {
|
67
|
+
color:#dadada;
|
68
|
+
background-color:#484848;
|
69
|
+
}
|
70
|
+
|
71
|
+
hr {
|
72
|
+
margin: 8px 0;
|
73
|
+
border:0;
|
74
|
+
border-bottom: #dadada 1px solid;
|
75
|
+
}
|
76
|
+
|
77
|
+
.form-group {
|
78
|
+
background-color: #dadada;
|
79
|
+
padding: 5px 0;
|
80
|
+
margin: 15px 20px 30px 20px;
|
81
|
+
border-radius: 5px;
|
82
|
+
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
|
83
|
+
}
|
84
|
+
|
85
|
+
.form-group p {
|
86
|
+
color: #000000;
|
87
|
+
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
|
88
|
+
}
|
89
|
+
|
90
|
+
p {
|
91
|
+
padding: 6px 20px;
|
92
|
+
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
|
93
|
+
font-size:16px;
|
94
|
+
}
|
95
|
+
|
96
|
+
.highlight {
|
97
|
+
display: inline-block;
|
98
|
+
background-color:#ffb62a;
|
99
|
+
padding: 6px 10px;
|
100
|
+
margin-left: 20px;
|
101
|
+
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
|
102
|
+
}
|
103
|
+
|
104
|
+
input {
|
105
|
+
border-radius: 2px;
|
106
|
+
border: #484848 1px solid;
|
107
|
+
padding: 5px 10px;
|
108
|
+
margin: 3px;
|
109
|
+
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
|
110
|
+
color: #484848;
|
111
|
+
font-size: 14px;
|
112
|
+
margin-right: 20px;
|
113
|
+
}
|
114
|
+
|
115
|
+
input[type=submit]{
|
116
|
+
font-size:16px;
|
117
|
+
padding: 8px 10px;
|
118
|
+
border-radius: 3px;
|
119
|
+
background-color: #ac0010;
|
120
|
+
color: #ffffff;
|
121
|
+
border: none;
|
122
|
+
}
|
123
|
+
|
124
|
+
input[type=submit]:hover {
|
125
|
+
background-color: #20283e;
|
126
|
+
color: #dadada;
|
127
|
+
}
|
128
|
+
|
129
|
+
.dashboard {
|
130
|
+
display: block;
|
131
|
+
background: none!important;
|
132
|
+
margin-top: 100px;
|
133
|
+
margin-left: 20%;
|
134
|
+
margin-right: 20%;
|
135
|
+
margin-bottom: 100px;
|
136
|
+
text-align: center;
|
137
|
+
}
|
138
|
+
|
139
|
+
.dashboard a {
|
140
|
+
margin: 5px 10px;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
.clear_logs {
|
145
|
+
background-color: #F62817 !important ;
|
146
|
+
border: none;
|
147
|
+
color: white;
|
148
|
+
padding: 15px 32px;
|
149
|
+
text-align: center;
|
150
|
+
text-decoration: none;
|
151
|
+
display: inline-block;
|
152
|
+
font-size: 14px;
|
153
|
+
}
|
154
|
+
|
155
|
+
.dashboard_button{
|
156
|
+
padding: 15px 32px !important ;
|
157
|
+
margin-left: 30px !important ;
|
158
|
+
}
|
159
|
+
|
160
|
+
.active{
|
161
|
+
background-color: #559FAF !important ;
|
162
|
+
}
|
163
|
+
|
164
|
+
.message{
|
165
|
+
text-align: center;
|
166
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_dependency "rails/pretty/logger/application_controller"
|
2
|
+
|
3
|
+
module Rails::Pretty::Logger
|
4
|
+
class DashboardsController < ApplicationController
|
5
|
+
|
6
|
+
def logs
|
7
|
+
@log = PrettyLogger.new(params)
|
8
|
+
@log_data = @log.log_data
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
@log_file_list = PrettyLogger.get_log_file_list
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear_logs
|
16
|
+
PrettyLogger.new(params).clear_logs
|
17
|
+
redirect_to logs_dashboards_path({log_file: params[:log_file]})
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rails::Pretty::Logger
|
2
|
+
module DashboardsHelper
|
3
|
+
def check_highlight(line)
|
4
|
+
if line.include?("[HIGHLIGHT]")
|
5
|
+
return "<div class='highlight'>#{line.delete('[HIGHLIGHT]')}</div>".html_safe
|
6
|
+
end
|
7
|
+
line
|
8
|
+
end
|
9
|
+
|
10
|
+
def time_now
|
11
|
+
Time.now.strftime("%Y-%m-%d")
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_divider(params)
|
15
|
+
if params[:date_range].blank?
|
16
|
+
100
|
17
|
+
elsif params[:date_range][:divider].blank?
|
18
|
+
100
|
19
|
+
else
|
20
|
+
params[:date_range][:divider]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_file_active(name, params)
|
25
|
+
if params[:log_file] == name
|
26
|
+
"active"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_page_active(index, params)
|
31
|
+
if params[:page].to_i == index
|
32
|
+
"active"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_rails_version
|
37
|
+
Rails::VERSION::STRING[0..2].to_f < 5.2
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Rails pretty logger</title>
|
5
|
+
<% if check_rails_version %>
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<% else %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
<%= csp_meta_tag %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= stylesheet_link_tag "rails/pretty/logger/application", media: "all" %>
|
13
|
+
<%= javascript_include_tag "rails/pretty/logger/application" %>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
|
17
|
+
<%= yield %>
|
18
|
+
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% if @log_file_list.count == 0 %>
|
2
|
+
<div>
|
3
|
+
<h1 class="message">There is no log file to show</h1>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<% else %>
|
7
|
+
<div>
|
8
|
+
Choose your log file :
|
9
|
+
<% @log_file_list .each do |key, value| %>
|
10
|
+
<%= link_to(value[:file_name].capitalize,
|
11
|
+
logs_dashboards_path(log_file: value[:file_name], date_range: { start: time_now, end: time_now }),
|
12
|
+
html_options = {class: "dashboard_button",
|
13
|
+
data: { confirm: "Log file size is #{ value[:file_size] } MB. Are you sure to open this file? " }}) %>
|
14
|
+
|
15
|
+
<%= link_to("x",
|
16
|
+
clear_logs_dashboards_path(log_file: value[:file_name]),
|
17
|
+
html_options = {class: "clear_logs",
|
18
|
+
method: :post,
|
19
|
+
data: { confirm: "Are you sure to clear all logs from #{value[:file_name].capitalize}? " }}) %>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
</div>
|
23
|
+
<% end %>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
<div>
|
3
|
+
Log Files:
|
4
|
+
<% @log.file_list.each do |key, value| %>
|
5
|
+
<%= link_to(value[:file_name].capitalize,
|
6
|
+
logs_dashboards_path(log_file: value[:file_name], date_range: { start: time_now, end: time_now }),
|
7
|
+
html_options = {class: "#{is_file_active(value[:file_name], params)}",
|
8
|
+
data: { confirm: "Log file size is #{ value[:file_size] } MB. Are you sure to open this file? " }}) %>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<hr>
|
12
|
+
|
13
|
+
<% if @log_data[:error].present? %>
|
14
|
+
<p>
|
15
|
+
<%= @log_data[:error] %>
|
16
|
+
</p>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% if @log_data[:error].blank? %>
|
20
|
+
<% @log_data[:logs_count].times do |index| %>
|
21
|
+
<%= link_to(
|
22
|
+
index + 1,
|
23
|
+
logs_dashboards_path(
|
24
|
+
log_file: params[:log_file],
|
25
|
+
page: index,
|
26
|
+
date_range: { start: @log.start_date, end: @log.end_date, divider: set_divider(params) }
|
27
|
+
),
|
28
|
+
html_options = {class: "#{is_page_active(index, params)}"}
|
29
|
+
|
30
|
+
) %>
|
31
|
+
<% end %>
|
32
|
+
<% end %>
|
33
|
+
<hr>
|
34
|
+
|
35
|
+
<div class="form-group">
|
36
|
+
<%= form_for :date_range, url: logs_dashboards_path(log_file: params[:log_file]), method: :post do |f| %>
|
37
|
+
<p>
|
38
|
+
<%= label(:start, :title, "Start Date:") %>
|
39
|
+
<%= f.date_field(:start, value: @log.start_date, max: Date.today) %>
|
40
|
+
<%= label(:end, :title, "End Date:") %>
|
41
|
+
<%= f.date_field(:end, value: @log.end_date, max: Date.today) %>
|
42
|
+
<%= label(:divider, :title, "Logs per page:") %>
|
43
|
+
<%= f.number_field(:divider, value: set_divider(params)) %>
|
44
|
+
<%= f.submit "Submit" %>
|
45
|
+
</p>
|
46
|
+
<%- end%>
|
47
|
+
|
48
|
+
<% if @log_data[:logs_count] > 0 %>
|
49
|
+
<p>
|
50
|
+
<%= link_to("Clear logs",
|
51
|
+
clear_logs_dashboards_path(log_file: params[:log_file]),
|
52
|
+
html_options = {class: "clear_logs",
|
53
|
+
method: :post,
|
54
|
+
data: { confirm: "Are you sure to clear all logs? " }}) %>
|
55
|
+
</p>
|
56
|
+
<% end %>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
|
60
|
+
<hr>
|
61
|
+
|
62
|
+
<% @log_data[:paginated_logs].each do |line| %>
|
63
|
+
<p>
|
64
|
+
<%= check_highlight(line) %>
|
65
|
+
</p>
|
66
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require "rails/pretty/logger/engine"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Pretty
|
5
|
+
module Logger
|
6
|
+
|
7
|
+
class PrettyLogger
|
8
|
+
|
9
|
+
def initialize(params)
|
10
|
+
@log_file = File.join(Rails.root, 'log', "#{params[:log_file]}.log")
|
11
|
+
@filter_params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.logger
|
15
|
+
Rails.logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.highlight(log)
|
19
|
+
self.logger.tagged('HIGHLIGHT') { logger.info log }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.file_size(log_file)
|
23
|
+
File.size?("./#{log_file}").to_f / 2**20
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def self.get_log_file_list
|
28
|
+
log = {}
|
29
|
+
log_files = Dir["**/*.log"]
|
30
|
+
log_files.each_with_index do |log_file,index|
|
31
|
+
log[index] = {}
|
32
|
+
log[index][:file_name] = File.basename(log_file, ".log")
|
33
|
+
log[index][:file_size] = self.file_size(log_file).round(4)
|
34
|
+
end
|
35
|
+
return log
|
36
|
+
end
|
37
|
+
|
38
|
+
def error
|
39
|
+
@error
|
40
|
+
end
|
41
|
+
|
42
|
+
def clear_logs
|
43
|
+
open(@log_file, File::TRUNC) {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def start_date
|
47
|
+
if @filter_params[:date_range].present?
|
48
|
+
@filter_params[:date_range][:start]
|
49
|
+
else
|
50
|
+
Time.now.strftime("%Y-%m-%d")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def end_date
|
55
|
+
if @filter_params[:date_range].present?
|
56
|
+
@filter_params[:date_range][:end]
|
57
|
+
else
|
58
|
+
Time.now.strftime("%Y-%m-%d")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def file_list
|
63
|
+
PrettyLogger.get_log_file_list
|
64
|
+
end
|
65
|
+
|
66
|
+
def filter_logs_with_date(file)
|
67
|
+
arr = []
|
68
|
+
start = false
|
69
|
+
|
70
|
+
IO.foreach(file) do |line|
|
71
|
+
if get_date_from_log_line(line)
|
72
|
+
start = true
|
73
|
+
arr.push(line)
|
74
|
+
elsif start && !(line_include_date?(line))
|
75
|
+
arr.push(line)
|
76
|
+
else
|
77
|
+
start = false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
return arr
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_test_logs(file)
|
84
|
+
arr = []
|
85
|
+
IO.foreach(file) do |line|
|
86
|
+
arr.push(line)
|
87
|
+
end
|
88
|
+
return arr
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_logs_from_file(file)
|
92
|
+
if @filter_params[:log_file].include?("test")
|
93
|
+
get_test_logs(file)
|
94
|
+
else
|
95
|
+
filter_logs_with_date(file)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_date_from_log_line(line)
|
100
|
+
params = @filter_params[:date_range]
|
101
|
+
if line_include_date?(line)
|
102
|
+
date_string_index = line.index("at ")
|
103
|
+
string_date = line[date_string_index .. date_string_index + 13]
|
104
|
+
date = string_date.to_date.strftime("%Y-%m-%d")
|
105
|
+
if params.present?
|
106
|
+
date.between?(params[:start], params[:end])
|
107
|
+
else
|
108
|
+
date.between?(Time.now.strftime("%Y-%m-%d"), Time.now.strftime("%Y-%m-%d"))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def line_include_date?(line)
|
114
|
+
line.include?("Started")
|
115
|
+
end
|
116
|
+
|
117
|
+
def validate_date
|
118
|
+
params = @filter_params[:date_range]
|
119
|
+
if params.present?
|
120
|
+
if (params[:start].present? && params[:end].present?)
|
121
|
+
if (params[:start] > params[:end])
|
122
|
+
"End Date should not be less than Start Date."
|
123
|
+
end
|
124
|
+
elsif params[:start].blank? || params[:end].blank?
|
125
|
+
"Start and End Date must be given."
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def log_data
|
131
|
+
error = validate_date
|
132
|
+
divider = set_divider_value
|
133
|
+
logs = get_logs_from_file(@log_file)
|
134
|
+
logs_count = (logs.count.to_f / divider).ceil
|
135
|
+
paginated_logs = logs[ @filter_params[:page].to_i * divider ..
|
136
|
+
(@filter_params[:page].to_i * divider) + divider ]
|
137
|
+
data = {}
|
138
|
+
data[:logs_count] = logs_count
|
139
|
+
data[:paginated_logs] = paginated_logs
|
140
|
+
data[:error] = error
|
141
|
+
return data
|
142
|
+
end
|
143
|
+
|
144
|
+
def set_divider_value
|
145
|
+
if @filter_params[:date_range].blank?
|
146
|
+
100
|
147
|
+
elsif @filter_params[:date_range][:divider].blank?
|
148
|
+
100
|
149
|
+
else
|
150
|
+
@filter_params[:date_range][:divider].to_i
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rails
|
2
|
+
module Pretty
|
3
|
+
module Logger
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace Rails::Pretty::Logger
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
include Rails::Pretty::Logger
|
8
|
+
end
|
9
|
+
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-pretty-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.3.6
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.3'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.6
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.6'
|
61
|
+
description: ": Description of Rails::Pretty::Logger."
|
62
|
+
email:
|
63
|
+
- cbaykam@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- app/assets/config/rails_pretty_logger_manifest.js
|
72
|
+
- app/assets/javascripts/rails/pretty/logger/application.js
|
73
|
+
- app/assets/javascripts/rails/pretty/logger/dashboards.js
|
74
|
+
- app/assets/stylesheets/rails/pretty/logger/application.css
|
75
|
+
- app/assets/stylesheets/rails/pretty/logger/dashboards.css
|
76
|
+
- app/controllers/rails/pretty/logger/application_controller.rb
|
77
|
+
- app/controllers/rails/pretty/logger/dashboards_controller.rb
|
78
|
+
- app/helpers/rails/pretty/logger/application_helper.rb
|
79
|
+
- app/helpers/rails/pretty/logger/dashboards_helper.rb
|
80
|
+
- app/models/rails/pretty/logger/application_record.rb
|
81
|
+
- app/views/layouts/rails/pretty/logger/application.html.erb
|
82
|
+
- app/views/rails/pretty/logger/dashboards/index.html.erb
|
83
|
+
- app/views/rails/pretty/logger/dashboards/logs.html.erb
|
84
|
+
- config/routes.rb
|
85
|
+
- lib/rails/pretty/logger.rb
|
86
|
+
- lib/rails/pretty/logger/engine.rb
|
87
|
+
- lib/rails/pretty/logger/version.rb
|
88
|
+
- lib/tasks/rails/pretty/logger_tasks.rake
|
89
|
+
homepage: https://github.com/kekik/rails-pretty-logger
|
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: '0'
|
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.6.11
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: ": Summary of Rails::Pretty::Logger."
|
113
|
+
test_files: []
|