Skip to content

Commit 8084ddb

Browse files
committed
Rename Logger to LogSubscriber and integrate with Monitoring API
1 parent e7a15f5 commit 8084ddb

36 files changed

+573
-509
lines changed

bin/prep-release.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function get_files() {
4444

4545
"src/MongoDB/*.{c,h}",
4646
"src/MongoDB/Exception/*.{c,h}",
47-
"src/MongoDB/Logging/*.{c,h}",
4847
"src/MongoDB/Monitoring/*.{c,h}",
4948
"src/BSON/*.{c,h}",
5049
"src/contrib/*.{c,h}",

config.m4

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,11 @@ if test "$PHP_MONGODB" != "no"; then
186186
src/MongoDB/Exception/SSLConnectionException.c \
187187
src/MongoDB/Exception/UnexpectedValueException.c \
188188
src/MongoDB/Exception/WriteException.c \
189-
src/MongoDB/Logging/Logger.c \
190-
src/MongoDB/Logging/functions.c \
191189
src/MongoDB/Monitoring/CommandFailedEvent.c \
192190
src/MongoDB/Monitoring/CommandStartedEvent.c \
193191
src/MongoDB/Monitoring/CommandSubscriber.c \
194192
src/MongoDB/Monitoring/CommandSucceededEvent.c \
193+
src/MongoDB/Monitoring/LogSubscriber.c \
195194
src/MongoDB/Monitoring/SDAMSubscriber.c \
196195
src/MongoDB/Monitoring/Subscriber.c \
197196
src/MongoDB/Monitoring/ServerChangedEvent.c \
@@ -544,15 +543,13 @@ if test "$PHP_MONGODB" != "no"; then
544543
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/BSON/])
545544
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/MongoDB/])
546545
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/MongoDB/Exception/])
547-
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/MongoDB/Logging/])
548546
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/MongoDB/Monitoring/])
549547
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR(mongodb)[/src/contrib/])
550548

551549
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/])
552550
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/BSON/])
553551
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/MongoDB/])
554552
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/MongoDB/Exception/])
555-
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/MongoDB/Logging/])
556553
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/MongoDB/Monitoring/])
557554
PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(mongodb)[/src/contrib/])
558555

config.w32

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ if (PHP_MONGODB != "no") {
9191
/I" + configure_module_dirname + "/src/BSON \
9292
/I" + configure_module_dirname + "/src/MongoDB \
9393
/I" + configure_module_dirname + "/src/MongoDB/Exception \
94-
/I" + configure_module_dirname + "/src/MongoDB/Logging \
9594
/I" + configure_module_dirname + "/src/MongoDB/Monitoring \
9695
/I" + configure_module_dirname + "/src/contrib \
9796
/I" + configure_module_dirname + "/src/libmongoc/src/common \
@@ -128,8 +127,7 @@ if (PHP_MONGODB != "no") {
128127
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");
129128
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");
130129
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");
131-
MONGODB_ADD_SOURCES("/src/MongoDB/Logging", "Logger.c functions.c");
132-
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");
133131
MONGODB_ADD_SOURCES("/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES);
134132
MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES);
135133
MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/jsonsl", PHP_MONGODB_JSONSL_SOURCES);

php_phongo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,13 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
282282
php_phongo_sslconnectionexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
283283
php_phongo_unexpectedvalueexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
284284

285-
php_phongo_logger_init_ce(INIT_FUNC_ARGS_PASSTHRU);
286-
287285
/* Register base APM classes first */
288286
php_phongo_subscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
289287
php_phongo_commandsubscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
290288
php_phongo_commandfailedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
291289
php_phongo_commandstartedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
292290
php_phongo_commandsucceededevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
291+
php_phongo_logsubscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
293292
php_phongo_sdamsubscriber_init_ce(INIT_FUNC_ARGS_PASSTHRU);
294293
php_phongo_serverchangedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);
295294
php_phongo_serverclosedevent_init_ce(INIT_FUNC_ARGS_PASSTHRU);

src/MongoDB/Logging/functions.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/MongoDB/Manager.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ static PHP_METHOD(MongoDB_Driver_Manager, addSubscriber)
304304
zend_hash_init(intern->subscribers, 0, NULL, ZVAL_PTR_DTOR, 0);
305305
}
306306

307+
// TODO: Consider throwing if subscriber is unsupported (see: PHPC-2289)
308+
307309
phongo_apm_add_subscriber(intern->subscribers, subscriber);
308310
}
309311

src/MongoDB/Logging/Logger.c renamed to src/MongoDB/Monitoring/LogSubscriber.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <php.h>
2020

2121
#include "php_phongo.h"
22-
#include "Logger_arginfo.h"
22+
#include "LogSubscriber_arginfo.h"
2323

24-
zend_class_entry* php_phongo_logger_ce;
24+
zend_class_entry* php_phongo_logsubscriber_ce;
2525

26-
void php_phongo_logger_init_ce(INIT_FUNC_ARGS)
26+
void php_phongo_logsubscriber_init_ce(INIT_FUNC_ARGS)
2727
{
28-
php_phongo_logger_ce = register_class_MongoDB_Driver_Logging_Logger();
28+
php_phongo_logsubscriber_ce = register_class_MongoDB_Driver_Monitoring_LogSubscriber(php_phongo_subscriber_ce);
2929
}

src/MongoDB/Logging/Logger.stub.php renamed to src/MongoDB/Monitoring/LogSubscriber.stub.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,49 @@
55
* @generate-function-entries
66
*/
77

8-
namespace MongoDB\Driver\Logging;
8+
namespace MongoDB\Driver\Monitoring;
99

10-
interface Logger
10+
interface LogSubscriber extends Subscriber
1111
{
1212
/**
1313
* @var int
1414
* @cvalue MONGOC_LOG_LEVEL_ERROR
1515
*/
16-
public const LEVEL_ERROR = UNKNOWN;
16+
public const LEVEL_ERROR = 0;
1717

1818
/**
1919
* @var int
2020
* @cvalue MONGOC_LOG_LEVEL_CRITICAL
2121
*/
22-
public const LEVEL_CRITICAL = UNKNOWN;
22+
public const LEVEL_CRITICAL = 1;
2323

2424
/**
2525
* @var int
2626
* @cvalue MONGOC_LOG_LEVEL_WARNING
2727
*/
28-
public const LEVEL_WARNING = UNKNOWN;
28+
public const LEVEL_WARNING = 2;
2929

3030
/**
3131
* @var int
3232
* @cvalue MONGOC_LOG_LEVEL_MESSAGE
3333
*/
34-
public const LEVEL_MESSAGE = UNKNOWN;
34+
public const LEVEL_MESSAGE = 3;
3535

3636
/**
3737
* @var int
3838
* @cvalue MONGOC_LOG_LEVEL_INFO
3939
*/
40-
public const LEVEL_INFO = UNKNOWN;
40+
public const LEVEL_INFO = 4;
4141

4242
/**
4343
* @var int
4444
* @cvalue MONGOC_LOG_LEVEL_DEBUG
4545
*/
46-
public const LEVEL_DEBUG = UNKNOWN;
46+
public const LEVEL_DEBUG = 5;
4747

48-
/**
49-
* @var int
50-
* @cvalue MONGOC_LOG_LEVEL_TRACE
51-
*/
52-
public const LEVEL_TRACE = UNKNOWN;
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. */
5351

5452
public function log(int $level, string $domain, string $message): void;
5553
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 60e1f5e5c02b6313e39e2890c957e9c2f69d2718 */
2+
* Stub hash: 4920ad21bd26ea586d4322d49bf44c9c3530e494 */
33

4-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Logging_Logger_log, 0, 3, IS_VOID, 0)
4+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_LogSubscriber_log, 0, 3, IS_VOID, 0)
55
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
66
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
77
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
@@ -10,59 +10,60 @@ ZEND_END_ARG_INFO()
1010

1111

1212

13-
static const zend_function_entry class_MongoDB_Driver_Logging_Logger_methods[] = {
14-
ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_Logging_Logger, log, arginfo_class_MongoDB_Driver_Logging_Logger_log, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
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)
1515
ZEND_FE_END
1616
};
1717

18-
static zend_class_entry *register_class_MongoDB_Driver_Logging_Logger(void)
18+
static zend_class_entry *register_class_MongoDB_Driver_Monitoring_LogSubscriber(zend_class_entry *class_entry_MongoDB_Driver_Monitoring_Subscriber)
1919
{
2020
zend_class_entry ce, *class_entry;
2121

22-
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Logging", "Logger", class_MongoDB_Driver_Logging_Logger_methods);
22+
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "LogSubscriber", class_MongoDB_Driver_Monitoring_LogSubscriber_methods);
2323
class_entry = zend_register_internal_interface(&ce);
24+
zend_class_implements(class_entry, 1, class_entry_MongoDB_Driver_Monitoring_Subscriber);
2425

2526
zval const_LEVEL_ERROR_value;
2627
ZVAL_LONG(&const_LEVEL_ERROR_value, MONGOC_LOG_LEVEL_ERROR);
2728
zend_string *const_LEVEL_ERROR_name = zend_string_init_interned("LEVEL_ERROR", sizeof("LEVEL_ERROR") - 1, 1);
2829
zend_declare_class_constant_ex(class_entry, const_LEVEL_ERROR_name, &const_LEVEL_ERROR_value, ZEND_ACC_PUBLIC, NULL);
2930
zend_string_release(const_LEVEL_ERROR_name);
31+
ZEND_ASSERT(MONGOC_LOG_LEVEL_ERROR == 0);
3032

