system_log 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in system_log.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 huolg
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # SystemLog
2
+
3
+ View the system log of the gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'system_log'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install system_log
18
+
19
+ ## Usage
20
+
21
+ set config/routes.rb
22
+
23
+ #The development environment,load log/development.log
24
+ if Rails.env == "development"
25
+ mount SystemLog::Engine, :at => "/system_log"
26
+ end
27
+
28
+ call on http:localhost.com:3000/system_log
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+ begin
9
+ require 'rdoc/task'
10
+ rescue LoadError
11
+ require 'rdoc/rdoc'
12
+ require 'rake/rdoctask'
13
+ RDoc::Task = Rake::RDocTask
14
+ end
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SystemLog'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ load 'rails/tasks/engine.rake'
24
+ Bundler::GemHelper.install_tasks
data/app/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ # 显示和清理系统日志
2
+ module SystemLog
3
+ class SystemLogController < ActionController::Base
4
+ # 默认每页显示20条记录
5
+ PER_PAGE = 20
6
+ layout "system_log/application"
7
+ include SystemLog::SystemLogHelper
8
+ def index
9
+ @logs = SystemLog.logo_data(params[:page]||1,params[:per]||PER_PAGE,params[:search] )
10
+ end
11
+
12
+ def clear
13
+ SystemLog.clear
14
+ redirect_to :action => :index
15
+ end
16
+ end
17
+ end
Binary file
Binary file
@@ -0,0 +1,49 @@
1
+ module SystemLog
2
+ module SystemLogHelper
3
+ class SystemLog
4
+ class << self
5
+ # 分页(支持多关键字查询)
6
+ def logo_data(page,per,search)
7
+ logs = find_all_logs
8
+ # 根据search参数来决定是否需要查询
9
+ keywords = search
10
+ if keywords && !keywords.strip.blank?
11
+ # 把keywords转化成正则表达式数组
12
+ keywords = keywords.strip.split(/\s+/).collect! {|w| Regexp.new(w, 'i')}
13
+ # 一条记录应该匹配每个关键字
14
+ logs = logs.find_all do |log|
15
+ keywords.all? { |r| log =~ r }
16
+ end
17
+ logs = Kaminari.paginate_array(logs).page(page).per(per).collect! {|log| parse(log)}
18
+ logs.collect! do |log|
19
+ keywords.each { |r| log.gsub!(r, '<span class="search_results">\0</span>')}
20
+ log
21
+ end
22
+ else
23
+ logs = Kaminari.paginate_array(logs).page(page).per(per).collect! {|log| parse(log)}
24
+ end
25
+ logs
26
+ end
27
+ def clear
28
+ File.open(logfile_path, 'w') do |f|
29
+ f.print ''
30
+ end
31
+ end
32
+ private
33
+ def find_all_logs
34
+ File.open(logfile_path) do |f|
35
+ f.read.split("\nProcessing ").reverse[1..-1]
36
+ end
37
+ end
38
+ # 日志文件的路径,一般在Rails.root/log下,根据环境配置
39
+ # 依次记录到product.log development.log test.log中
40
+ def logfile_path
41
+ File.join(Rails.root, "log", "#{ENV['RAILS_ENV']}.log")
42
+ end
43
+ def parse(log)
44
+ ERB::Util.html_escape(log.gsub(/\e\[[\d;m]+/, '')).gsub("\n", "<br/>")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
Binary file
Binary file
@@ -0,0 +1,54 @@
1
+ <%#
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+ %>
5
+
6
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7
+ <html xmlns="http://www.w3.org/1999/xhtml">
8
+ <head>
9
+ <title>System Log</title>
10
+ <style type="text/css">
11
+ /*body {*/
12
+ /*font-size:90%;*/
13
+ /*}*/
14
+ body {
15
+ color: #333333;
16
+ font-family: lucida grande, Lucida Sans Unicode, Arial, Helvetica, sans-serif;
17
+ font-size: 12px;
18
+ line-height: 20px;
19
+ }
20
+
21
+ .search_results {
22
+ color: red;
23
+ }
24
+ /*=======分页样式========*/
25
+ .pagination ul li a, .pagination ul li span{
26
+ background-color: #FFFFFF;
27
+ border-color: #DDDDDD;
28
+ border-image: none;
29
+ border-style: solid;
30
+ border-width: 1px 1px 1px 1px;
31
+ float: left;
32
+ line-height: 20px;
33
+ padding: 4px 12px;
34
+ text-decoration: none;
35
+ }
36
+ .pagination ul a {
37
+ color: #9B9B9B;
38
+ }
39
+ .pagination ul li a:hover, .pagination ul li a:focus, .pagination ul .active a, .pagination ul .active span{
40
+ background-color: #ffc02f;
41
+ border: 1px solid #ffc02f;
42
+ }
43
+ .pagination ul li{
44
+ float: left;
45
+ margin-right: 3px;
46
+ list-style: none outside none;
47
+ }
48
+ </style>
49
+ </head>
50
+
51
+ <body onload="document.getElementById('search').focus();">
52
+ <%= yield %>
53
+ </body>
54
+ </html>
Binary file
@@ -0,0 +1,24 @@
1
+ <h1>System Log</h1>
2
+ <a href="http://www.huolg.com/gems/system_log" title="huolg">huolg gem tool</a><br/>
3
+ <div id='tool'>
4
+ <form action="/system_log" style="float:right" >
5
+ <input type="text" name="search" size="36" maxlength="100" />
6
+ <input type="submit" value="搜索" id="search"/>
7
+ </form>
8
+
9
+ <div id='tool-bar'>
10
+ <%=link_to '所有日志', :action=>:index %> |
11
+ <%=link_to '清空日志', {:action=>:clear}, {:confirm => '确认清除所有日志?'} %> |
12
+ <%=link_to_function '刷新', 'window.location.reload();' %>
13
+ </div>
14
+ </div>
15
+ <div>&nbsp;&nbsp;</div>
16
+ <%= paginate @logs %><br/>
17
+
18
+ <% @logs.each do |log| %>
19
+ <% unless log.blank? %>
20
+ <p><%= raw log %></p><hr/>
21
+ <% end %>
22
+ <%end %>
23
+
24
+ <%= paginate @logs %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ SystemLog::Engine.routes.draw do
2
+ get "system_log/index"
3
+ get 'system_log/clear'
4
+ root :to => 'system_log#index'
5
+ end
data/lib/.DS_Store ADDED
Binary file
data/lib/system_log.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rails'
2
+ require "system_log/version"
3
+ require "system_log/engine"
4
+ module SystemLog
5
+ end
Binary file
@@ -0,0 +1,5 @@
1
+ module SystemLog
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SystemLog
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SystemLog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ file.reference.system_log-lib=/Users/guo/work/app/system_log/lib
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
4
+ </project-private>
File without changes
@@ -0,0 +1,5 @@
1
+ file.reference.system_log-lib=lib
2
+ main.file=
3
+ platform.active=Ruby
4
+ source.encoding=UTF-8
5
+ src.dir=${file.reference.system_log-lib}
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://www.netbeans.org/ns/project/1">
3
+ <type>org.netbeans.modules.ruby.rubyproject</type>
4
+ <configuration>
5
+ <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
6
+ <name>system_log</name>
7
+ <source-roots>
8
+ <root id="src.dir"/>
9
+ </source-roots>
10
+ <test-roots/>
11
+ </data>
12
+ </configuration>
13
+ </project>
data/script/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/system_log/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'system_log/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "system_log"
8
+ spec.version = SystemLog::VERSION
9
+ spec.authors = ["huolg"]
10
+ spec.email = ["1244002@qq.com"]
11
+ spec.description = %q{system log show in view}
12
+ spec.summary = %q{system log show in view}
13
+ spec.homepage = "http://www.huolg.com/gems/system_log"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ # spec.files = [
18
+ # ".gitignore",
19
+ # "Gemfile",
20
+ # "LICENSE.txt",
21
+ # "README.md",
22
+ # "Rakefile",
23
+ # "app/controllers/system_log_controller.rb",
24
+ # "app/views/layouts/system_log.rhtml",
25
+ # "app/views/system_log/index.rhtml",
26
+ # "config/routes.rb",
27
+ # "lib/system_log.rb",
28
+ # "lib/system_log/version.rb",
29
+ # "system_log.gemspec",
30
+ # "test/system_log_test.rb"
31
+ # ]
32
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.3"
37
+ spec.add_development_dependency "rake"
38
+ spec.add_development_dependency "kaminari", "~> 0.14.1"
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class SystemLogTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: system_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - huolg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: kaminari
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.14.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.1
62
+ description: system log show in view
63
+ email:
64
+ - 1244002@qq.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .DS_Store
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - app/.DS_Store
76
+ - app/controllers/.DS_Store
77
+ - app/controllers/system_log/.DS_Store
78
+ - app/controllers/system_log/system_log_controller.rb
79
+ - app/helpers/.DS_Store
80
+ - app/helpers/system_log/.DS_Store
81
+ - app/helpers/system_log/system_log_helper.rb
82
+ - app/views/.DS_Store
83
+ - app/views/layouts/.DS_Store
84
+ - app/views/layouts/system_log/.DS_Store
85
+ - app/views/layouts/system_log/application.html.erb
86
+ - app/views/system_log/.DS_Store
87
+ - app/views/system_log/system_log/.DS_Store
88
+ - app/views/system_log/system_log/index.html.erb
89
+ - config/routes.rb
90
+ - lib/.DS_Store
91
+ - lib/system_log.rb
92
+ - lib/system_log/.DS_Store
93
+ - lib/system_log/engine.rb
94
+ - lib/system_log/version.rb
95
+ - nbproject/private/private.properties
96
+ - nbproject/private/private.xml
97
+ - nbproject/private/rake-d.txt
98
+ - nbproject/project.properties
99
+ - nbproject/project.xml
100
+ - script/rails
101
+ - system_log.gemspec
102
+ - test/system_log_test.rb
103
+ homepage: http://www.huolg.com/gems/system_log
104
+ licenses:
105
+ - MIT
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.23
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: system log show in view
128
+ test_files:
129
+ - test/system_log_test.rb