Class: Taskr::Models::LogEntry
- Inherits:
-
Base
- Object
- Base
- Taskr::Models::LogEntry
- Defined in:
- lib/taskr/models.rb
Defined Under Namespace
Classes: ActionLogger
Class Method Summary collapse
- .log(level, action_or_task, data) ⇒ Object
-
.logger_for_action(action) ⇒ Object
Produces a Logger-like class that will create log entries for the given TaskAction.
Class Method Details
.log(level, action_or_task, data) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/taskr/models.rb', line 241 def log(level, action_or_task, data) level = level.upcase if action_or_task.kind_of? TaskAction action = action_or_task task = action.task elsif action_or_task.kind_of? Task action = nil task = action_or_task elsif action_or_task.kind_of? Integer action = TaskAction.find(action_or_task) task = action.task elsif action_or_task.kind_of? Taskr::Actions::Base action = action_or_task.task_action task = action.task else raise ArgumentError, "#{action_or_task.inspect} is not a valid Task or TaskAction!" end threshold = Taskr::Conf[:task_log][:level].upcase if Taskr::Conf[:task_log] && Taskr::Conf[:task_log][:level] if threshold.blank? || ['DEBUG', 'INFO', 'WARN', 'ERROR'].index(threshold) <= ['DEBUG', 'INFO', 'WARN', 'ERROR'].index(level) LogEntry.create( :level => level, :timestamp => Time.now, :task => task, :task_action => action, :data => data ) end end |
.logger_for_action(action) ⇒ Object
Produces a Logger-like class that will create log entries for the given TaskAction. The returned object exploses behaviour much like a standard Ruby Logger, so that it can be used in place of a Logger when necessary.
276 277 278 |
# File 'lib/taskr/models.rb', line 276 def logger_for_action(action) ActionLogger.new(action) end |