Skip to content

Commit 6b1632e

Browse files
committed
changed fetch method of xTrackId
1 parent a3c8860 commit 6b1632e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ XLOG_TRACK_ID_KEY= (default xTrackId)
2828
```php
2929
use Tartan\Log\XLog; // or register XLog Facade
3030

31+
XLog::debug('test message');
3132
XLog::info('test message');
3233
XLog::notice('test message');
3334
XLog::warning('test message');
@@ -55,4 +56,5 @@ XLog::info('test message', $array);
5556

5657
```php
5758
XLog::exception($e, 'error');
58-
```
59+
XLog::exception($e, 'emergency');
60+
```

src/XLog.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)