Log cURL Debug Message

@param string $message
@param \DateTime $messageTimestamp
@throws \RuntimeException
976414
protected function logCurlMessage($message, \DateTime $messageTimestamp)
    {
        if (!$this->debugLogFilePath) {
            throw new \RuntimeException('Debug log file path not defined.');
        }
        $logMessage = '[' . $messageTimestamp->format('Y-m-d H:i:s') . "] ----------------------------------------------------------\n" . $message . "\n\n";
        $logHandle = fopen($this->debugLogFilePath, 'a+');
        fwrite($logHandle, $logMessage);
        fclose($logHandle);
    }
1200545
public function recordThat(Message $event): void
    {
        if (! \array_key_exists($event->messageName(), $this->eventApplyMap)) {
            throw new \RuntimeException('Wrong event recording detected. Unknown event passed to GenericAggregateRoot: ' . $event->messageName());
        }

        $this->version += 1;

        $event = $event->withAddedMetadata('_aggregate_id', $this->aggregateId());
        $event = $event->withAddedMetadata('_aggregate_version', $this->version);
        $this->recordedEvents[] = $event;

        $this->apply($event);
    }
154695
public function push(Message $message)
    {
        if (empty($this->params)) {
            throw new \RuntimeException('Please set up this client using setUp() method before pushing messages.');
        }

        $tokens = $message->getTokens();
        if (empty($tokens)) {
            throw new \RuntimeException('No device token set. Please add at least 1 token using Message::addToken() before trying to push the message.');
        }

        $payload = $message->getPayloadAsJson();

        $headers = array(
            'Authorization: key='.$this->params['api_access_key'],
            'Content-Type: application/json',
        );

        $this->logger->info('Sending GcmMessage to Google Cloud Messaging server', array(
            'payload' => $payload,
        ));

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->params['endpoint']);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_exec($ch);
        curl_close($ch);
    }
974604
public function logMessage(Message $message): void
    {
        if (in_array($message->getLevel(), $this->config['log'])) {
            // If script is running for very long time (e.g. CRON), then date might change if time passes midnight.
            // In that case, log will continue to write messages to new file.

            $fpFile = $this->getFileName();
            if ($fpFile !== $this->fpFile) {
                //date has changed? or we need to init?
                if ($this->fp) {
                    // close pointer to old file
                    @fclose($this->fp);
                }

                if ($this->config['path'] === null) {
                    $path = Application::getStoragePath('log' . DS . $fpFile);
                } else {
                    $path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
                }

                $this->fpFile = $fpFile;

                if (!($this->fp = @fopen($path, 'a'))) {
                    // file failed to open, maybe directory doesn't exists?
                    $dir = dirname($path);
                    if (!is_dir($dir)) {
                        Directory::mkdir($dir, $this->mode);
                    }

                    if (!($this->fp = @fopen($path, 'a'))) {
                        // now the directory should exists, so try to open file again
                        throw new Exception('Can not write to log file on path=' . $path);
                    }
                }
            }

            if (!$this->fp || $this->fp === null) {
                if ($this->config['path'] === null) {
                    $path = Application::getStoragePath('log' . DS . $fpFile);
                } else {
                    $path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
                }

                throw new Exception("Can not write to log file path={$path}");
            }

            if ($this->getMessageFunction !== null) {
                $line = call_user_func($this->getMessageFunction, $message);
            } else {
                $time = $message->getTime()->format('y-m-d H:i:s.v');
                $level = strtoupper($message->getLevel());
                $space = str_repeat(' ', 10 - strlen($level));
                $who = $message->getWho() ?? Log::getWho();
                $line = "{$time} {$level}{$space}{$who}\t{$message->getMessage()}\n";
            }

            if (!@fwrite($this->fp, $line)) { // actually write it in file
                throw new Exception('Unable to write to log file');
            }
        }
    }
365654
public function log($message)
    {
        if ($this->enabled) {
            $entry = $this->formatMessage($message);
            $fp = fopen($this->file, "a");
            fwrite($fp, $entry . PHP_EOL);
            fclose($fp);
        }
    }
126283
protected function doWrite($message, $newline, $stream = null) {
        if (null === $stream) {
            $stream = $this->stdout;
        }
        if (false === @fwrite($stream, $message . ($newline ? PHP_EOL : ''))) {
            throw new \RuntimeException('Unable to write output.');
        }

        fflush($stream);
    }
846087
public static function log($message, $args = null)
    {
        if (getenv('DEBUG') || getenv('OPENCART_INSTALLER_DEBUG')) {
            if ($args) {
                if (!is_array($args)) {
                    $args = array($args);
                }
                $message = vsprintf($message, $args);
            }
            echo 'OpencartInstaller: ' . $message . PHP_EOL;
        }
    }
686002
public function debug_handler(&$smtp, $message)
    {
        // catch AUTH commands and set anonymization flag for subsequent sends
        if (preg_match('/^Send: AUTH ([A-Z]+)/', $message, $m)) {
            $this->anonymize_log = $m[1] == 'LOGIN' ? 2 : 1;
        }
        // anonymize this log entry
        else if ($this->anonymize_log > 0 && strpos($message, 'Send:') === 0 && --$this->anonymize_log == 0) {
            $message = sprintf('Send: ****** [%d]', strlen($message) - 8);
        }

        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $diff    = $len - self::DEBUG_LINE_LENGTH;
            $message = substr($message, 0, self::DEBUG_LINE_LENGTH)
                . "... [truncated $diff bytes]";
        }

        rcube::write_log('smtp', preg_replace('/\r\n$/', '', $message));
    }
