Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MyApp\Core;
- use Fuel\Core as Fuel;
- use Auth as Auth;
- class LogDatabase extends Fuel\Log
- {
- /**
- * Logs a message with the Info Log Level
- *
- * @param string $msg The log message
- * @param string $method The method that logged
- * @param Exception $e The exception thrown
- * @return bool If it was successfully logged
- */
- public static function info($msg, $method, $e = null)
- {
- return static::write(Fuel\Fuel::L_INFO, $msg, $method, $e);
- }
- /**
- * Logs a message with the Debug Log Level
- *
- * @param string $msg The log message
- * @param string $method The method that logged
- * @param Exception $e The exception thrown
- * @return bool If it was successfully logged
- */
- public static function debug($msg, $method, $e = null)
- {
- return static::write(Fuel\Fuel::L_DEBUG, $msg, $method, $e);
- }
- /**
- * Logs a message with the Warning Log Level
- *
- * @param string $msg The log message
- * @param string $method The method that logged
- * @param Exception $e The exception thrown
- * @return bool If it was successfully logged
- */
- public static function warning($msg, $method, $e = null)
- {
- return static::write(Fuel\Fuel::L_WARNING, $msg, $method, $e);
- }
- /**
- * Logs a message with the Error Log Level
- *
- * @param string $msg The log message
- * @param string $method The method that logged
- * @param Exception $e The exception thrown
- * @return bool If it was successfully logged
- */
- public static function error($msg, $method, $e = null)
- {
- return static::write(Fuel\Fuel::L_ERROR, $msg, $method, $e);
- }
- /**
- * Write Log File
- *
- * Generally this function will be called using the global log_message() function
- *
- * @access public
- * @param int|string the error level
- * @param string the error message
- * @param string information about the method
- * @param Exception $e The exception thrown
- * @return bool
- */
- public static function write($level, $msg, $method, $e = null)
- {
- // Use the parent write method to determine whether or not to log.
- if (!parent::write($level, $msg, $method))
- {
- return false;
- }
- // set level text.
- $labels = array(
- 1 => 'Error',
- 2 => 'Warning',
- 3 => 'Debug',
- 4 => 'Info',
- );
- $level = $labels[$level];
- // set a method if it wasn't already set.
- if(empty($method))
- {
- $method = \Input::uri();
- }
- $log = Fuel\Log::forge();
- $user_id = Auth\Auth::instance()->get_user_id();
- $log->user_id = $user_id[1];
- $log->occurred_on = \Date::forge()->get_timestamp();
- $log->message = $msg;
- $log->type = $level;
- $log->activity = $method;
- $log->stacktrace = ($e != null) ? $e->getTraceAsString() : 'N/A';
- $log->ip_address = \Input::ip();
- $log->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement