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)
2828``` php
2929use Tartan\Log\XLog; // or register XLog Facade
3030
31+ XLog::debug('test message');
3132XLog::info('test message');
3233XLog::notice('test message');
3334XLog::warning('test message');
@@ -55,4 +56,5 @@ XLog::info('test message', $array);
5556
5657``` php
5758XLog::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)
3838
3939 // get request track ID from service container
4040 if (!isset ($ arguments [1 ][$ trackIdKey ])) {
41- $ arguments [1 ][$ trackIdKey ] = resolve ($ trackIdKey );
41+ $ arguments [1 ][$ trackIdKey ] = self :: getTrackId ($ trackIdKey );
4242 }
4343
4444 return call_user_func_array (['Illuminate\Support\Facades\Log ' , $ name ], $ arguments );
4545 }
4646
47+ /**
48+ * @param Exception $e
49+ * @param string $level
50+ *
51+ * @return mixed
52+ */
4753 public static function exception (Exception $ e , $ level = 'error ' )
4854 {
55+ $ trackIdKey = env ('XLOG_TRACK_ID_KEY ' , 'xTrackId ' );
56+
4957 $ arguments = [];
5058 $ arguments [0 ] = 'exception ' . $ e ->getMessage ();
5159 $ arguments [1 ] = [
5260 'code ' => $ e ->getCode (),
5361 'file ' => basename ($ e ->getFile ()),
5462 'line ' => $ e ->getLine (),
63+ $ trackIdKey => self ::getTrackId ($ trackIdKey )
5564 ];
5665
5766 return call_user_func_array (['XLog ' , $ level ], $ arguments );
5867 }
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+ }
5983}
You can’t perform that action at this time.
0 commit comments