Skip to content

Commit 19c6c3d

Browse files
committed
Merge pull request bcit-ci#3427 from gadelat/logdate
Support for microseconds in CI_Log
2 parents e7068ed + 53e8303 commit 19c6c3d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

system/core/Log.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,20 @@ public function write_log($level, $msg)
198198
return FALSE;
199199
}
200200

201-
$message .= $level.' - '.date($this->_date_fmt).' --> '.$msg."\n";
201+
// Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format
202+
if (strpos($this->_date_fmt, 'u') !== FALSE)
203+
{
204+
$microtime_full = microtime(TRUE);
205+
$microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000);
206+
$date = new DateTime(date('Y-m-d H:i:s.'.$microtime_short, $microtime_full));
207+
$date = $date->format($this->_date_fmt);
208+
}
209+
else
210+
{
211+
$date = date($this->_date_fmt);
212+
}
213+
214+
$message .= $level.' - '.$date.' --> '.$msg."\n";
202215

203216
flock($fp, LOCK_EX);
204217

user_guide_src/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ Release Date: Not Released
553553

554554
- Added a ``$config['log_file_permissions']`` setting.
555555
- Changed the library constructor to try to create the **log_path** directory if it doesn't exist.
556+
- Added support for microseconds ("u" date format character) in ``$config['log_date_format']``.
556557

557558
- Added `compatibility layers <general/compatibility_functions>` for:
558559

0 commit comments

Comments
 (0)