3133
zval const_LEVEL_CRITICAL_value;
3234
ZVAL_LONG(&const_LEVEL_CRITICAL_value, MONGOC_LOG_LEVEL_CRITICAL);
3335
zend_string *const_LEVEL_CRITICAL_name = zend_string_init_interned("LEVEL_CRITICAL", sizeof("LEVEL_CRITICAL") - 1, 1);
3436
zend_declare_class_constant_ex(class_entry, const_LEVEL_CRITICAL_name, &const_LEVEL_CRITICAL_value, ZEND_ACC_PUBLIC, NULL);
3537
zend_string_release(const_LEVEL_CRITICAL_name);
38+
ZEND_ASSERT(MONGOC_LOG_LEVEL_CRITICAL == 1);
3639

3740
zval const_LEVEL_WARNING_value;
3841
ZVAL_LONG(&const_LEVEL_WARNING_value, MONGOC_LOG_LEVEL_WARNING);
3942
zend_string *const_LEVEL_WARNING_name = zend_string_init_interned("LEVEL_WARNING", sizeof("LEVEL_WARNING") - 1, 1);
4043
zend_declare_class_constant_ex(class_entry, const_LEVEL_WARNING_name, &const_LEVEL_WARNING_value, ZEND_ACC_PUBLIC, NULL);
4144
zend_string_release(const_LEVEL_WARNING_name);
45+
ZEND_ASSERT(MONGOC_LOG_LEVEL_WARNING == 2);
4246

4347
zval const_LEVEL_MESSAGE_value;
4448
ZVAL_LONG(&const_LEVEL_MESSAGE_value, MONGOC_LOG_LEVEL_MESSAGE);
4549
zend_string *const_LEVEL_MESSAGE_name = zend_string_init_interned("LEVEL_MESSAGE", sizeof("LEVEL_MESSAGE") - 1, 1);
4650
zend_declare_class_constant_ex(class_entry, const_LEVEL_MESSAGE_name, &const_LEVEL_MESSAGE_value, ZEND_ACC_PUBLIC, NULL);
4751
zend_string_release(const_LEVEL_MESSAGE_name);
52+
ZEND_ASSERT(MONGOC_LOG_LEVEL_MESSAGE == 3);
4853

4954
zval const_LEVEL_INFO_value;
5055
ZVAL_LONG(&const_LEVEL_INFO_value, MONGOC_LOG_LEVEL_INFO);
5156
zend_string *const_LEVEL_INFO_name = zend_string_init_interned("LEVEL_INFO", sizeof("LEVEL_INFO") - 1, 1);
5257
zend_declare_class_constant_ex(class_entry, const_LEVEL_INFO_name, &const_LEVEL_INFO_value, ZEND_ACC_PUBLIC, NULL);
5358
zend_string_release(const_LEVEL_INFO_name);
59+
ZEND_ASSERT(MONGOC_LOG_LEVEL_INFO == 4);
5460

5561
zval const_LEVEL_DEBUG_value;
5662
ZVAL_LONG(&const_LEVEL_DEBUG_value, MONGOC_LOG_LEVEL_DEBUG);
5763
zend_string *const_LEVEL_DEBUG_name = zend_string_init_interned("LEVEL_DEBUG", sizeof("LEVEL_DEBUG") - 1, 1);
5864
zend_declare_class_constant_ex(class_entry, const_LEVEL_DEBUG_name, &const_LEVEL_DEBUG_value, ZEND_ACC_PUBLIC, NULL);
5965
zend_string_release(const_LEVEL_DEBUG_name);
60-
61-
zval const_LEVEL_TRACE_value;
62-
ZVAL_LONG(&const_LEVEL_TRACE_value, MONGOC_LOG_LEVEL_TRACE);
63-
zend_string *const_LEVEL_TRACE_name = zend_string_init_interned("LEVEL_TRACE", sizeof("LEVEL_TRACE") - 1, 1);
64-
zend_declare_class_constant_ex(class_entry, const_LEVEL_TRACE_name, &const_LEVEL_TRACE_value, ZEND_ACC_PUBLIC, NULL);
65-
zend_string_release(const_LEVEL_TRACE_name);
66+
ZEND_ASSERT(MONGOC_LOG_LEVEL_DEBUG == 5);
6667

6768
return class_entry;
6869
}

0 commit comments

Comments
 (0)