From 061e4599c3f4e7d5e662ba54509defb45fda8a4a Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 22 Jan 2015 16:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=8C=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E4=BA=86=E8=AE=B8=E5=A4=9A=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/system_log_controller.rb | 44 +++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/app/controllers/system_log_controller.rb b/app/controllers/system_log_controller.rb index 9e3d208b0..92eaca0e3 100644 --- a/app/controllers/system_log_controller.rb +++ b/app/controllers/system_log_controller.rb @@ -1,17 +1,51 @@ # 显示和清理系统日志 class SystemLogController < ApplicationController - # 默认每页显示20条记录 - before_filter :require_login ,:only =>:index + + before_filter :require_login before_filter :require_admin ,:only =>:clear + # 默认每页显示20条记录 PER_PAGE = 20 layout "base" include SystemLogHelper + #查看所有日志 def index - @logs = SystemLog.logo_data(params[:page]||1,params[:per]||PER_PAGE,params[:search] ) + @logs = SystemLog.logo_data(params[:page]||1,params[:per]||PER_PAGE,params[:search] , params[:day]) + @logs + #@access_module = params[:access_module] unless params[:access_module].nil? end - def clear - SystemLog.clear + #清除日志 + def clear day + SystemLog.clear day redirect_to :action => :index + end + + #访问分析 + def access_analysis + #解析日志,然后逆序 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + @access_module = Hash.new + #如果日誌為空 + if @log_result && !@log_result.empty? + #将数组中的模块访问统计出来放到hash中 每条记录的第四个值是Controller#action的形式 + @log_result.collect! {|r| @access_module[r[3]].nil? ? + @access_module[r[3]] = 1 : @access_module[r[3]] +=1 } + # 去掉key可能为空记录 排序,然后取逆序 + @access_module = @access_module.delete_if{|k,v| k.nil?}.sort_by{|key,val| val}.reverse + else + @access_module end + end + + #耗时分析 + def time_analysis + #解析日志 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + if @log_result && !@log_result.empty? + #分页 + @log_result = Kaminari.paginate_array(@log_result).page(params[:page]||1).per(params[:per]||PER_PAGE) + else + @log_result = [] + end + end end