NF_Database_Logger

Class NF_Abstracts_logger.

Defined (1)

The class is defined in the following location(s).

/includes/Database/Logger.php  
  1. final class NF_Database_Logger extends NF_Abstracts_Logger 
  2. protected $_current = array(); 
  3.  
  4. /** 
  5. * Logs with an arbitrary level. 
  6. * @param mixed $level 
  7. * @param string $message 
  8. * @param array $context 
  9. * @return null 
  10. */ 
  11. public function log( $level, $message, array $context = array() ) 
  12. $message = $this->interpolate( $message, $context ); 
  13.  
  14. // Create Log Object 
  15. $log = Ninja_Forms()->form()->object()->get(); 
  16. $log->update_setting( 'type', 'log' ) 
  17. ->update_setting( 'level', $level ) 
  18. ->update_setting( 'message', $message ); 
  19.  
  20. foreach ($context as $key => $value) { 
  21. $log->update_setting($key, maybe_serialize($value)); 
  22.  
  23. // Add to Database 
  24. $log->save(); 
  25.  
  26. // Add to Current Property Array 
  27. $this->_current[ $level ][] = $log; 
  28.  
  29. /** 
  30. * Get current logs for the request lifecycle 
  31. * @param string $level 
  32. * @return array 
  33. */ 
  34. public function get_current( $level = '' ) 
  35. return ( $level ) ? $this->_current[ $level ] : $this->_current; 
  36.  
  37. /** 
  38. * Interpolates context values into the message placeholders. 
  39. * @param $message 
  40. * @param array $context 
  41. * @return string 
  42. */ 
  43. protected function interpolate( $message, array $context = array() ) 
  44. // build a replacement array with braces around the context keys 
  45. $replace = array(); 
  46. foreach ($context as $key => $val) { 
  47.  
  48. if( is_array( $val ) ) continue; 
  49.  
  50. $replace['{' . $key . '}'] = $val; 
  51.  
  52. // interpolate replacement values into the message and return 
  53. return strtr($message, $replace);