log_file 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # LogFile
2
2
 
3
- TODO: Write a gem description
3
+ The basic instension of making this gem is to display the log file data in browser
4
+ for easy referencing and tracking the requests and application execution
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,8 +19,11 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
-
22
+ add following lines to your development.rb file
23
+ config.middleware.use LogFile::Display
24
+ that's it now restart your app server
25
+ go to http://localhost:port-no/log_file
26
+ thats it you can see it in your browser
23
27
  ## Contributing
24
28
 
25
29
  1. Fork it
@@ -1,22 +1,56 @@
1
1
  require "log_file/version"
2
2
  module LogFile
3
- # Your code goes here...
4
3
 
5
- class DevelopmentLog
6
-
7
- def show_log()
8
-
9
- myfile=File.open(Rails.root+("log/development.log"),"r")
10
- a= myfile.readline(100)
11
- myfile.close
12
- return a
4
+ class Display
5
+ def initialize(app)
6
+ @app=app
13
7
  end
14
8
 
15
- end
16
-
17
-
9
+ def call(env={})
10
+ if env["PATH_INFO"]=~/^\/log_file/
11
+ @log_name=((Rails.env=="development")?("log/development.log"):("log/production.log"))
12
+
13
+ @lines=`wc -l <"#{ @log_name }"`.to_i
14
+
15
+ if(env["QUERY_STRING"]=~/direction/ )
16
+ if(env["QUERY_STRING"]=="direction=Next")
17
+ count=@lines-env['rack.session'][:line_count]
18
+ env['rack.session'][:line_count]=@lines
19
+ env['rack.session'][:displayed_lines] += count
20
+ data=`tail -n "#{ count }" "#{ @log_name }"`
21
+ [200,{"Content-Type"=>"text/html"},[view_append(data)]]
22
+ elsif(env["QUERY_STRING"]=="direction=Previous")
23
+ count=env['rack.session'][:displayed_lines]+10+(@lines-env['rack.session'][:line_count])
24
+ env['rack.session'][:displayed_lines] += 10
25
+ data=`tail -n "#{ count }" "#{ @log_name }" | head -10`
26
+ [200,{"Content-Type"=>"text/html"},[view_append(data)]]
27
+ end
28
+ else
29
+ env['rack.session'][:line_count]=@lines
30
+ env['rack.session'][:displayed_lines]=30
31
+ data=`tail -30 "#{ @log_name }"`
32
+ [200,{"Content-Type"=>"text/html"},[view_generate(data)]]
33
+ end
34
+ else
35
+ @app.call(env)
36
+ end
37
+ end
18
38
 
39
+ def view_generate(data)
40
+ temp=file_open("../log_file/views/display.html.erb")
41
+ temp=ERB.new(temp)
42
+ return temp.result(binding)
43
+ end
19
44
 
45
+ def view_append(data)
46
+ temp=file_open("../log_file/views/append.html.erb")
47
+ temp=ERB.new(temp)
48
+ return temp.result(binding)
49
+ end
20
50
 
51
+ def file_open(name)
52
+ File.open(File.expand_path(name,__FILE__),"r").read()
53
+ end
21
54
 
55
+ end
22
56
  end
@@ -0,0 +1,6 @@
1
+ document.ready(function(){
2
+
3
+ alert("welcome");
4
+
5
+
6
+ });
@@ -0,0 +1,5 @@
1
+ body {
2
+ padding: 10px 20px;
3
+ border:#cacaca 1px solid ;
4
+ background-color:#CCFFCC;
5
+ }
@@ -1,3 +1,4 @@
1
1
  module LogFile
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
4
+
@@ -0,0 +1,5 @@
1
+ <div>
2
+ <% data.each_line do|line| %>
3
+ <p><%= line %></p><br/>
4
+ <% end %>
5
+ </div>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Log Viewer</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <style type="text/css">
8
+ body {
9
+ padding: 10px 20px;
10
+ border:#cacaca 1px solid ;
11
+ background-color:#CCFFCC;
12
+ }
13
+ </style>
14
+
15
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
16
+ <script type="text/javascript">
17
+ $(document).ready(function(){
18
+ $("#next").click(function(){
19
+ $.ajax({
20
+
21
+ type:"GET",
22
+ url:"/log_file",
23
+ data:{direction: "Next" },
24
+ success: function(data){
25
+ $("article").append(data);
26
+ }
27
+
28
+ });
29
+ });
30
+ $("#previous").click(function(){
31
+ $.ajax({
32
+ type:"GET",
33
+ url:"/log_file",
34
+ data:{direction: "Previous" },
35
+ success: function(data){
36
+ $("article").prepend(data);
37
+ }
38
+
39
+ });
40
+ });
41
+ });
42
+ </script>
43
+ <!--
44
+ <script type="text/javascript" src="/custom.js"></script>
45
+ <script type="text/css" src="/style.css"> -->
46
+ </head>
47
+ <body>
48
+ <input type="button" style="background-color:#9999FF;float:right;" id="previous" value="Previous"></input>
49
+ <article>
50
+ <% data.each_line do|line| %>
51
+ <p><%= line %></p>
52
+ <% end %>
53
+ </article>
54
+ <input type="button" style="background-color:#9999FF;float:right;" id="next" value="Next"></input>
55
+ </body>
56
+ </html>
57
+
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = LogFile::VERSION
9
9
  spec.authors = ["praveenyoungind"]
10
10
  spec.email = ["praveenyoungind@gmail.com"]
11
- spec.description = %q{this is to see log file dat}
12
- spec.summary = %q{log file data checking}
11
+ spec.description = %q{this is gem is useful to check the log file data in browser}
12
+ spec.summary = %q{this gem is useful to check log file data through browser}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ # spec.add_dependency "kaminari"
23
24
  end
25
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-14 00:00:00.000000000 Z
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: this is to see log file dat
46
+ description: this is gem is useful to check the log file data in browser
47
47
  email:
48
48
  - praveenyoungind@gmail.com
49
49
  executables: []
@@ -56,7 +56,11 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/log_file.rb
59
+ - lib/log_file/assets/custom.js
60
+ - lib/log_file/assets/style.css
59
61
  - lib/log_file/version.rb
62
+ - lib/log_file/views/append.html.erb
63
+ - lib/log_file/views/display.html.erb
60
64
  - log_file.gemspec
61
65
  homepage: ''
62
66
  licenses:
@@ -82,5 +86,5 @@ rubyforge_project:
82
86
  rubygems_version: 1.8.23
83
87
  signing_key:
84
88
  specification_version: 3
85
- summary: log file data checking
89
+ summary: this gem is useful to check log file data through browser
86
90
  test_files: []