Skip to content

Commit cf125e3

Browse files
authored
PHPC-2180: Allow applications to register a log message subscriber (#1395)
* Introduce LogSubscriber interface and integrate with Monitoring API LogSubscribers can be registered globally with existing add/removeSubscriber functions, and can be used as an alternative to the mongodb.debug INI setting with the notable difference that MONGOC_LOG_LEVEL_TRACE messages will not be dispatched to LogSubscribers (too verbose). An internal mongoc_log() function is introduced purely testing in both PHPC and PHPLIB. It will not be documented and should not be used by applications. * Use call_user_function instead of zend_call_method_if_exists zend_call_method_if_exists() was introduced in PHP 8.2, so this ensures compatibility back to PHP 7.4. This could still be optimized to initialize FCI/FCC structs when a logger is first registered. If so, call_user_function can be replaced with zend_call_function(). * Rely on contravariance to simplify interface implementations in tests These methods are never called, so type hints are unnecessary * Test add/removeSubscriber behavior with LogSubscriber&CommandSubscriber * PHPC-2289: Prohibit passing LogSubscriber to Manager::addSubscriber() libmongoc does not yet support client-level logging, so only allow LogSubscribers to be registered globally.
1 parent 8b5e192 commit cf125e3

32 files changed

+1071
-70
lines changed

config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ if test "$PHP_MONGODB" != "no"; then
120120
src/phongo_error.c \
121121
src/phongo_execute.c \
122122
src/phongo_ini.c \
123+
src/phongo_log.c \
123124
src/phongo_util.c \
124125
src/BSON/Binary.c \
125126
src/BSON/BinaryInterface.c \
@@ -189,6 +190,7 @@ if test "$PHP_MONGODB" != "no"; then
189190
src/MongoDB/Monitoring/CommandStartedEvent.c \
190191
src/MongoDB/Monitoring/CommandSubscriber.c \
191192
src/MongoDB/Monitoring/CommandSucceededEvent.c \
193+
src/MongoDB/Monitoring/LogSubscriber.c \
192194
src/MongoDB/Monitoring/SDAMSubscriber.c \
193195
src/MongoDB/Monitoring/Subscriber.c \
194196
src/MongoDB/Monitoring/ServerChangedEvent.c \

config.w32

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ if (PHP_MONGODB != "no") {
123123
var PHP_MONGODB_UTF8PROC_SOURCES="utf8proc.c";
124124

125125
EXTENSION("mongodb", "php_phongo.c", null, PHP_MONGODB_CFLAGS);
126-
MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_util.c");
126+
MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c");
127127
MONGODB_ADD_SOURCES("/src/BSON", "Binary.c BinaryInterface.c Document.c Iterator.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c PackedArray.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c");
128128
MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorId.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c");
129129
MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c");
130-
MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c");
130+
MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c LogSubscriber.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c");
131131
MONGODB_ADD_SOURCES("/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES);
132132
MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES);
133133
MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/jsonsl", PHP_MONGODB_JSONSL_SOURCES);

php_phongo.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/phongo_client.h"
2929
#include "src/phongo_error.h"
3030
#include "src/phongo_ini.h"
31+
#include "src/phongo_log.h"
3132
#include "src/functions_arginfo.h"
3233

3334
ZEND_DECLARE_MODULE_GLOBALS(mongodb)
@@ -89,6 +90,16 @@ PHP_RINIT_FUNCTION(mongodb) /* {{{ */
8990
zend_hash_init(MONGODB_G(request_clients), 0, NULL, php_phongo_pclient_destroy_ptr, 0);
9091
}
9192

93+
/* Initialize HashTable for loggers, which is initialized to NULL in GINIT
94+
* and destroyed and reset to NULL in RSHUTDOWN. Since this HashTable will
95+
* store logger object zvals, we specify ZVAL_PTR_DTOR as its element
96+
* destructor so that any still-registered loggers can be freed in
97+
* RSHUTDOWN. */
98+
if (MONGODB_G(loggers) == NULL) {
99+
ALLOC_HASHTABLE(MONGODB_G(loggers));
100+
zend_hash_init(MONGODB_G(loggers), 0, NULL, ZVAL_PTR_DTOR, 0);
101+
}
102+
92103
/* Initialize HashTable for APM subscribers, which is initialized to NULL in
93104
* GINIT and destroyed and reset to NULL in RSHUTDOWN. Since this HashTable
94105
* will store subscriber object zvals, we specify ZVAL_PTR_DTOR as its
@@ -160,6 +171,12 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
160171

161172
(void) type; /* We don't care if we are loaded via dl() or extension= */
162173

174+
/* Start by disabling libmongoc's default log handler, which could write to
175+
* stdout/stderr. The PHP driver's log handler may be assigned below when
176+
* parsing INI options or at a later point during a request when registering
177+
* a logger. */
178+
mongoc_log_set_handler(NULL, NULL);
179+
163180
phongo_register_ini_entries(INIT_FUNC_ARGS_PASSTHRU);
164181

165182
/* Assign our custom vtable to libbson, so all memory allocation in libbson
@@ -271,6 +288,7 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
271288
php_phongo_commandfailedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
272289
php_phongo_commandstartedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
273290
php_phongo_commandsucceededevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
291+
php_phongo_logsubscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
274292
php_phongo_sdamsubscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
275293
php_phongo_serverchangedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
276294
php_phongo_serverclosedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
@@ -297,6 +315,16 @@ PHP_MSHUTDOWN_FUNCTION(mongodb) /* {{{ */
297315

298316
PHP_RSHUTDOWN_FUNCTION(mongodb) /* {{{ */
299317
{
318+
/* Destroy HashTable for loggers, which was initialized in RINIT. */
319+
if (MONGODB_G(loggers)) {
320+
zend_hash_destroy(MONGODB_G(loggers));
321+
FREE_HASHTABLE(MONGODB_G(loggers));
322+
MONGODB_G(loggers) = NULL;
323+
}
324+
325+
/* TODO: consider calling phongo_log_sync_handler here since logging may no
326+
* longer be enabled. */
327+
300328
/* Destroy HashTable for APM subscribers, which was initialized in RINIT. */
301329
if (MONGODB_G(subscribers)) {
302330
zend_hash_destroy(MONGODB_G(subscribers));
@@ -334,8 +362,9 @@ PHP_GSHUTDOWN_FUNCTION(mongodb) /* {{{ */
334362
* encryption settings. */
335363
zend_hash_graceful_reverse_destroy(&mongodb_globals->persistent_clients);
336364

337-
phongo_log_disable(mongodb_globals->debug_fd);
338-
mongodb_globals->debug_fd = NULL;
365+
/* TODO: Check that logging actually gets disabled. The logger HashTable
366+
* should be empty by this point. */
367+
phongo_log_set_stream(NULL);
339368

340369
/* Decrement the thread counter. If it reaches zero, we can infer that this
341370
* is the last thread, MSHUTDOWN has been called, persistent clients from

php_phongo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ZEND_BEGIN_MODULE_GLOBALS(mongodb)
5050
HashTable* request_clients;
5151
HashTable* subscribers;
5252
HashTable* managers;
53+
HashTable* loggers;
5354
ZEND_END_MODULE_GLOBALS(mongodb)
5455

5556
#define MONGODB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mongodb, v)

src/MongoDB/Manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ static PHP_METHOD(MongoDB_Driver_Manager, addSubscriber)
296296
Z_PARAM_OBJECT_OF_CLASS(subscriber, php_phongo_subscriber_ce)
297297
PHONGO_PARSE_PARAMETERS_END();
298298

299+
if (instanceof_function(Z_OBJCE_P(subscriber), php_phongo_logsubscriber_ce)) {
300+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "LogSubscriber instances cannot be registered with a Manager");
301+
}
302+
299303
intern = Z_MANAGER_OBJ_P(getThis());
300304

301305
/* Lazily initialize the subscriber HashTable */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2016-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "mongoc/mongoc.h"
18+
19+
#include <php.h>
20+
21+
#include "php_phongo.h"
22+
#include "LogSubscriber_arginfo.h"
23+
24+
zend_class_entry* php_phongo_logsubscriber_ce;
25+
26+
void php_phongo_logsubscriber_init_ce(INIT_FUNC_ARGS)
27+
{
28+
php_phongo_logsubscriber_ce = register_class_MongoDB_Driver_Monitoring_LogSubscriber(php_phongo_subscriber_ce);
29+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* @generate-class-entries static
5+
* @generate-function-entries
6+
*/
7+
8+
namespace MongoDB\Driver\Monitoring;
9+
10+
interface LogSubscriber extends Subscriber
11+
{
12+
/**
13+
* @var int
14+
* @cvalue MONGOC_LOG_LEVEL_ERROR
15+
*/
16+
public const LEVEL_ERROR = 0;
17+
18+
/**
19+
* @var int
20+
* @cvalue MONGOC_LOG_LEVEL_CRITICAL
21+
*/
22+
public const LEVEL_CRITICAL = 1;
23+
24+
/**
25+
* @var int
26+
* @cvalue MONGOC_LOG_LEVEL_WARNING
27+
*/
28+
public const LEVEL_WARNING = 2;
29+
30+
/**
31+
* @var int
32+
* @cvalue MONGOC_LOG_LEVEL_MESSAGE
33+
*/
34+
public const LEVEL_MESSAGE = 3;
35+
36+
/**
37+
* @var int
38+
* @cvalue MONGOC_LOG_LEVEL_INFO
39+
*/
40+
public const LEVEL_INFO = 4;
41+
42+
/**
43+
* @var int
44+
* @cvalue MONGOC_LOG_LEVEL_DEBUG
45+
*/
46+
public const LEVEL_DEBUG = 5;
47+
48+
/* MONGOC_LOG_LEVEL_TRACE is intentionally omitted. Trace logs are only
49+
* reported via streams (i.e. mongodb.debug INI), so the constant is not
50+
* relevant to LogSubscriber implementations. */
51+
52+
public function log(int $level, string $domain, string $message): void;
53+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 4920ad21bd26ea586d4322d49bf44c9c3530e494 */
3+
4+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_LogSubscriber_log, 0, 3, IS_VOID, 0)
5+
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
6+
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
7+
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
8+
ZEND_END_ARG_INFO()
9+
10+
11+
12+
13+
static const zend_function_entry class_MongoDB_Driver_Monitoring_LogSubscriber_methods[] = {
14+
ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_Monitoring_LogSubscriber, log, arginfo_class_MongoDB_Driver_Monitoring_LogSubscriber_log, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
15+
ZEND_FE_END
16+
};
17+
18+
static zend_class_entry *register_class_MongoDB_Driver_Monitoring_LogSubscriber(zend_class_entry *class_entry_MongoDB_Driver_Monitoring_Subscriber)
19+
{
20+
zend_class_entry ce, *class_entry;
21+
22+
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "LogSubscriber", class_MongoDB_Driver_Monitoring_LogSubscriber_methods);
23+
class_entry = zend_register_internal_interface(&ce);
24+
zend_class_implements(class_entry, 1, class_entry_MongoDB_Driver_Monitoring_Subscriber);
25+
26+
zval const_LEVEL_ERROR_value;
27+
ZVAL_LONG(&const_LEVEL_ERROR_value, MONGOC_LOG_LEVEL_ERROR);
28+
zend_string *const_LEVEL_ERROR_name = zend_string_init_interned("LEVEL_ERROR", sizeof("LEVEL_ERROR") - 1, 1);
29+
zend_declare_class_constant_ex(class_entry, const_LEVEL_ERROR_name, &const_LEVEL_ERROR_value, ZEND_ACC_PUBLIC, NULL);
30+
zend_string_release(const_LEVEL_ERROR_name);
31+
ZEND_ASSERT(MONGOC_LOG_LEVEL_ERROR == 0);
32+
33+
zval const_LEVEL_CRITICAL_value;
34+
ZVAL_LONG(&const_LEVEL_CRITICAL_value, MONGOC_LOG_LEVEL_CRITICAL);
35+
zend_string *const_LEVEL_CRITICAL_name = zend_string_init_interned("LEVEL_CRITICAL", sizeof("LEVEL_CRITICAL") - 1, 1);
36+
zend_declare_class_constant_ex(class_entry, const_LEVEL_CRITICAL_name, &const_LEVEL_CRITICAL_value, ZEND_ACC_PUBLIC, NULL);
37+
zend_string_release(const_LEVEL_CRITICAL_name);
38+
ZEND_ASSERT(MONGOC_LOG_LEVEL_CRITICAL == 1);
39+
40+
zval const_LEVEL_WARNING_value;
41+
ZVAL_LONG(&const_LEVEL_WARNING_value, MONGOC_LOG_LEVEL_WARNING);
42+
zend_string *const_LEVEL_WARNING_name = zend_string_init_interned("LEVEL_WARNING", sizeof("LEVEL_WARNING") - 1, 1);
43+
zend_declare_class_constant_ex(class_entry, const_LEVEL_WARNING_name, &const_LEVEL_WARNING_value, ZEND_ACC_PUBLIC, NULL);
44+
zend_string_release(const_LEVEL_WARNING_name);
45+
ZEND_ASSERT(MONGOC_LOG_LEVEL_WARNING == 2);
46+
47+
zval const_LEVEL_MESSAGE_value;
48+
ZVAL_LONG(&const_LEVEL_MESSAGE_value, MONGOC_LOG_LEVEL_MESSAGE);
49+
zend_string *const_LEVEL_MESSAGE_name = zend_string_init_interned("LEVEL_MESSAGE", sizeof("LEVEL_MESSAGE") - 1, 1);
50+
zend_declare_class_constant_ex(class_entry, const_LEVEL_MESSAGE_name, &const_LEVEL_MESSAGE_value, ZEND_ACC_PUBLIC, NULL);
51+
zend_string_release(const_LEVEL_MESSAGE_name);
52+
ZEND_ASSERT(MONGOC_LOG_LEVEL_MESSAGE == 3);
53+
54+
zval const_LEVEL_INFO_value;
55+
ZVAL_LONG(&const_LEVEL_INFO_value, MONGOC_LOG_LEVEL_INFO);
56+
zend_string *const_LEVEL_INFO_name = zend_string_init_interned("LEVEL_INFO", sizeof("LEVEL_INFO") - 1, 1);
57+
zend_declare_class_constant_ex(class_entry, const_LEVEL_INFO_name, &const_LEVEL_INFO_value, ZEND_ACC_PUBLIC, NULL);
58+
zend_string_release(const_LEVEL_INFO_name);
59+
ZEND_ASSERT(MONGOC_LOG_LEVEL_INFO == 4);
60+
61+
zval const_LEVEL_DEBUG_value;
62+
ZVAL_LONG(&const_LEVEL_DEBUG_value, MONGOC_LOG_LEVEL_DEBUG);
63+
zend_string *const_LEVEL_DEBUG_name = zend_string_init_interned("LEVEL_DEBUG", sizeof("LEVEL_DEBUG") - 1, 1);
64+
zend_declare_class_constant_ex(class_entry, const_LEVEL_DEBUG_name, &const_LEVEL_DEBUG_value, ZEND_ACC_PUBLIC, NULL);
65+
zend_string_release(const_LEVEL_DEBUG_name);
66+
ZEND_ASSERT(MONGOC_LOG_LEVEL_DEBUG == 5);
67+
68+
return class_entry;
69+
}

src/MongoDB/Monitoring/functions.c

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include "mongoc/mongoc.h"
18+
1719
#include <php.h>
1820

1921
#include "php_phongo.h"
2022
#include "phongo_apm.h"
2123
#include "phongo_error.h"
24+
#include "phongo_log.h"
2225

2326
ZEND_EXTERN_MODULE_GLOBALS(mongodb)
2427

28+
#define IS_APM_SUBSCRIBER(zv) \
29+
instanceof_function(Z_OBJCE_P(zv), php_phongo_commandsubscriber_ce) || \
30+
instanceof_function(Z_OBJCE_P(zv), php_phongo_sdamsubscriber_ce)
31+
32+
#define IS_LOG_SUBSCRIBER(zv) instanceof_function(Z_OBJCE_P(zv), php_phongo_logsubscriber_ce)
33+
2534
/* Registers a global event subscriber */
2635
PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber)
2736
{
@@ -31,7 +40,15 @@ PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber)
3140
Z_PARAM_OBJECT_OF_CLASS(subscriber, php_phongo_subscriber_ce)
3241
PHONGO_PARSE_PARAMETERS_END();
3342

34-
phongo_apm_add_subscriber(MONGODB_G(subscribers), subscriber);
43+
// TODO: Consider throwing if subscriber is unsupported (see: PHPC-2289)
44+
45+
if (IS_APM_SUBSCRIBER(subscriber)) {
46+
phongo_apm_add_subscriber(MONGODB_G(subscribers), subscriber);
47+
}
48+
49+
if (IS_LOG_SUBSCRIBER(subscriber)) {
50+
phongo_log_add_logger(subscriber);
51+
}
3552
}
3653

3754
/* Unregisters a global event subscriber */
@@ -43,5 +60,42 @@ PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber)
4360
Z_PARAM_OBJECT_OF_CLASS(subscriber, php_phongo_subscriber_ce)
4461
PHONGO_PARSE_PARAMETERS_END();
4562

