Skip to content

Commit 03da646

Browse files
committed
PHPC-709: Add microseconds to log messages
1 parent 0f31fc4 commit 03da646

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

php_phongo.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,24 @@ void phongo_throw_exception_from_bson_error_t(bson_error_t *error TSRMLS_DC)
213213
{
214214
zend_throw_exception(phongo_exception_from_mongoc_domain(error->domain, error->code), error->message, error->code TSRMLS_CC);
215215
}
216+
216217
static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain, const char *message, void *user_data)
217218
{
218-
phongo_char *dt;
219+
struct timeval tv;
220+
time_t t;
221+
phongo_long tu;
222+
phongo_char *dt;
219223

220224
PHONGO_TSRMLS_FETCH_FROM_CTX(user_data);
221225
(void)user_data;
222226

223-
dt = php_format_date((char *) ZEND_STRL("Y-m-d\\TH:i:sP"), time(NULL), 0 TSRMLS_CC);
227+
gettimeofday(&tv, NULL);
228+
t = tv.tv_sec;
229+
tu = tv.tv_usec;
230+
231+
dt = php_format_date((char *) ZEND_STRL("Y-m-d\\TH:i:s"), t, 0 TSRMLS_CC);
224232

225-
fprintf(MONGODB_G(debug_fd), "[%s] %10s: %-8s> %s\n", ZSTR_VAL(dt), log_domain, mongoc_log_level_str(log_level), message);
233+
fprintf(MONGODB_G(debug_fd), "[%s.%06lu+00:00] %10s: %-8s> %s\n", ZSTR_VAL(dt), tu, log_domain, mongoc_log_level_str(log_level), message);
226234
fflush(MONGODB_G(debug_fd));
227235
efree(dt);
228236
}

tests/manager/manager-debug-001.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
MongoDB\Driver\Manager: Writing debug log files
3-
--SKIPIF--
4-
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM uses HHVM's logging functionality"); ?>
53
--FILE--
64
<?php
75

tests/manager/manager-debug-002.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\Manager: mongodb.debug=stderr
3-
--SKIPIF--
4-
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM uses HHVM's logging functionality"); ?>
2+
MongoDB\Driver\Manager: mongodb.debug=stderr (connection string and version)
53
--INI--
64
mongodb.debug=stderr
75
--FILE--

tests/manager/manager-debug-003.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
MongoDB\Driver\Manager: mongodb.debug=stderr (date format)
3+
--INI--
4+
mongodb.debug=stderr
5+
--FILE--
6+
<?php
7+
$manager = new MongoDB\Driver\Manager;
8+
?>
9+
===DONE===
10+
<?php exit(0); ?>
11+
--EXPECTF--
12+
[%r(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}\+00:00)%r]%A
13+
===DONE===%A

0 commit comments

Comments
 (0)