Skip to content

Make sendPacket a protected function#21

Open
kenziedeschepper wants to merge 1 commit intoitspire:masterfrom
kenziedeschepper:sendpacket-overridable
Open

Make sendPacket a protected function#21
kenziedeschepper wants to merge 1 commit intoitspire:masterfrom
kenziedeschepper:sendpacket-overridable

Conversation

@kenziedeschepper
Copy link
Copy Markdown

Make sendPacket a protected function to allow overrides in classes extending this handler.

Make sendPacket a protected function to allow overrides in classes extending this handler.
@rrajkomar
Copy link
Copy Markdown
Contributor

Hi,
While the change is simple enough, may I ask what it is you want to achieve that requires changing the method to protected ?
It may be useful for other users and warrant a bigger change in the library codebase that just the method signature.
Thanks.

@kenziedeschepper
Copy link
Copy Markdown
Author

kenziedeschepper commented Aug 21, 2023

I'm writing an specific extension for Drupal cms. Where I would like to use the symfony process component (Symfony\Component\Process\Process) to handle the api request for sending the log to Loki async. It's based on an existing Drupal module: https://git.drupalcode.org/project/monolog_loki/-/blob/1.x/src/Logger/Handler/LokiHandler.php
The change I would like to make is the following:

protected function sendPacket(array $packet): void {
    $this->connection = FALSE;
    $payload = json_encode($packet, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

    $url = sprintf('%s/loki/api/v1/push', $this->entrypoint);
    $env_vars = [
      'LOKI_URL' => $url,
      'LOKI_AUTH' => implode(':', $this->basicAuth),
      'PAYLOAD' => $payload,
      'CONTENT_LENGTH' => strlen($payload),
    ];

    $process = Process::fromShellCommandline('curl -u "$LOKI_AUTH" -H "Content-Type: application/json" -H "Content-Length: $CONTENT_LENGTH" -d "$PAYLOAD" -X POST $LOKI_URL', NULL, $env_vars);
    $process->start();
  }

@rrajkomar
Copy link
Copy Markdown
Contributor

Ok.
Is there any specific reason why you don't wan't to use the provided version ?
Maybe we could find a workaround for the issue that prompted this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants