Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 56f9e69

Browse files
committed
up
1 parent 5466d43 commit 56f9e69

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

src/Helpers/DateHelper.php

+33
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ public static function isDateFormat($date, $format = 'Y-m-d')
6060
return false;
6161
}
6262

63+
/**
64+
* @return int
65+
*/
66+
public static function todayStart()
67+
{
68+
// return strtotime(date('Y-m-d 00:00:00'));
69+
return strtotime('today 00:00:00');
70+
}
71+
72+
/**
73+
* @return int
74+
*/
75+
public static function todayEnd()
76+
{
77+
// return strtotime(date('Y-m-d 23:59:59'));
78+
return strtotime('today 23:59:59');
79+
}
80+
6381
/**
6482
* @return false|int
6583
*/
@@ -68,6 +86,21 @@ public static function tomorrowBegin()
6886
return mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'));
6987
}
7088

89+
/**
90+
* @return int
91+
*/
92+
public static function tomorrowStart()
93+
{
94+
return strtotime('+1 day 00:00:00');
95+
}
96+
97+
/**
98+
* @return int
99+
*/
100+
public static function tomorrowEnd()
101+
{
102+
return strtotime('+1 day 23:59:59');
103+
}
71104
/**
72105
* @return false|int
73106
*/

src/Traits/LogProfileTrait.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ trait LogProfileTrait
2424
*/
2525
private $profiles = [];
2626

27+
/** @var string e.g 'application|request' */
28+
private $activeKey;
29+
2730
/**
2831
* mark data analysis start
2932
* @param $name
@@ -41,18 +44,23 @@ public function profile($name, array $context = [], $category = 'application')
4144
'_profile_end' => null,
4245
];
4346

47+
$this->activeKey = $category . '|' . $name;
4448
$this->profiles[$category][$name] = $data;
4549
}
4650

4751
/**
4852
* mark data analysis end
49-
* @param string $name
5053
* @param string|null $title
5154
* @param array $context
52-
* @param string $category
5355
*/
54-
public function profileEnd($name, $title = null, array $context = [], $category = 'application')
56+
public function profileEnd($title = null, array $context = [])
5557
{
58+
if (!$this->activeKey) {
59+
return;
60+
}
61+
62+
list($category, $name) = explode('|', $this->activeKey);
63+
5664
if (isset($this->profiles[$category][$name])) {
5765
$data = $this->profiles[$category][$name];
5866

@@ -62,8 +70,9 @@ public function profileEnd($name, $title = null, array $context = [], $category
6270

6371
$title = $category . ' - ' . ($title ?: $name);
6472

73+
$this->activeKey = null;
6574
$this->log(Logger::DEBUG, $title, $data);
6675
}
6776
}
6877

69-
}
78+
}

src/Traits/LogShortTrait.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ public static function debug($message, array $context = array())
139139
*/
140140
public static function trace($message, array $context = array())
141141
{
142-
$tce = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
142+
if (!isset($context['_called_at'])) {
143+
$tce = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
143144

144-
if ($info = $tce[1] ?? null) {
145-
$context['_called_at'] = sprintf('%s::%s Line %d', $info['class'], $info['function'], $tce[0]['line']);
145+
if ($info = $tce[1] ?? null) {
146+
$context['_called_at'] = sprintf('%s::%s Line %d', $info['class'], $info['function'], $tce[0]['line']);
147+
}
146148
}
147149

148150
$context['_stats'] = PhpHelper::runtime(Req::server('request_time_float'), Req::server('request_memory'));

src/Utils/LiteLogger.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,16 @@ public function trace($message = '', array $context = [])
283283

284284
if (!isset($context['_called_at'])) {
285285
$file = $method = $line = 'Unknown';
286+
$data = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
286287

287-
if ($data = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)) {
288-
if (isset($data[0])) {
289-
$file = $data[0]['file'];
290-
$line = $data[0]['line'];
291-
}
292-
293-
if (isset($data[1])) {
294-
$t = $data[1];
295-
$method = Arr::remove($t, 'class', 'CLASS') . '::' . Arr::remove($t, 'function', 'METHOD');
296-
}
288+
if (isset($data[1])) {
289+
$file = $data[0]['file'];
290+
$line = $data[0]['line'];
291+
$t = $data[1];
292+
$method = Arr::remove($t, 'class', 'CLASS') . '::' . Arr::remove($t, 'function', 'METHOD');
297293
}
298294

299-
$context['_called_at'] = "$method File $file line $line";
295+
$context['_called_at'] = "$method, On $file line $line";
300296
}
301297

302298
$this->log(self::TRACE, $message, $context);

0 commit comments

Comments
 (0)