TraceLog.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/10/26
  6. * Time: 上午11:01
  7. */
  8. namespace app\framework\Log;
  9. class TraceLog
  10. {
  11. private $enable = false;
  12. public function __construct()
  13. {
  14. $this->enable = isset($_GET['debug_log']);
  15. }
  16. private function enable($key)
  17. {
  18. if(!$this->enable){
  19. return false;
  20. }
  21. if($_GET['debug_log'] == '*'){
  22. return true;
  23. }
  24. if(is_array(json_decode($_GET['debug_log'])) && in_array($key,json_decode($_GET['debug_log'],true))){
  25. return true;
  26. }
  27. return false;
  28. }
  29. public function coupon($key, $value)
  30. {
  31. if (!$this->enable('coupon')) {
  32. return;
  33. }
  34. file_put_contents($this->getFileName('coupon'), "{$key}:{$value}" . PHP_EOL, FILE_APPEND);
  35. }
  36. public function deduction($key, $value)
  37. {
  38. if (!$this->enable('deduction')) {
  39. return;
  40. }
  41. file_put_contents($this->getFileName('deduction'), "{$key}:{$value}" . PHP_EOL, FILE_APPEND);
  42. }
  43. public function freight($key, $value)
  44. {
  45. if (!$this->enable('freight')) {
  46. return;
  47. }
  48. file_put_contents($this->getFileName('freight'), "{$key}:{$value}" . PHP_EOL, FILE_APPEND);
  49. }
  50. private function getFileName($name)
  51. {
  52. return storage_path("logs/trace/{$name}.log");
  53. }
  54. }