parent
d112c5a911
commit
5afbf6dbca
@ -1,48 +1,59 @@
|
|||||||
# 显示和清理系统日志
|
# Time 2015-01-26 17:12:23
|
||||||
class SystemLogController < ApplicationController
|
# Author lizanle
|
||||||
|
# Description 显示和清理系统日志
|
||||||
|
class SystemLogController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
# 默认每页显示20条记录
|
# 默认每页显示20条记录
|
||||||
PER_PAGE = 20
|
PER_PAGE = 20
|
||||||
layout "base"
|
layout "base"
|
||||||
include SystemLogHelper
|
include SystemLogHelper
|
||||||
#查看所有日志
|
|
||||||
def index
|
|
||||||
@logs = SystemLog.logo_data(params[:page]||1,params[:per]||PER_PAGE,params[:search] , params[:day])
|
|
||||||
end
|
|
||||||
|
|
||||||
#清除日志
|
# Time 2015-01-26 17:12:46
|
||||||
def clear
|
# Author lizanle
|
||||||
SystemLog.clear params[:day]
|
# Description 查看所有日志
|
||||||
redirect_to :action => :index
|
def index
|
||||||
end
|
@logs = SystemLog.logo_data(params[:page]||1, params[:per]||PER_PAGE, params[:search], params[:day])
|
||||||
|
end
|
||||||
|
|
||||||
#访问分析
|
# Time 2015-01-26 14:42:38
|
||||||
def access_analysis
|
# Author lizanle
|
||||||
#解析日志,然后逆序
|
# Description 清除日志
|
||||||
@log_result = SystemLog.analysis(params[:day]).reverse[1...-1]
|
def clear
|
||||||
@access_module = Hash.new
|
SystemLog.clear params[:day]
|
||||||
#日誌可能為空
|
redirect_to :action => :index
|
||||||
if @log_result && !@log_result.empty?
|
end
|
||||||
#将数组中的模块访问统计出来放到hash中 每条记录的第四个值是Controller#action的形式
|
|
||||||
@log_result.collect! {|r| @access_module[r[3]].nil? ?
|
# Time 2015-01-26 17:24:25
|
||||||
@access_module[r[3]] = 1 : @access_module[r[3]] +=1 }
|
# Author lizanle
|
||||||
# 去掉key可能为空记录 排序,然后取逆序
|
# Description 访问分析
|
||||||
@access_module = @access_module.delete_if{|k,v| k.nil?}.sort_by{|key,val| val}.reverse
|
def access_analysis
|
||||||
else
|
#解析日志,然后逆序
|
||||||
@access_module
|
@log_result = SystemLog.analysis(params[:day]).reverse[1...-1]
|
||||||
end
|
@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
|
||||||
|
end
|
||||||
|
|
||||||
#耗时分析
|
# Time 2015-01-26 17:24:36
|
||||||
def time_analysis
|
# Author lizanle
|
||||||
#解析日志
|
# Description 耗时分析
|
||||||
@log_result = SystemLog.analysis(params[:day]).reverse[1...-1]
|
def time_analysis
|
||||||
if @log_result && !@log_result.empty?
|
#解析日志
|
||||||
#分页
|
@log_result = SystemLog.analysis(params[:day]).reverse[1...-1]
|
||||||
@log_result = Kaminari.paginate_array(@log_result).page(params[:page]||1).per(params[:per]||PER_PAGE)
|
if @log_result && !@log_result.empty?
|
||||||
else
|
#分页
|
||||||
@log_result = []
|
@log_result = Kaminari.paginate_array(@log_result).page(params[:page]||1).per(params[:per]||PER_PAGE)
|
||||||
end
|
else
|
||||||
|
@log_result = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in new issue