671527
public function debug($message)
    {
        $config = ConfigManager::getInstance()->getConfigHashmap();
        // Disable debug in live mode.
        if (array_key_exists('mode', $config) && $config['mode'] != 'live') {
            $this->logger->debug($message);
        }
    }
727077
public function log($message, $type = PHP_COMPONENT_MESSAGE_INFO, $internal = false) {
		$message = '[' . date('H:i:s', time()) . ($internal ? '] <core> ' : '] <app> ') . "$message\n";
		switch($this->logging_mode) {
			case PHP_COMPONENT_LOG_FILE:
				if(is_null($this->log_file)) {
					$this->log_file = @ fopen($this->log_filename, 'a');
					@ ftruncate($this->log_file, 0);
					@ flock($this->log_file, LOCK_EX);
				}
				@ fputs($this->log_file, $message);
			break;
			case PHP_COMPONENT_LOG_SYSLOG:
				// TODO
			break;
			case PHP_COMPONENT_LOG_CONSOLE:
				if(strtolower(php_uname('s')) == 'linux') {
					switch($type) {
						case PHP_COMPONENT_MESSAGE_INFO:
							echo "\033[22;37m$message\033[0m";
						break;
						case PHP_COMPONENT_MESSAGE_WARNING:
							echo "\033[01;33m$message\033[0m";
						break;
						case PHP_COMPONENT_MESSAGE_ERROR:
							echo "\033[22;31m$message\033[0m";
						break;
					}
				} else {
					echo $message;
				}
			break;
		}
	}
495190
private static function debugStart($message)
    {
        // SWATDB_DEBUG is legacy, use SwatDB::setDebug() instead
        if (defined('SWATDB_DEBUG') || self::$debug) {
            $trace = debug_backtrace();

            // get first trace line that is not in the SwatDB package
            foreach ($trace as $entry) {
                if (
                    !array_key_exists('class', $entry) ||
                    strncmp($entry['class'], 'SwatDB', 6) !== 0
                ) {
                    break;
                }
            }

            $class = array_key_exists('class', $entry) ? $entry['class'] : null;

            $function = array_key_exists('function', $entry)
                ? $entry['function']
                : null;

            ob_start();
            printf(
                "<strong>%s%s%s()</strong><br />\n",
                $class === null ? '' : $class,
                array_key_exists('type', $entry) ? $entry['type'] : '',
                $function === null ? '' : $function
            );

            echo $message;
            $debug_message = ob_get_clean();

            $debug_info = array();
            $debug_info['message'] = $debug_message;
            $debug_info['time'] = microtime(true) * 1000;
            $debug_info['depth'] = self::$debug_wrapper_depth;
            $debug_info['count'] = self::$query_count;
            self::$debug_info[] = $debug_info;

            self::$debug_wrapper_depth++;
        }
    }
614788
private function logMessage(Message $message)
    {
        $logMessage = \sprintf(
            '%s %s (%.3Fs)',
            $message->getRequest()->getMethod(),
            (string) $message->getRequest()->getUri(),
            $message->getDuration()
        );

        // This is a "simple" log, for general purpose
        $this->logger->log(
            $message->getLogLevel(),
            $logMessage
        );

        // This is a debug log, with all message details, useful for debugging
        $this->logger->debug($logMessage, $message->jsonSerialize());
    }
854792
protected function debug($message, $args = array()) {
    if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
        /** @noinspection HtmlUnknownTag */
        $this->output->writeln('<fg=green>'.sprintf($message, $args));
        }
    }
16983
public function debug( $message, $group = false ) {
		static $start_time = null;
		if ( null === $start_time ) {
			$start_time = microtime( true );
		}
		$debug = $this->get_runner()->config['debug'];
		if ( ! $debug ) {
			return;
		}
		if ( true !== $debug && $group !== $debug ) {
			return;
		}
		$time   = round( microtime( true ) - ( defined( 'WP_CLI_START_MICROTIME' ) ? WP_CLI_START_MICROTIME : $start_time ), 3 );
		$prefix = 'Debug';
		if ( $group && true === $debug ) {
			$prefix = 'Debug (' . $group . ')';
		}
		$this->_line( "$message ({$time}s)", $prefix, '%B', STDERR );
	}
626251
public function logEvent(EventMessage $message): void
    {
        $name = $message->payloadType()->toString();

        $this->logger->info(
            sprintf('Event dispatched {%s}', $name),
            ['message' => $message->toString()]
        );
    }
1238533
public function log($message)
    {
        if ($this->progress) {
            $this->progress->setMessage($message);
            $this->logs[] = $message;
        } else {
            $this->output->writeLn($message);
        }
    }
978380
public function debug($message = "%s seconds")
    {
        $this->logger->debug(sprintf($message, $this->currentProfile->getDuration()));
    }