Guest User

Untitled

a guest
Feb 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5. * debug_log
  6. * @param {*} $data
  7. * @param {string} $d = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough"
  8. * */
  9. function debug_log($data, $type = ''){
  10.  
  11. $patterns = [
  12. "black" => "str",
  13. "red" => "str",
  14. "green" => "str",
  15. "yellow" => "str",
  16. "blue" => "str",
  17. "magenta" => "str",
  18. "cyan" => "str",
  19. "white" => "str",
  20. "gray" => "str",
  21. "bold" => "str",
  22. "dim" => "str",
  23. "italic" => "str",
  24. "underline" => "str",
  25. "inverse" => "str",
  26. "hidden" => "str",
  27. "strikethrough" => "str",
  28. ];
  29.  
  30. if (!is_string($data) && !is_numeric($data)) {
  31. $data = json_encode($data, JSON_PRETTY_PRINT);
  32. }
  33.  
  34. if ($type && isset($patterns[$type])) {
  35. $pattern = $patterns[$type];
  36. $data = str_replace('str', $data, $pattern);
  37. }
  38.  
  39. file_put_contents('php://stderr', $data);
  40. file_put_contents('php://stderr', "\n");
  41. }
Add Comment
Please, Sign In to add comment