Skip to content

Commit 9678047

Browse files
committed
follow convention for bufflog errors
1 parent dc77486 commit 9678047

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

example.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use Buffer\BuffLog\Bufflog;
66

77
// putenv("LOG_VERBOSITY=WARNING");
8-
BuffLog::debug("I am a debug string");
8+
BuffLog::debug("I am a debug string", 2, 2);
9+
BuffLog::debug(["I am a"]);
10+
BuffLog::debug("I am a", "test");
11+
BuffLog::debug("I am a debug string", 2, 2);
912
BuffLog::debug("I am a debug with context", ["my key" => " my value"]);
1013

1114
BuffLog::info("I am an info");
@@ -14,7 +17,7 @@
1417
BuffLog::warning("I am a warning");
1518
BuffLog::warning("I am a warning", ["duration" => "40ms"]);
1619

17-
BuffLog::error("I am an error");
20+
BuffLog::error(2);
1821
BuffLog::error("I am an error", ["mean" => "70"]);
1922

2023
BuffLog::critical("I am criticals information with a typo and you shouldn't see me!");

src/BuffLog/BuffLog.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ protected static function configureInstance()
4545
} else {
4646
// local envs don't need tracing
4747
if (getenv("ENVIRONMENT") !== "local") {
48-
error_log("Tip #1: Can't find \DDTrace\GlobalTracer class. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier.");
49-
error_log("Tip #2: If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?");
48+
echo json_encode([
49+
"message" => "Can't find \DDTrace\GlobalTracer class. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier. If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?",
50+
"level" => 300,
51+
"level_name" => "WARNING",
52+
"context" => ["bufflog_error" => "no_tracer"]
53+
]);
5054
}
5155
}
5256

@@ -117,10 +121,10 @@ public static function __callStatic($methodName, $args)
117121
}
118122
}
119123
} else {
120-
error_log("BuffLog::$methodName() is not supported yet. Add it to the BuffLog whitelist to allow it");
124+
self::getLogger()->warning("BuffLog::$methodName() is not supported yet. Add it to the BuffLog whitelist to allow it", ["bufflog_error" => "method_not_supported"]);
121125
}
122126
} else {
123-
error_log("BuffLog::$methodName() method does not exist");
127+
self::getLogger()->warning("BuffLog::$methodName() method does not exist", ["bufflog_error" => "method_not_exist"]);
124128
}
125129

126130
return false;
@@ -129,17 +133,17 @@ public static function __callStatic($methodName, $args)
129133
private static function checkLogParametersType($args)
130134
{
131135
if (count($args) > 2) {
132-
error_log("BuffLog: Too many parameters");
136+
self::getLogger()->warning("BuffLog: Malformed logs: Too many parameters", ["bufflog_error" => "incorrect_parameters", "args" => $args]);
133137
return false;
134138
}
135139

136140
if (isset($args[0]) && !is_string($args[0])) {
137-
error_log("BuffLog: First parameter must be a string");
141+
self::getLogger()->warning("BuffLog: Malformed logs: First parameter must be a string", ["args" => $args, "bufflog_error" => "incorrect_parameters"]);
138142
return false;
139143
}
140144

141145
if (isset($args[1]) && !is_array($args[1])) {
142-
error_log("BuffLog: Second parameter must be an array");
146+
self::getLogger()->warning("BuffLog: Malformed logs: Second parameter must be an array", ["args" => $args, "bufflog_error" => "incorrect_parameters"]);
143147
return false;
144148
}
145149

0 commit comments

Comments
 (0)