Install the latest version with
composer require florinmotoc/laravel-addon- set
FM_LARAVEL_ADDON_TESTS_USE_DATABASE_MOCKING=falsein your.envfile if you want to disable database mocking- how database mocking works:
- first time it will create
database/init.sqlite- viaartisan migrate && artisan db:seed - following tests will copy
init.sqliteintoa.sqlitefor each run- you can use env variable
PHPUNITDB=to change sqlite file. ex: if you run tests in parallel and each test should use its own database file
- you can use env variable
- first time it will create
- how database mocking works:
- set
FM_LARAVEL_ADDON_TESTS_USE_GUZZLE_HTTP_MOCKING=falsein your.envfile if you want to disable guzzle http mocking - set
FM_LARAVEL_ADDON_TESTS_USE_LARAVEL_HTTP_MOCKING=falsein your.envfile if you want to disable laravel http mocking - set
FM_LARAVEL_ADDON_TESTS_HTTP_MOCK_BEAUTIFY_JSON=falsein your.envfile if you want to disable json beautifier in mock files - set
FM_LARAVEL_ADDON_TESTS_HTTP_MOCK_EXCEPTION_FOR_NEW_MOCKS=falsein your.envfile if you want to not throw exceptions for new mock files- it's recommended to be left true for automated test runs (ex Jenkins) because you want to know when a http call is not mocked (test will fail)
- set
FM_LARAVEL_ADDON_TESTS_HTTP_MOCK_IGNORED_HOSTS=domain.tld,domain2.tldin your.envfile if you want to not generate http mock files for some domains. - set
FM_LARAVEL_ADDON_TESTS_HTTP_MOCK_REGENERATE=truein your.envfile if you want to ignore disk files and regenerate - set
FM_LARAVEL_ADDON_TESTS_HTTP_SKIP_MOCK_GENERATION=truein your.envfile if you want to ignore disk files and make http calls - without mock file generation
FM_LARAVEL_ADDON_STATSD_JOB_TIME_ENABLED=true
FM_LARAVEL_ADDON_STATSD_CLIENT=FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG
# example of .env variables
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_HOST=localhost
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_PORT=8125
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_LOCAL_HOSTNAME=optional-hostname
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_SOME_KEY=some_value- set
FM_LARAVEL_ADDON_STATSD_JOB_TIME_ENABLED=truein your.envfile if you want to send laravel queue job times to statsd - set
FM_LARAVEL_ADDON_STATSD_CLIENTto any of:FM_LARAVEL_ADDON_STATSD_CLIENT_NULL- nothing will be storedFM_LARAVEL_ADDON_STATSD_CLIENT_ARRAY- all will be stored into ArrayStatsdClient::$dataFM_LARAVEL_ADDON_STATSD_CLIENT_DATADOG- default datadog statsd client - udp localhost on port 8125FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG- datadog statsd client with possibility to change host,port,hostname; add custom tags
- if
FM_LARAVEL_ADDON_STATSD_CLIENTisFM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG, then these are available:FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_HOST- your statsd hostFM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_PORT- your statsd portFM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_LOCAL_HOSTNAME=changeable-hostname- if you want to send a custom hostname (not system hostname), you can set this .env variable
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_- this is a prefix.
- anything after prefix's
_will be sent to statsd with a prefixc_ - ex:
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_ABC=ABCwill send to statsdc_abc=ABC - ex:
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_ABC=abcwill send to statsdc_abc=abc - ex:
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_D=smthwill send to statsdc_d=smth - ex:
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_ENV=prodwill send to statsdc_env=prod - ex:
FM_LARAVEL_ADDON_STATSD_CLIENT_CUSTOM_DATADOG_TAGS_CUSTOM_ENV=develwill send to statsdc_env=devel
This will log in json format to laravel.log with extra information, and when used via CLI it will log in human-readable format in console output, and also in json format in laravel.log.
LOG_CHANNEL=fm_stack
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_PID=true
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_JOB_INFO=true
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_INTROSPECTION=true
# change this to one of \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_* values for more logs - 256 is very verbose!
FM_LARAVEL_ADDON_LOGS_CONSOLE_VERBOSITY=256- set
LOG_CHANNEL=fm_stackin your.envfile to activateLaravelMonologTap- also need to change laravel's
config/logging.phpfile with contents below!
- also need to change laravel's
- set
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_PID=truein your.envfile if you want to add the PID to the monolog extra array. - set
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_JOB_INFO=truein your.envfile if you want to add the laravel queue jobs id to the monolog extra array. - set
FM_LARAVEL_ADDON_LOGS_USE_EXTRA_INTROSPECTION=truein your.envfile if you want to add the\Monolog\Processor\IntrospectionProcessorto the monolog extra array. (this will add file,class,function,line) - optionally set
FM_LARAVEL_ADDON_LOGS_CONSOLE_VERBOSITY=in your.envfile to control verbosity- change this to one of
\Symfony\Component\Console\Output\OutputInterface::VERBOSITY_*values for more logs - 256 is very verbose!- VERBOSITY_QUIET = 16;
- VERBOSITY_NORMAL = 32;
- VERBOSITY_VERBOSE = 64;
- VERBOSITY_VERY_VERBOSE = 128;
- VERBOSITY_DEBUG = 256;
- change this to one of
<?php
// laravel's config/logging.php file:
return [
'default' => env('LOG_CHANNEL', 'fm_stack'),
'channels' => [
'fm_stack' => [
'driver' => 'stack',
'channels' => ['fm_console', 'fm_file'],
'ignore_exceptions' => false,
],
'fm_console' => [
'driver' => 'monolog',
'handler' => \FlorinMotoc\LaravelAddon\Logs\LaravelMonologTap\Handler\ConsoleHandler::class,
'with' => [
'verbosity' => env('FM_LARAVEL_ADDON_LOGS_CONSOLE_VERBOSITY'), // \Symfony\Component\Console\Output\OutputInterface::VERBOSITY_DEBUG
]
],
'fm_file' => [
'driver' => 'monolog',
'formatter' => Monolog\Formatter\JsonFormatter::class,
'handler' => Monolog\Handler\StreamHandler::class,
'with' => [
'stream' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'tap' => [
\FlorinMotoc\LaravelAddon\Logs\LaravelMonologTap\LaravelMonologTap::class
],
],
]
]