Skip to content

Commit 721b73d

Browse files
Updated to latest log package, introduced 'WP_LOGGER_FORMAT'.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
1 parent 2cffedd commit 721b73d

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

GlobalLogger.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Jitesoft\Wordpress\Plugins\Logger;
33

4+
use Jitesoft\Log\JsonLogger;
45
use Jitesoft\Log\MultiLogger;
56
use Jitesoft\Log\StdLogger;
67
use Psr\Log\LoggerInterface;
@@ -11,7 +12,6 @@
1112
* Currently uses the STDLogger only, which logs to stdout and stderr.
1213
*/
1314
class GlobalLogger {
14-
1515
/**
1616
* Set the log level to use.
1717
* Automatically done on plugin initialization.
@@ -30,8 +30,24 @@ public static function setLogLevel(string $level): void {
3030
public static function logger(): LoggerInterface {
3131
static $logger = null;
3232
if (!$logger) {
33+
34+
$format = getenv('WP_LOGGER_FORMAT');
35+
if (!$format) {
36+
$format = 'stdout';
37+
}
38+
39+
$outLogger = null;
40+
if ($format === 'stdout') {
41+
$outLogger = new StdLogger(
42+
StdLogger::DEFAULT_FORMAT,
43+
"Y-m-d H:i:s.v"
44+
);
45+
} else if ($format = 'json') {
46+
$outLogger = new JsonLogger();
47+
}
48+
3349
$logger = new MultiLogger([
34-
new StdLogger(StdLogger::DEFAULT_FORMAT, "Y-m-d H:i:s.v"),
50+
$outLogger,
3551
]);
3652
}
3753
return $logger;

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
}
1313
],
1414
"require": {
15-
"composer/installers": "^1.0",
15+
"composer/installers": "^1.11",
1616
"ext-json": "*",
17-
"jitesoft/loggers": ">=2.2.1",
17+
"jitesoft/loggers": ">=2.3.0",
1818
"php": ">=7.4.2"
1919
},
2020
"require-dev": {

composer.lock

Lines changed: 20 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-logger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Description: An actual logger for WordPress.
55
Plugin URI: https://github.com/jitesoft/wp-logger
66
GitHub Plugin URI: https://github.com/jitesoft/wp-logger
7-
Version: 1.0.0
7+
Version: 1.2.0
88
Author: Johannes Tegnér
99
Author URI: https://jitesoft.com
1010
License: MIT License
@@ -17,7 +17,7 @@
1717
if (defined('WP_ENV')) {
1818
return WP_ENV;
1919
}
20-
if (getenv('WP_ENV', true)) {
20+
if (getenv('WP_ENV')) {
2121
return getenv('WP_ENV');
2222
}
2323

0 commit comments

Comments
 (0)