PHPackages                             gbhorwood/gander - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gbhorwood/gander

ActiveLibrary

gbhorwood/gander
================

An inspector for restful Laravel apis

1.2.2(2y ago)1258MITHTMLPHP ^7.4|^8.0

Since Aug 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gbhorwood/Gander)[ Packagist](https://packagist.org/packages/gbhorwood/gander)[ RSS](/packages/gbhorwood-gander/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (9)Used By (0)

Gander
======

[](#gander)

[![License](https://camo.githubusercontent.com/0f5d65c150cbdbab845d2e9097d6dd81b1f056a941f44f233f5ecef3ecaad283/687474703a2f2f706f7365722e707567782e6f72672f6762686f72776f6f642f67616e6465722f6c6963656e7365)](https://packagist.org/packages/gbhorwood/gander)[![Version](https://camo.githubusercontent.com/36b40cfc546375475cd3699f7b8e84a09fb99bae3ad23b63822a0390a8600e04/687474703a2f2f706f7365722e707567782e6f72672f6762686f72776f6f642f67616e6465722f76657273696f6e)](https://packagist.org/packages/gbhorwood/gander)[![License](https://camo.githubusercontent.com/761014762f7b1ed27d18f7c2cf6836b08e012a4b0fc142d295cb513854327813/687474703a2f2f706f7365722e707567782e6f72672f6762686f72776f6f642f67616e6465722f726571756972652f706870)](https://packagist.org/packages/gbhorwood/gander)

Gander is an inspector and logger for restful Laravel apis. Gander allows logging of request/responses, as well as optional logging of events in your source code. Gander reports are viewed with an exported javascript client which can be hosted anywhere. Gander was developed as an internal-use tool for [fruitbat studios](https://fruitbat.studio)/cloverhitch technologies/kludgetastic implementations.

Install
-------

[](#install)

Gander is installed via composer:

```
composer require gbhorwood/gander
php artisan vendor:publish --provider="Gbhorwood\Gander\GanderServiceProvider" --tag="config"
php artisan migrate
```

Installing Gander will add a middleware to your api middleware group, create tables to store Gander events and access keys, expose the `gbhorwood:gander` artisan command, and write the gander config file to your `config` directory.

Quickstart
----------

[](#quickstart)

The shortest path to getting Gander working after install is to create a client in your api's root directory with:

```
php artisan gbhorwood:gander --create-client
```

Then load the html file in a browser, either by hosting it on any http server or by opening it as a file in your browser.

Configuration
-------------

[](#configuration)

Gander has four configuration values that can be added to your `.env` file:

```
GANDER_ENABLE=true
GANDER_ENABLE_STACK_TIMERS=true
GANDER_PASSWORD_KEYS=password,repeat_password,password_repeat,again_password,password_again
GANDER_HEADERS_TO_LOG=x-authorization,user-agent

```

**`GANDER_ENABLE`**: Setting `GANDER_ENABLE` to `false` will turn off Gander completely. Gander is on by default.

**`GANDER_ENABLE_STACK_TIMERS`**: Setting `GANDER_ENABLE_STACK_TIMERS` to false will disable the elapsed time value on all log writes you have added to your code using `Gander::track()`. Stack timers are on by default.

**`GANDER_PASSWORD_KEYS`**: Gander attempts to sanitize password data from request bodies before writing to the database by removing a value if its key matches one of the keys listed in `GANDER_PASSWORD_KEYS`. If you accept password data keyed with something not in the `GANDER_PASSWORD_KEYS` list, add it.

**`GANDER_HEADERS_TO_LOG`**: Gander can log a subset of request headers. Header names to log are listed here as a comma-separated list. If no headers are listed, only `X-Authorization` and `User-Agent` are stored.

### A short note on timer configuration

[](#a-short-note-on-timer-configuration)

Timing of the elapsed seconds of a request is done internally using php's [`hrtime()`](https://www.php.net/manual/en/function.hrtime.php) for performance reasons. However, `hrtime()` is unreliable when called across function calls. For this reason, calculating the elapsed time when writing log calls made by `Gander::track()` is done using [`microtime()`](https://www.php.net/manual/en/function.microtime.php). However, `microtime()` may be slow in some virtual environments who's [vDSO](https://man7.org/linux/man-pages/man7/vdso.7.html) does not allow access to the clock. For this reason, Gander allows you to turn off the use of `microtime()` by setting `GANDER_ENABLE_STACK_TIMERS` to `false`.

Writing logs
------------

[](#writing-logs)

Gander logs requests and responses automatically. In addition, you can also add log writes for a given request in your endpoint's source code with:

```
\Gbhorwood\Gander\Gander::track()
```

This method takes a message as an optional string argument.

The track method can be called anywhere in your executed code, for example:

```
