Skip to content

Commit 701edc3

Browse files
committed
Fix suggestions from code review
1 parent 414a1b9 commit 701edc3

6 files changed

+53
-74
lines changed

src/libmongoc/src/mongoc/mongoc-structured-log-command-private.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
*/
1616

1717
#include "mongoc-prelude.h"
18+
19+
#ifndef MONGOC_STRUCTURED_LOG_COMMAND_PRIVATE_H
20+
#define MONGOC_STRUCTURED_LOG_COMMAND_PRIVATE_H
21+
1822
#include "mongoc-structured-log.h"
1923
#include "mongoc-cmd-private.h"
2024

21-
#ifndef MONGOC_STRUCTRURED_LOG_COMMAND_PRIVATE_H
22-
#define MONGOC_STRUCTRURED_LOG_COMMAND_PRIVATE_H
23-
2425
typedef struct {
2526
const char *command_name;
2627
const char *db_name;

src/libmongoc/src/mongoc/mongoc-structured-log-command.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
#if defined(__linux__)
19-
#include <sys/syscall.h>
20-
#elif defined(_WIN32)
21-
#include <process.h>
22-
#elif defined(__FreeBSD__)
23-
#include <sys/thr.h>
24-
#else
25-
#include <unistd.h>
26-
#endif
27-
#include <time.h>
28-
2917
#include "mongoc-structured-log.h"
3018
#include "mongoc-structured-log-private.h"
3119
#include "mongoc-structured-log-command-private.h"
@@ -130,14 +118,17 @@ mongoc_structured_log_command_started (const bson_t *command,
130118
bool explicit_session)
131119
{
132120
_mongoc_structured_log_command_t command_log = {
133-
.command = command,
134-
.command_name = command_name,
135-
.db_name = db_name,
136-
.operation_id = operation_id,
137-
.request_id = request_id,
138-
.driver_connection_id = driver_connection_id,
139-
.server_connection_id = server_connection_id,
140-
.explicit_session = explicit_session,
121+
command_name,
122+
db_name,
123+
command,
124+
NULL,
125+
NULL,
126+
0,
127+
operation_id,
128+
request_id,
129+
driver_connection_id,
130+
server_connection_id,
131+
explicit_session,
141132
};
142133

143134
mongoc_structured_log (MONGOC_STRUCTURED_LOG_LEVEL_INFO,
@@ -158,14 +149,17 @@ mongoc_structured_log_command_success (const char *command_name,
158149
bool explicit_session)
159150
{
160151
_mongoc_structured_log_command_t command_log = {
161-
.command_name = command_name,
162-
.operation_id = operation_id,
163-
.reply = reply,
164-
.duration = duration,
165-
.request_id = request_id,
166-
.driver_connection_id = driver_connection_id,
167-
.server_connection_id = server_connection_id,
168-
.explicit_session = explicit_session,
152+
command_name,
153+
NULL,
154+
NULL,
155+
reply,
156+
NULL,
157+
duration,
158+
operation_id,
159+
request_id,
160+
driver_connection_id,
161+
server_connection_id,
162+
explicit_session,
169163
};
170164

171165
mongoc_structured_log (MONGOC_STRUCTURED_LOG_LEVEL_INFO,
@@ -186,14 +180,17 @@ mongoc_structured_log_command_failure (const char *command_name,
186180
bool explicit_session)
187181
{
188182
_mongoc_structured_log_command_t command_log = {
189-
.command_name = command_name,
190-
.operation_id = operation_id,
191-
.reply = reply,
192-
.error = error,
193-
.request_id = request_id,
194-
.driver_connection_id = driver_connection_id,
195-
.server_connection_id = server_connection_id,
196-
.explicit_session = explicit_session,
183+
command_name,
184+
NULL,
185+
NULL,
186+
reply,
187+
error,
188+
0,
189+
operation_id,
190+
request_id,
191+
driver_connection_id,
192+
server_connection_id,
193+
explicit_session,
197194
};
198195

199196
mongoc_structured_log (MONGOC_STRUCTURED_LOG_LEVEL_INFO,

src/libmongoc/src/mongoc/mongoc-structured-log-connection-private.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
#include "mongoc-prelude.h"
18+
19+
#ifndef MONGOC_STRUCTURED_LOG_CONNECTION_PRIVATE_H
20+
#define MONGOC_STRUCTURED_LOG_CONNECTION_PRIVATE_H
21+
1822
#include "mongoc-structured-log.h"
1923
#include "mongoc-cmd-private.h"
2024

21-
#ifndef MONGOC_STRUCTRURED_LOG_CONNECTION_PRIVATE_H
22-
#define MONGOC_STRUCTRURED_LOG_CONNECTION_PRIVATE_H
23-
2425
void
25-
mongoc_structured_log_connection_client_created ();
26+
mongoc_structured_log_connection_client_created (void);
2627

2728
#endif /* MONGOC_STRUCTURED_LOG_COMMAND_PRIVATE_H */

src/libmongoc/src/mongoc/mongoc-structured-log-connection.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
#if defined(__linux__)
19-
#include <sys/syscall.h>
20-
#elif defined(_WIN32)
21-
#include <process.h>
22-
#elif defined(__FreeBSD__)
23-
#include <sys/thr.h>
24-
#else
25-
#include <unistd.h>
26-
#endif
27-
#include <time.h>
28-
2917
#include "mongoc-structured-log-private.h"
3018

3119
void
32-
mongoc_structured_log_connection_client_created ()
20+
mongoc_structured_log_connection_client_created (void)
3321
{
3422
mongoc_structured_log (MONGOC_STRUCTURED_LOG_LEVEL_DEBUG,
3523
MONGOC_STRUCTURED_LOG_COMPONENT_CONNECTION,

src/libmongoc/src/mongoc/mongoc-structured-log-private.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
#include "mongoc-prelude.h"
18+
19+
#ifndef MONGOC_STRUCTURED_LOG_PRIVATE_H
20+
#define MONGOC_STRUCTURED_LOG_PRIVATE_H
21+
1822
#include "mongoc-structured-log.h"
1923
#include "mongoc-cmd-private.h"
2024
#include "mongoc-structured-log-command-private.h"
2125

22-
#ifndef MONGOC_STRUCTRURED_LOG_PRIVATE_H
23-
#define MONGOC_STRUCTRURED_LOG_PRIVATE_H
24-
2526
#define MONGOC_STRUCTURED_LOG_DEFAULT_LEVEL MONGOC_STRUCTURED_LOG_LEVEL_WARNING;
2627

2728
typedef void (*mongoc_structured_log_build_message_t) (

src/libmongoc/src/mongoc/mongoc-structured-log.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
#if defined(__linux__)
19-
#include <sys/syscall.h>
20-
#elif defined(_WIN32)
21-
#include <process.h>
22-
#elif defined(__FreeBSD__)
23-
#include <sys/thr.h>
24-
#else
25-
#include <unistd.h>
26-
#endif
27-
#include <stdarg.h>
28-
#include <time.h>
29-
3017
#include "mongoc-structured-log.h"
3118
#include "mongoc-structured-log-private.h"
3219
#include "mongoc-thread-private.h"
20+
#include "mongoc-util-private.h"
3321

3422
static void
3523
mongoc_structured_log_default_handler (mongoc_structured_log_entry_t *entry,
@@ -53,7 +41,7 @@ static void
5341
mongoc_structured_log_entry_destroy (mongoc_structured_log_entry_t *entry)
5442
{
5543
if (entry->structured_message) {
56-
bson_free (entry->structured_message);
44+
bson_destroy (entry->structured_message);
5745
}
5846
}
5947

@@ -114,11 +102,14 @@ mongoc_structured_log (mongoc_structured_log_level_t level,
114102
structured_message_data,
115103
};
116104

105+
bson_once (&once, &_mongoc_ensure_mutex_once);
106+
bson_mutex_lock (&gStructuredLogMutex);
107+
117108
if (!gStructuredLogger) {
109+
bson_mutex_unlock (&gStructuredLogMutex);
118110
return;
119111
}
120112

121-
bson_mutex_lock (&gStructuredLogMutex);
122113
gStructuredLogger (&entry, gStructuredLoggerData);
123114
bson_mutex_unlock (&gStructuredLogMutex);
124115

0 commit comments

Comments
 (0)