-
Notifications
You must be signed in to change notification settings - Fork 1
"Type safety" #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
"Type safety" #21
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,12 @@ protected static function configureInstance() | |
} else { | ||
// local envs don't need tracing | ||
if (getenv("ENVIRONMENT") !== "local") { | ||
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."); | ||
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?"); | ||
echo json_encode([ | ||
"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?", | ||
"level" => 300, | ||
"level_name" => "WARNING", | ||
"context" => ["bufflog_error" => "no_tracer"] | ||
]); | ||
Comment on lines
+48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the logger isn't ready yet, we have to do this manually |
||
} | ||
} | ||
|
||
|
@@ -110,15 +114,40 @@ public static function __callStatic($methodName, $args) | |
if (in_array($methodName, array_merge(self::$logOutputMethods, self::$extraAllowedMethods))) { | ||
|
||
if (in_array($methodName, self::$logOutputMethods)) { | ||
// Where the magic happen. We "proxy" functions name with arguments to the Monolog instance | ||
return call_user_func_array(array(self::getLogger(), $methodName), $args); | ||
|
||
if (self::checkLogParametersType($args)) { | ||
// Where the magic happen. We "proxy" functions name with arguments to the Monolog instance | ||
return call_user_func_array(array(self::getLogger(), $methodName), $args); | ||
} | ||
} | ||
} else { | ||
error_log("BuffLog::$methodName() is not supported yet. Add it to the BuffLog whitelist to allow it"); | ||
self::getLogger()->warning("BuffLog::$methodName() is not supported yet. Add it to the BuffLog whitelist to allow it", ["bufflog_error" => "method_not_supported"]); | ||
} | ||
} else { | ||
error_log("BuffLog::$methodName() method does not exist"); | ||
self::getLogger()->warning("BuffLog::$methodName() method does not exist", ["bufflog_error" => "method_not_exist"]); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static function checkLogParametersType($args) | ||
{ | ||
if (count($args) > 2) { | ||
self::getLogger()->warning("BuffLog: Malformed logs: Too many parameters", ["bufflog_error" => "incorrect_parameters", "args" => $args]); | ||
return false; | ||
} | ||
|
||
if (isset($args[0]) && !is_string($args[0])) { | ||
self::getLogger()->warning("BuffLog: Malformed logs: First parameter must be a string", ["args" => $args, "bufflog_error" => "incorrect_parameters"]); | ||
return false; | ||
} | ||
|
||
if (isset($args[1]) && !is_array($args[1])) { | ||
self::getLogger()->warning("BuffLog: Malformed logs: Second parameter must be an array", ["args" => $args, "bufflog_error" => "incorrect_parameters"]); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.