mode === self::C_LOGGER_ECHO ) { echo $log; } else { $this->logs[] = $log; } } else { if ( $this->mode === self::C_LOGGER_ECHO ) { echo $argument; } else { $this->logs[] = $argument; } } if ( $this->mode === self::C_LOGGER_ECHO ) echo "
" . PHP_EOL; } } /** * Returns the internal log array. * The internal log array is where all log messages are stored. * * @return array */ public function getLogs() { return $this->logs; } /** * Clears the internal log array, removing all * previously stored entries. * * @return self */ public function clear() { $this->logs = array(); return $this; } /** * Selects a logging mode. * There are several options available. * * * C_LOGGER_ARRAY - log silently, stores entries in internal log array only * * C_LOGGER_ECHO - also forward log messages directly to STDOUT * * @param integer $mode mode of operation for logging object * * @return self */ public function setMode( $mode ) { if ($mode !== self::C_LOGGER_ARRAY && $mode !== self::C_LOGGER_ECHO ) { throw new RedException( 'Invalid mode selected for logger, use C_LOGGER_ARRAY or C_LOGGER_ECHO.' ); } $this->mode = $mode; return $this; } /** * Searches for all log entries in internal log array * for $needle and returns those entries. * This method will return an array containing all matches for your * search query. * * @param string $needle phrase to look for in internal log array * * @return array */ public function grep( $needle ) { $found = array(); foreach( $this->logs as $logEntry ) { if ( strpos( $logEntry, $needle ) !== FALSE ) $found[] = $logEntry; } return $found; } }