From 5afbf6dbca66eb015bb098c256cdf84f8cbca661 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 27 Jan 2015 14:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/system_log_controller.rb | 95 +++++++++++++----------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/app/controllers/system_log_controller.rb b/app/controllers/system_log_controller.rb index eb62140f9..274cb18a9 100644 --- a/app/controllers/system_log_controller.rb +++ b/app/controllers/system_log_controller.rb @@ -1,48 +1,59 @@ -# 显示和清理系统日志 - class SystemLogController < ApplicationController +# Time 2015-01-26 17:12:23 +# Author lizanle +# Description 显示和清理系统日志 +class SystemLogController < ApplicationController - before_filter :require_admin - # 默认每页显示20条记录 - PER_PAGE = 20 - layout "base" - include SystemLogHelper - #查看所有日志 - def index - @logs = SystemLog.logo_data(params[:page]||1,params[:per]||PER_PAGE,params[:search] , params[:day]) - end + before_filter :require_admin + # 默认每页显示20条记录 + PER_PAGE = 20 + layout "base" + include SystemLogHelper - #清除日志 - def clear - SystemLog.clear params[:day] - redirect_to :action => :index - end + # Time 2015-01-26 17:12:46 + # Author lizanle + # Description 查看所有日志 + def index + @logs = SystemLog.logo_data(params[:page]||1, params[:per]||PER_PAGE, params[:search], params[:day]) + 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 + # Time 2015-01-26 14:42:38 + # Author lizanle + # Description 清除日志 + def clear + SystemLog.clear params[:day] + redirect_to :action => :index + 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 + # Time 2015-01-26 17:24:25 + # Author lizanle + # Description 访问分析 + 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 + + # Time 2015-01-26 17:24:36 + # Author lizanle + # Description 耗时分析 + 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