Class: Jlog::AjaxController

Inherits:
ActionController::Metal
  • Object
show all
Includes:
ActionController::Rendering
Defined in:
app/controllers/jlog/ajax_controller.rb

Constant Summary collapse

Levels =
['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']

Instance Method Summary collapse

Instance Method Details

#appendObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/jlog/ajax_controller.rb', line 8

def append
  messages = Array(params[:message])
  messages.each do |message|
    path = request.original_fullpath
    message = message[1]
    output = JLog.formatter(path).call(:path => path, :message => message[:message])

    if Levels.include? message[:level]
      level = $1
      JLog.logger(path).send(message[:level].downcase.to_sym, output)
    else
      JLog.logger.warn('*** Attempt to log with a nonexistent level ***')
      JLog.logger.warn(output)
    end
  end

  render text: 'ok', status: :ok
end