|
| 1 | +<?php |
| 2 | +namespace Onramplab\LaravelLogEnhancement\Concerns; |
| 3 | + |
| 4 | +use Illuminate\Support\Facades\Log; |
| 5 | + |
| 6 | +trait LogWithClassPath { |
| 7 | + public function debug(string $message, array $context = []) |
| 8 | + { |
| 9 | + $this->log('debug', $message, $context); |
| 10 | + } |
| 11 | + |
| 12 | + public function info(string $message, array $context = []) |
| 13 | + { |
| 14 | + $this->log('info', $message, $context); |
| 15 | + } |
| 16 | + |
| 17 | + public function notice(string $message, array $context = []) |
| 18 | + { |
| 19 | + $this->log('notice', $message, $context); |
| 20 | + } |
| 21 | + |
| 22 | + public function warning(string $message, array $context = []) |
| 23 | + { |
| 24 | + $this->log('warning', $message, $context); |
| 25 | + } |
| 26 | + |
| 27 | + public function error(string $message, array $context = []) |
| 28 | + { |
| 29 | + $this->log('error', $message, $context); |
| 30 | + } |
| 31 | + |
| 32 | + public function critical(string $message, array $context = []) |
| 33 | + { |
| 34 | + $this->log('critical', $message, $context); |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + public function alert(string $message, array $context = []) |
| 39 | + { |
| 40 | + $this->log('alert', $message, $context); |
| 41 | + } |
| 42 | + |
| 43 | + public function emergency(string $message, array $context = []) |
| 44 | + { |
| 45 | + $this->log('emergency', $message, $context); |
| 46 | + } |
| 47 | + |
| 48 | + protected function log(string $logLevel, string $message, array $context = []) |
| 49 | + { |
| 50 | + $className = get_class($this); |
| 51 | + $context = array_merge($context, [ |
| 52 | + 'class_path' => $className, |
| 53 | + ]); |
| 54 | + |
| 55 | + Log::log($logLevel, $message, $context); |
| 56 | + } |
| 57 | +} |
0 commit comments