diff --git a/.env b/.env index 2ca3d0e..7209c02 100644 --- a/.env +++ b/.env @@ -68,3 +68,8 @@ INVITE_FROM_ADDRESS=no-reply@example.org # USE ABSOLUTE PATHS for better predictability WEBDAV_TMP_DIR='/tmp' WEBDAV_PUBLIC_DIR='/webdav' + +# Logging path +# By default, it will log in the standard Symfony directory: var/log/prod.log (for production) +# You can use /dev/null here if you want to discard logs entirely +LOG_FILE_PATH="%kernel.logs_dir%/%kernel.environment%.log" diff --git a/README.md b/README.md index 1d696b4..8fce978 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,14 @@ WEBDAV_TMP_DIR='/tmp' WEBDAV_PUBLIC_DIR='/webdav' ``` +g. The log file path + +You can use an absolute file path here, and you can use Symfony's `%kernel.logs_dir%` and `%kernel.environment%` placeholders if needed (as in the default value). Setting it to `/dev/null` will disable logging altogether. + +``` +LOG_FILE_PATH="%kernel.logs_dir%/%kernel.environment%.log" +``` + ### Specific environment variables for IMAP and LDAP authentication methods In case you use the `IMAP` auth type, you must specify the auth url (_the "mailbox" url_) in `IMAP_AUTH_URL`. See https://www.php.net/manual/en/function.imap-open.php for more details. diff --git a/config/packages/dev/easy_log_handler.yaml b/config/packages/dev/easy_log_handler.yaml deleted file mode 100644 index 27bfc60..0000000 --- a/config/packages/dev/easy_log_handler.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - EasyCorp\EasyLog\EasyLogHandler: - public: false - arguments: ['%kernel.logs_dir%/%kernel.environment%.log'] - -#// FIXME: How to add this configuration automatically without messing up with the monolog configuration? -#monolog: -# handlers: -# buffered: -# type: buffer -# handler: easylog -# channels: ['!event'] -# level: debug -# easylog: -# type: service -# id: EasyCorp\EasyLog\EasyLogHandler diff --git a/config/packages/prod/monolog.yaml b/config/packages/prod/monolog.yaml index bfe69c0..4df854e 100644 --- a/config/packages/prod/monolog.yaml +++ b/config/packages/prod/monolog.yaml @@ -8,7 +8,7 @@ monolog: buffer_size: 50 # How many messages should be saved? Prevent memory leaks nested: type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" + path: "%env(resolve:LOG_FILE_PATH)%" level: debug console: type: console diff --git a/config/services.yaml b/config/services.yaml index ce7544b..ab946fc 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -55,4 +55,8 @@ services: App\Security\LoginFormAuthenticator: arguments: $adminLogin: "%env(ADMIN_LOGIN)%" - $adminPassword: "%env(ADMIN_PASSWORD)%" \ No newline at end of file + $adminPassword: "%env(ADMIN_PASSWORD)%" + + App\Logging\Monolog\PasswordFilterProcessor: + tags: + - { name: monolog.processor } diff --git a/src/Logging/Monolog/PasswordFilterProcessor.php b/src/Logging/Monolog/PasswordFilterProcessor.php new file mode 100644 index 0000000..0d003e6 --- /dev/null +++ b/src/Logging/Monolog/PasswordFilterProcessor.php @@ -0,0 +1,28 @@ + $item) { + if (self::PASSWORD_KEY === strtolower($key) || ('args' === $key && $shouldRedactArgs)) { + $record[$key] = self::REDACTED; + } elseif (is_array($item)) { + $record[$key] = $this($item); + } + } + + return $record; + } +} diff --git a/src/Services/IMAPAuth.php b/src/Services/IMAPAuth.php index 372b518..17e184e 100644 --- a/src/Services/IMAPAuth.php +++ b/src/Services/IMAPAuth.php @@ -62,7 +62,12 @@ final class IMAPAuth extends IMAP $this->utils->createPasswordlessUserWithDefaultObjects($username, $username, $username); $em = $this->doctrine->getManager(); - $em->flush(); + + try { + $em->flush(); + } catch (\Exception $e) { + error_log('IMAP Error (flush): '.$e->getMessage()); + } } } diff --git a/src/Services/LDAPAuth.php b/src/Services/LDAPAuth.php index 776686b..b7bea87 100644 --- a/src/Services/LDAPAuth.php +++ b/src/Services/LDAPAuth.php @@ -91,7 +91,7 @@ final class LDAPAuth extends AbstractBasic try { $ldap = ldap_connect($this->LDAPAuthUrl); } catch (\ErrorException $e) { - error_log($e->getMessage()); + error_log('LDAP Error (ldap_connect): '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); } if (!$ldap || !ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3)) { @@ -124,8 +124,7 @@ final class LDAPAuth extends AbstractBasic $success = true; } } catch (\ErrorException $e) { - error_log($e->getMessage()); - error_log('LDAP Error: '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); + error_log('LDAP Error (ldap_bind): '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); } if ($success && $this->autoCreate) { @@ -161,7 +160,12 @@ final class LDAPAuth extends AbstractBasic $this->utils->createPasswordlessUserWithDefaultObjects($username, $displayName, $email); $em = $this->doctrine->getManager(); - $em->flush(); + + try { + $em->flush(); + } catch (\Exception $e) { + error_log('LDAP Error (flush): '.$e->getMessage()); + } } }