Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand logging
James Cole0bf97ccf2276
diff --git a/.env.example b/.env.exampleindex c884bcdec2..ec2b4a8762 100644--- a/.env.example+++ b/.env.example@@ -45,12 +45,6 @@ TRUSTED_PROXIES=# Default setting 'stack' will log to 'daily' and to 'stdout' at the same time.LOG_CHANNEL=stack-#-# Used when logging to papertrail:-#-PAPERTRAIL_HOST=-PAPERTRAIL_PORT=-# Log level. You can set this from least severe to most severe:# debug, info, notice, warning, error, critical, alert, emergency# If you set it to debug your logs will grow large, and fast. If you set it to emergency probably@@ -68,11 +62,21 @@ AUDIT_LOG_LEVEL=emergency## If you want, you can redirect the audit logs to another channel.-# Options are: 'papertrail', 'syslog' OR 'errorlog'+# Set 'audit_stdout', 'audit_syslog', 'audit_errorlog' to log to the system itself.+# Use audit_daily to log to a rotating file.+# Use audit_papertrail to log to papertrail.#-# If you do this, the audit logs may be mixed with normal logs (if they also use the same channel).+# If you do this, the audit logs may be mixed with normal logs because the settings for these channels+# are often the same as the settings for the normal logs.AUDIT_LOG_CHANNEL=+#+# Used when logging to papertrail:+# Also used when audit logs log to papertrail:+#+PAPERTRAIL_HOST=+PAPERTRAIL_PORT=+# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III# For other database types, please see the FAQ: https://docs.firefly-iii.org/firefly-iii/faq/self-hosted/#i-want-to-use-sqlite# If you use Docker or similar, you can set these variables from a file by appending them with _FILEdiff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.phpindex 04dc365f7d..080da2d31b 100644--- a/app/Factory/AccountFactory.php+++ b/app/Factory/AccountFactory.php@@ -218,6 +218,7 @@ class AccountFactory}// create account!$account = Account::create($databaseData);+ Log::channel('audit')->info(sprintf('Account #%d ("%s") has been created.', $account->id, $account->name));// update meta data:$data = $this->cleanMetaDataArray($account, $data);diff --git a/app/Factory/AccountMetaFactory.php b/app/Factory/AccountMetaFactory.phpindex 46f1d013b1..e92b88a6cc 100644--- a/app/Factory/AccountMetaFactory.php+++ b/app/Factory/AccountMetaFactory.php@@ -26,6 +26,7 @@ namespace FireflyIII\Factory;use FireflyIII\Models\Account;use FireflyIII\Models\AccountMeta;+use Illuminate\Support\Facades\Log;/*** Class AccountMetaFactorydiff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.phpindex e935837d69..94e6f83f64 100644--- a/app/Http/Requests/ReportFormRequest.php+++ b/app/Http/Requests/ReportFormRequest.php@@ -222,19 +222,18 @@ class ReportFormRequest extends FormRequest}if (!is_array($set)) {Log::error(sprintf('Set is not an array! "%s"', $set));+ return $collection;}- if (is_array($set)) {- foreach ($set as $tagTag) {- Log::debug(sprintf('Now searching for "%s"', $tagTag));- $tag = $repository->findByTag($tagTag);- if (null !== $tag) {- $collection->push($tag);- continue;- }- $tag = $repository->find((int)$tagTag);- if (null !== $tag) {- $collection->push($tag);- }+ foreach ($set as $tagTag) {+ Log::debug(sprintf('Now searching for "%s"', $tagTag));+ $tag = $repository->findByTag($tagTag);+ if (null !== $tag) {+ $collection->push($tag);+ continue;+ }+ $tag = $repository->find((int)$tagTag);+ if (null !== $tag) {+ $collection->push($tag);}}diff --git a/config/logging.php b/config/logging.phpindex 503f606190..57d2601851 100644--- a/config/logging.php+++ b/config/logging.php@@ -24,13 +24,28 @@ declare(strict_types=1);use FireflyIII\Support\Logging\AuditLogger;use Monolog\Handler\SyslogUdpHandler;-// to correctly redirect audit channel messages the-// options for the audit stack are set here, but can be overruled-// from an environment variable:-$auditChannels = ['audit_daily', 'audit_stdout'];-$option = envNonEmpty('AUDIT_LOG_CHANNEL', '');-if ('' !== (string)$option) {- $auditChannels = [$option];+// standard config for both log things:+$defaultChannels = ['daily', 'stdout'];+$auditChannels = ['audit_daily', 'audit_stdout'];+++// validChannels is missing 'stack' because we already check for that one.+$validChannels = ['single', 'papertrail', 'stdout', 'daily', 'syslog', 'errorlog'];+$validAuditChannels = ['audit_papertrail', 'audit_stdout', 'audit_stdout', 'audit_daily', 'audit_syslog', 'audit_errorlog'];++// which settings did the user set, if any?+$defaultLogChannel = (string)envNonEmpty('LOG_CHANNEL', 'stack');+$auditLogChannel = (string)envNonEmpty('AUDIT_LOG_CHANNEL', '');++if ('stack' === $defaultLogChannel) {+ $defaultChannels = ['daily', 'stdout'];+}+if (in_array($defaultLogChannel, $validChannels, true)) {+ $defaultChannels = [$defaultLogChannel];+}++if (in_array($auditLogChannel, $validAuditChannels, true)) {+ $auditChannels = [$auditLogChannel];}return [@@ -62,16 +77,27 @@ return [*/'channels' => [- // default channels for 'stack' and 'audit' logs are stdout and daily logs.- 'stack' => [+ /*+ * 'stack' and 'audit' are the two "generic" channels that+ * are valid destinations for logs.+ */+ 'stack' => ['driver' => 'stack',- 'channels' => ['daily', 'stdout'],+ 'channels' => $defaultChannels,],- 'audit' => [+ 'audit' => ['driver' => 'stack','channels' => $auditChannels,],- 'papertrail' => [+ /*+ * There are 6 valid destinations for the normal logs, listed below:+ */+ 'single' => [+ 'driver' => 'single',+ 'path' => storage_path('logs/laravel.log'),+ 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),+ ],+ 'papertrail' => ['driver' => 'monolog','level' => envNonEmpty('APP_LOG_LEVEL', 'info'),'handler' => SyslogUdpHandler::class,@@ -80,55 +106,65 @@ return ['port' => env('PAPERTRAIL_PORT'),],],-- // single laravel log file:- 'single' => [- 'driver' => 'single',- 'path' => storage_path('logs/laravel.log'),- 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),- ],-- // stdout, used in stack 'stack' by default:- 'stdout' => [+ 'stdout' => ['driver' => 'single','path' => 'php://stdout','level' => envNonEmpty('APP_LOG_LEVEL', 'info'),],-- // daily, used in stack 'stack' by default:- 'daily' => [+ 'daily' => ['driver' => 'daily','path' => storage_path('logs/ff3-' . PHP_SAPI . '.log'),'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),'days' => 7,],+ 'syslog' => [+ 'driver' => 'syslog',+ 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),+ ],+ 'errorlog' => [+ 'driver' => 'errorlog',+ 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),+ ],- // the audit log destinations:- 'audit_daily' => [+ /*+ * There are 5 valid destinations for the audit logs, listed below.+ * The only one missing is "single".+ */+ 'audit_papertrail' => [+ 'driver' => 'monolog',+ 'level' => envNonEmpty('AUDIT_LOG_LEVEL', 'info'),+ 'handler' => SyslogUdpHandler::class,+ 'tap' => [AuditLogger::class],+ 'handler_with' => [+ 'host' => env('PAPERTRAIL_HOST'),+ 'port' => env('PAPERTRAIL_PORT'),+ ],+ ],+ 'audit_stdout' => [+ 'driver' => 'single',+ 'path' => 'php://stdout',+ 'tap' => [AuditLogger::class],+ 'level' => envNonEmpty('AUDIT_LOG_LEVEL', 'info'),+ ],+ 'audit_daily' => ['driver' => 'daily','path' => storage_path('logs/ff3-audit.log'),'tap' => [AuditLogger::class],'level' => envNonEmpty('AUDIT_LOG_LEVEL', 'info'),'days' => 90,],- 'audit_stdout' => [- 'driver' => 'single',- 'path' => 'php://stdout',+ 'audit_syslog' => [+ 'driver' => 'syslog','tap' => [AuditLogger::class],'level' => envNonEmpty('AUDIT_LOG_LEVEL', 'info'),],-- // syslog destination- 'syslog' => [- 'driver' => 'syslog',- 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),- ],-- // errorlog destination- 'errorlog' => [+ 'audit_errorlog' => ['driver' => 'errorlog',- 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'),+ 'tap' => [AuditLogger::class],+ 'level' => envNonEmpty('AUDIT_LOG_LEVEL', 'info'),],++],];