nextcloud / lognormalizer
Parses variables and converts them to string so that they can be logged
Installs: 4 757
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 2
Open Issues: 1
pkg:composer/nextcloud/lognormalizer
Requires
- php: >=8.1
- ext-json: *
Requires (Dev)
- nextcloud/coding-standard: ^1.4
- phpunit/phpunit: ^10.5
- symfony/polyfill-php85: ^1.33
- vimeo/psalm: ^6.14
- dev-master
- v3.0.0
- v2.0.0
- v1.0.0
- dev-php/8.5
- dev-ci/install-apt-libzmq3
- dev-dependabot/github_actions/dot-github/workflows/shivammathur/setup-php-2.36.0
- dev-dependabot/github_actions/dot-github/workflows/actions/checkout-6.0.0
- dev-bugfix/noid/harden-output
- dev-bugfix/noid/apply-cs-to-tests
- dev-bugfix/9/remove-reference
This package is not auto-updated.
Last update: 2025-12-17 14:58:25 UTC
README
Log Normalizer
Parses variables and converts them to string so that they can be logged
Based on the Monolog formatter/normalizer.
How to use
Initialization in your class
use Nextcloud\LogNormalizer\Normalizer; $normalizer = new Normalizer();
The constructor supports the following optional arguments
int $maxRecursionDepth: The maximum depth at which you want to go in objects and arraysint $maxArrayItems: The maximum number of elements you want to show, when parsing an array or an objectstring $dateFormat: The format to apply to dates
Format variables before logging them
This is what your logging function could look like
/** * Converts the variables in the received log message to string before * sending everything to the real logger * * @param string $level * @param string $message * @param array $variables * * @return mixed */ public function log($level, $message, array $variables= []) { array_walk($variables, [$this->normalizer, 'format']); // Then use your current PSR-3 compatible logging system $this->logger->log($level, $message, $variables); }
And you would call it like this from another class
$myLogger->log('debug', 'Logger test {var1}, {var2}', [ 'var1' => $var1, 'var2' => $var2 ] );
Convert a single variable to a string
$normalizedVariable = $this->normalizer->format($variable);