46-
phongo_apm_remove_subscriber(MONGODB_G(subscribers), subscriber);
63+
if (IS_APM_SUBSCRIBER(subscriber)) {
64+
phongo_apm_remove_subscriber(MONGODB_G(subscribers), subscriber);
65+
}
66+
67+
if (IS_LOG_SUBSCRIBER(subscriber)) {
68+
phongo_log_remove_logger(subscriber);
69+
}
70+
}
71+
72+
/* Log a message through libmongoc (used for internal testing) */
73+
PHP_FUNCTION(MongoDB_Driver_Monitoring_mongoc_log)
74+
{
75+
zend_long level;
76+
char * domain, *message;
77+
size_t domain_len, message_len;
78+
79+
PHONGO_PARSE_PARAMETERS_START(3, 3)
80+
Z_PARAM_LONG(level)
81+
Z_PARAM_STRING(domain, domain_len)
82+
Z_PARAM_STRING(message, message_len)
83+
PHONGO_PARSE_PARAMETERS_END();
84+
85+
if (level < MONGOC_LOG_LEVEL_ERROR || level > MONGOC_LOG_LEVEL_TRACE) {
86+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected level to be >= %d and <= %d, %" PHONGO_LONG_FORMAT " given", MONGOC_LOG_LEVEL_ERROR, MONGOC_LOG_LEVEL_TRACE, level);
87+
return;
88+
}
89+
90+
if (strlen(domain) != domain_len) {
91+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Domain cannot contain null bytes. Unexpected null byte after \"%s\".", domain);
92+
return;
93+
}
94+
95+
if (strlen(message) != message_len) {
96+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Message cannot contain null bytes. Unexpected null byte after \"%s\".", message);
97+
return;
98+
}
99+
100+
mongoc_log(level, domain, "%s", message);
47101
}

src/functions.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ function toRelaxedExtendedJSON(string $bson): string {}
2929
namespace MongoDB\Driver\Monitoring {
3030
function addSubscriber(Subscriber $subscriber): void {}
3131

32+
/** @internal */
33+
function mongoc_log(int $level, string $domain, string $message): void {}
34+
3235
function removeSubscriber(Subscriber $subscriber): void {}
3336
}

0 commit comments

Comments
 (0)