Skip to content

Commit 427748b

Browse files
author
Tatiana Azundris Nuernberg
committed
WL#9344: Logging services: error messages
1 parent fad8f09 commit 427748b

File tree

119 files changed

+4940
-2812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4940
-2812
lines changed

components/logging/log_sink_json.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,25 @@ DEFINE_METHOD(int, log_service_imp::variable_update, (log_line *ll))
104104
*/
105105
DEFINE_METHOD(int, log_service_imp::run, (void *inst, log_line *ll))
106106
{
107-
char out_buff[LOG_BUFF_MAX];
108-
char esc_buff[LOG_BUFF_MAX];
109-
const char *inp_readpos;
110-
char *out_writepos= out_buff;
111-
size_t len,
112-
out_left= LOG_BUFF_MAX,
113-
inp_left;
114-
int wellknown_label,
115-
out_fields= 0;
116-
const char *comma= (pretty != JSON_NOSPACE) ? " " : "";
117-
const char *separator;
118-
enum loglevel level= ERROR_LEVEL;
119-
log_item_type item_type= LOG_ITEM_END;
120-
log_type_mask out_types= 0;
121-
log_item_iter *it;
122-
log_item *li;
107+
char out_buff[LOG_BUFF_MAX];
108+
char esc_buff[LOG_BUFF_MAX];
109+
const char *inp_readpos;
110+
char *out_writepos= out_buff;
111+
size_t len,
112+
out_left= LOG_BUFF_MAX,
113+
inp_left;
114+
int wellknown_label,
115+
out_fields= 0;
116+
const char *comma= (pretty != JSON_NOSPACE) ? " " : "";
117+
const char *separator;
118+
enum loglevel level= ERROR_LEVEL;
119+
log_item_type item_type= LOG_ITEM_END;
120+
log_item_type_mask out_types= 0;
121+
log_item_iter *it;
122+
log_item *li;
123+
124+
if (inst == nullptr)
125+
return out_fields;
123126

124127
if (inst == nullptr)
125128
return out_fields;

components/logging/log_sink_syseventlog.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,14 @@ DEFINE_METHOD(int, log_service_imp::variable_update, (log_line *ll))
478478
*/
479479
DEFINE_METHOD(int, log_service_imp::run, (void *instance, log_line *ll))
480480
{
481-
const char *msg= nullptr;
482-
int out_fields= 0;
483-
enum loglevel level= ERROR_LEVEL;
484-
log_item_type item_type= LOG_ITEM_END;
485-
log_type_mask out_types= 0;
486-
487-
log_item_iter *it;
488-
log_item *li;
481+
const char *msg= nullptr;
482+
int out_fields= 0;
483+
enum loglevel level= ERROR_LEVEL;
484+
log_item_type item_type= LOG_ITEM_END;
485+
log_item_type_mask out_types= 0;
486+
487+
log_item_iter *it;
488+
log_item *li;
489489

490490
if (!log_syslog_enabled)
491491
return -1;

components/logging/log_sink_test.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,17 @@ static void banner()
540540
*/
541541
DEFINE_METHOD(int, log_service_imp::run, (void *instance, log_line *ll))
542542
{
543-
char out_buff[LOG_BUFF_MAX];
544-
char *out_writepos= out_buff;
545-
size_t out_left= LOG_BUFF_MAX-1, // remaining bytes in output buffer
546-
len; // length of current output particle
547-
int out_fields= 0, // number of fields in output (retval)
548-
wellknown_label; // index of label in array of wellknowns
549-
enum loglevel level= ERROR_LEVEL; // default severity
550-
log_item_type t= LOG_ITEM_END;
551-
log_type_mask out_types= 0;
552-
log_item_iter *it;
553-
log_item *li;
543+
char out_buff[LOG_BUFF_MAX];
544+
char *out_writepos= out_buff;
545+
size_t out_left= LOG_BUFF_MAX-1, // bytes left in output buffer
546+
len; // length of current output particle
547+
int out_fields= 0, // number of fields in output
548+
wellknown_label; // index of label in wellknowns[]
549+
enum loglevel level= ERROR_LEVEL; // default severity
550+
log_item_type t= LOG_ITEM_END;
551+
log_item_type_mask out_types= 0;
552+
log_item_iter *it;
553+
log_item *li;
554554

555555
/*
556556
If we have detected some sort of massive failure (disk full, out of

components/mysql_server/log_builtins.cc

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ PSI_memory_key key_memory_log_error_stack;
4343
}
4444

4545

46-
// interim interface until pfs exports services
47-
extern bool parse_length_encoded_string(const char **ptr,
48-
char *dest, uint dest_size,
49-
uint *copied_len,
50-
const char *start_ptr,
51-
uint input_length,
52-
bool copy_data,
53-
const CHARSET_INFO *from_cs,
54-
uint nchars_max);
55-
extern bool pfs_copy_connect_attrs(const CHARSET_INFO **cs,
56-
char *buff, uint bufsiz, uint *copied);
57-
5846
/**
5947
We're caching handles to the services used in error logging
6048
as looking them up is costly.
@@ -463,21 +451,30 @@ void log_item_free(log_item *li)
463451

464452

465453
/**
466-
Initialize a log_line. Use buffer "buff" of size "bufsize".
467-
468-
@param buff address of buffer to use
469-
@param bufsize size of buffer to use
454+
Dynamically allocate and initialize a log_line.
470455
471456
@retval nullptr could not set up buffer (too small?)
472457
@retval other address of the newly initialized log_line
473458
*/
474-
log_line *log_line_init(char *buff, size_t bufsize)
459+
log_line *log_line_init()
475460
{
476-
if (bufsize < sizeof(log_line))
477-
return nullptr;
461+
log_line *ll;
462+
if ((ll= (log_line *) my_malloc(key_memory_log_error_stack,
463+
sizeof(log_line), MYF(0))) != nullptr)
464+
memset(ll, 0, sizeof(log_line));
465+
return ll;
466+
}
467+
478468

479-
memset(buff, 0, bufsize);
480-
return (log_line *) buff;
469+
/**
470+
Release a log_line allocated with line_init()
471+
472+
@param ll a log_line previously allocated with line_init()
473+
*/
474+
void log_line_exit(log_line *ll)
475+
{
476+
if (ll != nullptr)
477+
my_free(ll);
481478
}
482479

483480

@@ -492,7 +489,7 @@ log_line *log_line_init(char *buff, size_t bufsize)
492489
*/
493490
bool log_line_full(log_line *ll)
494491
{
495-
return (ll->count >= LOG_ITEM_MAX);
492+
return ((ll == nullptr) || (ll->count >= LOG_ITEM_MAX));
496493
}
497494

498495

@@ -518,9 +515,9 @@ inline bool log_line_item_count(log_line *ll)
518515
@retval 0 not present
519516
@retval !=0 present
520517
*/
521-
log_type_mask log_line_item_types_seen(log_line *ll, log_type_mask m)
518+
log_item_type_mask log_line_item_types_seen(log_line *ll, log_item_type_mask m)
522519
{
523-
return ll->seen & m;
520+
return (ll != nullptr) ? (ll->seen & m) : 0;
524521
}
525522

526523

@@ -991,18 +988,18 @@ const char *log_label_from_prio(int prio)
991988
*/
992989
static int log_sink_trad(void *instance, log_line *ll)
993990
{
994-
const char *label= "",
995-
*msg= "";
996-
int c,
997-
out_fields= 0;
998-
size_t msg_len= 0,
999-
ts_len= 0,
1000-
label_len= 0;
1001-
enum loglevel level= ERROR_LEVEL;
1002-
log_item_type item_type= LOG_ITEM_END;
1003-
log_type_mask out_types= 0;
1004-
const char *iso_timestamp= "";
1005-
my_thread_id thread_id= 0;
991+
const char *label= "",
992+
*msg= "";
993+
int c,
994+
out_fields= 0;
995+
size_t msg_len= 0,
996+
ts_len= 0,
997+
label_len= 0;
998+
enum loglevel level= ERROR_LEVEL;
999+
log_item_type item_type= LOG_ITEM_END;
1000+
log_item_type_mask out_types= 0;
1001+
const char *iso_timestamp= "";
1002+
my_thread_id thread_id= 0;
10061003

10071004
if (ll->count > 0)
10081005
{
@@ -2380,18 +2377,25 @@ DEFINE_METHOD(log_item_data *, log_builtins_imp::line_item_set,
23802377

23812378

23822379
/**
2383-
Initialize a log_line. Use buffer "buff" of size "bufsize".
2384-
2385-
@param buff address of buffer to use
2386-
@param bufsize size of buffer to use
2380+
Dynamically allocate and initialize a log_line.
23872381
23882382
@retval nullptr could not set up buffer (too small?)
23892383
@retval other address of the newly initialized log_line
23902384
*/
2391-
DEFINE_METHOD(log_line *, log_builtins_imp::line_init,
2392-
(char *buff, size_t bufsize))
2385+
DEFINE_METHOD(log_line *, log_builtins_imp::line_init, ())
2386+
{
2387+
return log_line_init();
2388+
}
2389+
2390+
2391+
/**
2392+
Release a log_line allocated with line_init()
2393+
2394+
@param ll a log_line previously allocated with line_init()
2395+
*/
2396+
DEFINE_METHOD(void, log_builtins_imp::line_exit, (log_line *ll))
23932397
{
2394-
return log_line_init(buff, bufsize);
2398+
log_line_exit(ll);
23952399
}
23962400

23972401

@@ -2418,8 +2422,8 @@ DEFINE_METHOD(int, log_builtins_imp::line_item_count,
24182422
@retval 0 not present
24192423
@retval !=0 present
24202424
*/
2421-
DEFINE_METHOD(log_type_mask, log_builtins_imp::line_item_types_seen,
2422-
(log_line *ll, log_type_mask m))
2425+
DEFINE_METHOD(log_item_type_mask, log_builtins_imp::line_item_types_seen,
2426+
(log_line *ll, log_item_type_mask m))
24232427
{
24242428
return log_line_item_types_seen(ll, m);
24252429
}

components/mysql_server/log_builtins_filter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static void log_builtins_filter_defaults()
256256
// "+source_line? delete_field."
257257
// these are not desirable by default, only while debugging.
258258
r= log_builtins_filter_rule_init();
259-
log_item_set(&r->match, LOG_ITEM_SRC_LINE)->data_integer= INFORMATION_LEVEL;
259+
log_item_set(&r->match, LOG_ITEM_SRC_LINE);
260260
r->cond= LOG_FILTER_COND_PRESENT;
261261
r->verb= LOG_FILTER_ITEM_DEL;
262262
// aux optional

components/mysql_server/log_builtins_imp.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ typedef struct _log_item_iter
3131

3232
typedef struct _log_line
3333
{
34-
log_type_mask seen;
35-
log_item_iter iter;
36-
int count;
37-
log_item item[LOG_ITEM_MAX];
34+
log_item_type_mask seen;
35+
log_item_iter iter;
36+
int count;
37+
log_item item[LOG_ITEM_MAX];
3838
} log_line;
3939

4040

@@ -83,13 +83,13 @@ class log_builtins_imp
8383
static DEFINE_METHOD(log_item_data *, line_item_set,
8484
(log_line *ll, log_item_type t));
8585

86-
static DEFINE_METHOD(log_line *, line_init,
87-
(char *buff, size_t bufsize));
86+
static DEFINE_METHOD(log_line *, line_init, ());
87+
static DEFINE_METHOD(void, line_exit, (log_line *ll));
8888
static DEFINE_METHOD(int, line_item_count,
8989
(log_line *ll));
9090

91-
static DEFINE_METHOD(log_type_mask, line_item_types_seen,
92-
(log_line *ll, log_type_mask m));
91+
static DEFINE_METHOD(log_item_type_mask, line_item_types_seen,
92+
(log_line *ll, log_item_type_mask m));
9393

9494
static DEFINE_METHOD(log_item_iter *, line_item_iter_acquire,
9595
(log_line *ll));

components/mysql_server/server_component.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ BEGIN_SERVICE_IMPLEMENTATION(mysql_server, log_builtins)
177177
log_builtins_imp::line_item_set,
178178

179179
log_builtins_imp::line_init,
180+
log_builtins_imp::line_exit,
180181
log_builtins_imp::line_item_count,
181182

182183
log_builtins_imp::line_item_types_seen,

0 commit comments

Comments
 (0)