diff --git a/example-project/README.md b/example-project/README.md index 0bf3714..c899539 100644 --- a/example-project/README.md +++ b/example-project/README.md @@ -16,10 +16,10 @@ This command will install all dependencies from `composer.json` file and lock th To run the example application, simply run the following command: ```bash -php index.php +php index.php ``` -*Don't forget to replace `` with your actual source token which you can find by going to logtail.com -> sources -> edit.* +*Don't forget to replace `` with your actual source token, and `` with the URL of your ingesting endpoint (eg. `https://in.logs.betterstack.com`), which you can find by going to telemetry.betterstack.com -> sources -> edit.* You should see the following output: ```text @@ -51,10 +51,14 @@ Now it’s time to create a `Logger` instance and push a `LogtailHandler` handle ```php $logger = new Logger("logtail-source"); -$logger->pushHandler(LogtailHandlerBuilder::withSourceToken("")->build()); +$logger->pushHandler( + LogtailHandlerBuilder::withSourceToken("") + ->withEndpoint("") + ->build() +); ``` -Don’t forget to change `` to your actual token which you can find in the *Basic information* section when clicking on *Edit* on your select source. +*Don't forget to replace `` with your actual source token, and `` with the URL of your ingesting endpoint (eg. `https://in.logs.betterstack.com`), which you can find by going to telemetry.betterstack.com -> sources -> edit.* Also, make sure that the `Logger` instance is accessible from all the branches of your application in which you wish to use the logger. diff --git a/example-project/index.php b/example-project/index.php index 6c235d8..66312f2 100644 --- a/example-project/index.php +++ b/example-project/index.php @@ -10,14 +10,15 @@ use Logtail\Monolog\LogtailHandlerBuilder; # Check for arguments -if($argc != 2){ - # No argument was provided - echo "No source token was provided. Please, run the script as followed:\n php index.php \n"; +if($argc != 3){ + # None or one argument provided + echo "Not enough arguments. Please, run the script as followed:\n php index.php \n e.g. php index.php MySourceToken123 https://s12345.my-logs.bettestackdata.com\n"; exit; } $logger = new Logger("logtail-source"); $handler = LogtailHandlerBuilder::withSourceToken($argv[1]) + ->withEndpoint($argv[2]) ->withBufferLimit(100) ->withFlushIntervalMilliseconds(500) ->withExceptionThrowing(true) @@ -25,7 +26,7 @@ $logger->pushHandler($handler); # Below you can see available methods that can be used to send logs to logtail. -# Each method corresponds to Monologs log level. +# Each method corresponds to Monolog's log level. # You can also add additional context information in form of an array to any logging method and pass it as the # second argument of the select method (as shown in the warn() method ). @@ -33,7 +34,7 @@ $logger->debug("Logtail logger is ready!"); # Send information about interesting events using info() method -$logger->info("An interesting event occured!"); +$logger->info("An interesting event occurred!"); # Send information about normal but significant events using notice() method $logger->notice("Sending notice"); @@ -54,10 +55,10 @@ $logger->critical("Oh no! An critical event occurred!"); # Send an alert message about events for which action must be taken immediately using alert() method -$logger->alert("Something terrible happend! Imidiate action is required!"); +$logger->alert("Something terrible happened! Immediate action is required!"); # Send an emergency message about events that forced the application to crash using emergency() method -$logger->emergency("Application just crashed! Imidiate action is required!"); +$logger->emergency("Application just crashed! Immediate action is required!"); echo "All done, you can check your logs in the control panel. \n"; diff --git a/src/Monolog/LogtailHandlerBuilder.php b/src/Monolog/LogtailHandlerBuilder.php index 7acf894..b197816 100644 --- a/src/Monolog/LogtailHandlerBuilder.php +++ b/src/Monolog/LogtailHandlerBuilder.php @@ -46,6 +46,20 @@ public static function withSourceToken(string $sourceToken): self return new self($sourceToken); } + /** + * Sets the endpoint URL to send logs to. + * + * @param string $endpoint + * @return self Always returns new immutable instance + */ + public function withEndpoint(string $endpoint): self + { + $clone = clone $this; + $clone->endpoint = $endpoint; + + return $clone; + } + /** * Sets the minimum logging level at which this handler will be triggered. *