Module: WebSandboxConsole::Common

Included in:
WebSandboxConsole
Defined in:
lib/web_sandbox_console/common.rb

Instance Method Summary collapse

Instance Method Details

#current_uuid(uuid = nil) ⇒ Object



4
5
6
# File 'lib/web_sandbox_console/common.rb', line 4

def current_uuid(uuid=nil)
  @uuid ||= uuid
end

#fetch_loggerObject

获取 logger



32
33
34
# File 'lib/web_sandbox_console/common.rb', line 32

def fetch_logger
  @logger ||= Logger.new(log_path, 'daily')
end

#log_p(msg_or_exce, is_general_text = false) ⇒ Object

uuid 方便取出日志



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/web_sandbox_console/common.rb', line 17

def log_p(msg_or_exce, is_general_text = false)
  uuid   = current_uuid
  logger = fetch_logger
  
  if msg_or_exce.respond_to?(:message) # 异常
    logger.info "#{uuid}:" + msg_or_exce.message 
    logger.info "#{uuid}:" + msg_or_exce.backtrace.join("|||")
  elsif is_general_text  # 普通文本
    logger.info "#{uuid}:" + msg_or_exce.inspect
  else                   # 返回值
    logger.info "#{uuid}: => " + msg_or_exce.inspect
  end
end

#log_pathObject



36
37
38
# File 'lib/web_sandbox_console/common.rb', line 36

def log_path
  "#{Rails.root}/#{self.console_log_path || "log/web_sandbox_console.log"}"
end

#logger_sqlObject

logger sql语句



9
10
11
12
13
14
# File 'lib/web_sandbox_console/common.rb', line 9

def logger_sql
  logger = fetch_logger
  logger.level = 0
  logger.formatter = proc {|severity, time, progname, msg|  "#{current_uuid}: #{msg}\n"}
  ActiveRecord::Base.logger = logger
end