Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sendPacket a protected function #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kenziedeschepper
Copy link

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
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
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
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