I could never get the hang of logging to an area on the current page.
Also, there are cases where I want to keep track of logged information.
Fortunately, there''s a surprisingly simple alternative: logging to the
server. Below is my first stab using prototype.js (of course) and
Rails.
Michael
Logger = {
loggingUrl: ''/myapp/admin/log'',
debug: false,
log: function(msg, level) {
if (!loggingUrl) {
return;
}
try {
new Ajax.Request(Logger.loggingUrl, {
parameters: ''msg='' + encodeURIComponent(msg) +
''&level='' + encodeURIComponent(level),
method: ''post'',
asynchronous: true
});
} catch (e) {
if (Logger.debug) {
alert("Logging error\nMessage: " + msg +
"\nError: " + Object.inspect(e));
}
}
},
debug: function(msg) {
Logger.log(msg, ''debug'');
},
error: function(msg) {
Logger.log(msg, ''error'');
},
warn: function(msg) {
Logger.log(msg, ''warn'');
}
}
class Admin::LogController < ActionController::Base
def log
severity = LEVELS.index(params[:level].to_s.upcase) || Logger::DEBUG
logger.log(severity, params[:msg])
render :nothing => true
end
private
LEVELS = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN )
end
--
Michael Schuerig You can twist perceptions
mailto:michael@schuerig.de Reality won''t budge
http://www.schuerig.de/michael/ --Rush, Show Don''t Tell