File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ XLOG_TRACK_ID_KEY= (default xTrackId)
28
28
``` php
29
29
use Tartan\Log\XLog; // or register XLog Facade
30
30
31
+ XLog::debug('test message');
31
32
XLog::info('test message');
32
33
XLog::notice('test message');
33
34
XLog::warning('test message');
@@ -55,4 +56,5 @@ XLog::info('test message', $array);
55
56
56
57
``` php
57
58
XLog::exception($e, 'error');
58
- ```
59
+ XLog::exception($e, 'emergency');
60
+ ```
Original file line number Diff line number Diff line change @@ -38,22 +38,46 @@ public static function __callStatic($name, $arguments)
38
38
39
39
// get request track ID from service container
40
40
if (!isset ($ arguments [1 ][$ trackIdKey ])) {
41
- $ arguments [1 ][$ trackIdKey ] = resolve ($ trackIdKey );
41
+ $ arguments [1 ][$ trackIdKey ] = self :: getTrackId ($ trackIdKey );
42
42
}
43
43
44
44
return call_user_func_array (['Illuminate\Support\Facades\Log ' , $ name ], $ arguments );
45
45
}
46
46
47
+ /**
48
+ * @param Exception $e
49
+ * @param string $level
50
+ *
51
+ * @return mixed
52
+ */
47
53
public static function exception (Exception $ e , $ level = 'error ' )
48
54
{
55
+ $ trackIdKey = env ('XLOG_TRACK_ID_KEY ' , 'xTrackId ' );
56
+
49
57
$ arguments = [];
50
58
$ arguments [0 ] = 'exception ' . $ e ->getMessage ();
51
59
$ arguments [1 ] = [
52
60
'code ' => $ e ->getCode (),
53
61
'file ' => basename ($ e ->getFile ()),
54
62
'line ' => $ e ->getLine (),
63
+ $ trackIdKey => self ::getTrackId ($ trackIdKey )
55
64
];
56
65
57
66
return call_user_func_array (['XLog ' , $ level ], $ arguments );
58
67
}
68
+
69
+ /**
70
+ * @param $trackIdKey
71
+ *
72
+ * @return string
73
+ */
74
+ protected static function getTrackId ($ trackIdKey )
75
+ {
76
+ try {
77
+ $ trackId = resolve ($ trackIdKey );
78
+ } catch (Exception $ e ) {
79
+ $ trackId = '- ' ;
80
+ }
81
+ return $ trackId ;
82
+ }
59
83
}
You can’t perform that action at this time.
0 commit comments