MySQL  8.0.16
Source Code Documentation
log.h
Go to the documentation of this file.
1 /* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /**
24  @file sql/log.h
25 
26  Error logging, slow query logging, general query logging:
27  If it's server-internal, and it's logging, it's here.
28 
29  Components/services should NOT include this, but include
30  include/mysql/components/services/log_builtins.h instead
31  to gain access to the error logging stack.
32 
33  Legacy plugins (pre-"services") will likely include
34  include/mysql/service_my_plugin_log.h instead.
35 */
36 
37 #ifndef LOG_H
38 #define LOG_H
39 
41 #include <stdarg.h>
42 #include <stddef.h>
43 #include <sys/types.h>
44 
45 #include "lex_string.h"
46 #include "my_command.h"
47 #include "my_compiler.h"
48 #include "my_dbug.h"
49 #include "my_inttypes.h"
50 #include "my_io.h"
51 #include "my_loglevel.h"
52 #include "my_psi_config.h"
53 #include "my_thread_local.h"
57 #include "mysql/psi/mysql_mutex.h"
58 #include "mysql_com.h"
59 #include "sql/auth/sql_security_ctx.h" // Security_context
60 
61 class THD;
62 struct CHARSET_INFO;
63 struct TABLE_LIST;
64 
65 ////////////////////////////////////////////////////////////
66 //
67 // Slow/General Log
68 //
69 ////////////////////////////////////////////////////////////
70 
71 /*
72  System variables controlling logging:
73 
74  log_output (--log-output)
75  Values: NONE, FILE, TABLE
76  Select output destination. Does not enable logging.
77  Can set more than one (e.g. TABLE | FILE).
78 
79  general_log (--general_log)
80  slow_query_log (--slow_query_log)
81  Values: 0, 1
82  Enable/disable general/slow query log.
83 
84  general_log_file (--general-log-file)
85  slow_query_log_file (--slow-query-log-file)
86  Values: filename
87  Set name of general/slow query log file.
88 
89  sql_log_off
90  Values: ON, OFF
91  Enable/disable general query log (OPTION_LOG_OFF).
92 
93  log_queries_not_using_indexes (--log-queries-not-using-indexes)
94  Values: ON, OFF
95  Control slow query logging of queries that do not use indexes.
96 
97  --log-raw
98  Values: ON, OFF
99  Control query rewrite of passwords to the general log.
100 
101  --log-short-format
102  Values: ON, OFF
103  Write short format to the slow query log (and the binary log).
104 
105  --log-slow-admin-statements
106  Values: ON, OFF
107  Log statements such as OPTIMIZE TABLE, ALTER TABLE to the slow query log.
108 
109  --log-slow-slave-statements
110  Values: ON, OFF
111 
112  log_throttle_queries_not_using_indexes
113  Values: INT
114  Number of queries not using indexes logged to the slow query log per min.
115 */
116 
117 /**
118  Write a message to a log (for now just used for error log).
119  This is a variadic convenience interface to the logging components
120  (which use the log_line structure internally), e.g.
121 
122  log_message(LOG_TYPE_ERROR,
123  LOG_ITEM_LOG_PRIO, INFORMATION_LEVEL,
124  LOG_ITEM_LOG_MESSAGE, "file %s is %f %% yellow",
125  filename, yellowfication);
126 
127  For use by legacy sql_print_*(), legacy my_plugin_log_message();
128  also available via the log_builtins service as message().
129 
130  Wherever possible, use the fluent C++ wrapper LogErr()
131  (see log_builtins.h) instead.
132 
133  See log_shared.h for LOG_TYPEs as well as for allowed LOG_ITEM_ types.
134 */
135 int log_vmessage(int log_type, va_list lili);
136 int log_message(int log_type, ...);
137 
138 /**
139  A helper that we can stubify so we don't have to pull all of THD
140  into the unit tests.
141 
142  @param thd a thd
143  @retval its thread-ID
144 */
146 
147 /** Type of the log table */
152 };
153 
154 /**
155  Abstract superclass for handling logging to slow/general logs.
156  Currently has two subclasses, for table and file based logging.
157 */
159  public:
161  virtual ~Log_event_handler() {}
162 
163  /**
164  Log a query to the slow log.
165 
166  @param thd THD of the query
167  @param current_utime Current timestamp in microseconds
168  @param query_start_arg Command start timestamp in microseconds
169  @param user_host The pointer to the string with user\@host info
170  @param user_host_len Length of the user_host string
171  @param query_utime Number of microseconds query execution took
172  @param lock_utime Number of microseconds the query was locked
173  @param is_command The flag which determines whether the sql_text
174  is a query or an administrator command
175  @param sql_text The query or administrator in textual form
176  @param sql_text_len The length of sql_text string
177  @param query_start_status Pointer to a snapshot of thd->status_var taken
178  at the start of execution
179 
180  @return true if error, false otherwise.
181  */
182  virtual bool log_slow(THD *thd, ulonglong current_utime,
183  ulonglong query_start_arg, const char *user_host,
184  size_t user_host_len, ulonglong query_utime,
185  ulonglong lock_utime, bool is_command,
186  const char *sql_text, size_t sql_text_len,
187  struct System_status_var *query_start_status) = 0;
188 
189  /**
190  Log command to the general log.
191 
192  @param thd THD of the query
193  @param event_utime Command start timestamp in micro seconds
194  @param user_host The pointer to the string with user\@host info
195  @param user_host_len Length of the user_host string. this is computed
196  once and passed to all general log event handlers
197  @param thread_id Id of the thread, issued a query
198  @param command_type The type of the command being logged
199  @param command_type_len The length of the string above
200  @param sql_text The very text of the query being executed
201  @param sql_text_len The length of sql_text string
202  @param client_cs Character set to use for strings
203 
204  @return This function attempts to never call my_error(). This is
205  necessary, because general logging happens already after a statement
206  status has been sent to the client, so the client can not see the
207  error anyway. Besides, the error is not related to the statement
208  being executed and is internal, and thus should be handled
209  internally (@todo: how?).
210  If a write to the table has failed, the function attempts to
211  write to a short error message to the file. The failure is also
212  indicated in the return value.
213 
214  @retval false OK
215  @retval true error occured
216  */
217  virtual bool log_general(THD *thd, ulonglong event_utime,
218  const char *user_host, size_t user_host_len,
219  my_thread_id thread_id, const char *command_type,
220  size_t command_type_len, const char *sql_text,
221  size_t sql_text_len,
222  const CHARSET_INFO *client_cs) = 0;
223 };
224 
225 /** Class responsible for table based logging. */
227  public:
228  /** @see Log_event_handler::log_slow(). */
229  virtual bool log_slow(THD *thd, ulonglong current_utime,
230  ulonglong query_start_arg, const char *user_host,
231  size_t user_host_len, ulonglong query_utime,
232  ulonglong lock_utime, bool is_command,
233  const char *sql_text, size_t sql_text_len,
234  struct System_status_var *query_start_status);
235 
236  /** @see Log_event_handler::log_general(). */
237  virtual bool log_general(THD *thd, ulonglong event_utime,
238  const char *user_host, size_t user_host_len,
239  my_thread_id thread_id, const char *command_type,
240  size_t command_type_len, const char *sql_text,
241  size_t sql_text_len, const CHARSET_INFO *client_cs);
242 
243  private:
244  /**
245  Check if log table for given log type exists and can be opened.
246 
247  @param thd Thread handle
248  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
249 
250  @return true if table could not be opened, false otherwise.
251  */
253 
254  friend class Query_logger;
255 };
256 
257 /* Log event handler flags */
258 static const uint LOG_NONE = 1;
259 static const uint LOG_FILE = 2;
260 static const uint LOG_TABLE = 4;
261 
263 
264 /** Class which manages slow and general log event handlers. */
266  /**
267  Currently we have only 2 kinds of logging functions: old-fashioned
268  file logs and csv logging routines.
269  */
270  static const uint MAX_LOG_HANDLERS_NUM = 2;
271 
272  /**
273  RW-lock protecting Query_logger.
274  R-lock taken when writing to slow/general query log.
275  W-lock taken when activating/deactivating logs.
276  */
278 
279  /** Available log handlers. */
282 
283  /** NULL-terminated arrays of log handlers. */
286 
287  private:
288  /**
289  Setup log event handlers for the given log_type.
290 
291  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
292  @param log_printer Bitmap of LOG_NONE, LOG_FILE, LOG_TABLE
293  */
295 
296  public:
298 
299  /**
300  Check if table logging is turned on for the given log_type.
301 
302  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
303 
304  @return true if table logging is on, false otherwise.
305  */
307 
308  /**
309  Check if file logging is turned on for the given log type.
310 
311  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
312 
313  @return true if the file logging is on, false otherwise.
314  */
316 
317  /**
318  Perform basic log initialization: create file-based log handler.
319 
320  We want to initialize all log mutexes as soon as possible,
321  but we cannot do it in constructor, as safe_mutex relies on
322  initialization, performed by MY_INIT(). This why this is done in
323  this function.
324  */
325  void init();
326 
327  /** Free memory. Nothing could be logged after this function is called. */
328  void cleanup();
329 
330  /**
331  Log slow query with all enabled log event handlers.
332 
333  @param thd THD of the statement being logged.
334  @param query The query string being logged.
335  @param query_length The length of the query string.
336  @param query_start_status Pointer to a snapshot of thd->status_var taken
337  at the start of execution
338 
339  @return true if error, false otherwise.
340  */
341  bool slow_log_write(THD *thd, const char *query, size_t query_length,
342  struct System_status_var *query_start_status);
343 
344  /**
345  Write printf style message to general query log.
346 
347  @param thd THD of the statement being logged.
348  @param command COM of statement being logged.
349  @param format Printf style format of message.
350  @param ... Printf parameters to write.
351 
352  @return true if error, false otherwise.
353  */
355  const char *format, ...)
356  MY_ATTRIBUTE((format(printf, 4, 5)));
357 
358  /**
359  Write query to general query log.
360 
361  @param thd THD of the statement being logged.
362  @param command COM of statement being logged.
363  @param query The query string being logged.
364  @param query_length The length of the query string.
365 
366  @return true if error, false otherwise.
367  */
369  const char *query, size_t query_length);
370 
371  /**
372  Enable log event handlers for slow/general log.
373 
374  @param log_printer Bitmask of log event handlers.
375 
376  @note Acceptable values are LOG_NONE, LOG_FILE, LOG_TABLE
377  */
378  void set_handlers(ulonglong log_printer);
379 
380  /**
381  Activate log handlers for the given log type.
382 
383  @param thd Thread handle
384  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
385 
386  @return true if error, false otherwise.
387  */
389 
390  /**
391  Close file log for the given log type.
392 
393  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
394  */
396 
397  /**
398  Close file log for the given log type and the reopen it.
399 
400  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
401  */
403 
404  /**
405  Read log file name from global variable opt_*_logname.
406  If called from a sys_var update function, the caller
407  must hold a lock protecting the sys_var
408  (LOCK_global_system_variables, a polylock for the
409  variable, etc.).
410 
411  @param log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
412  */
414 
415  /**
416  Check if given TABLE_LIST has a query log table name and
417  optionally check if the query log is currently enabled.
418 
419  @param table_list TABLE_LIST representing the table to check
420  @param check_if_opened Always return QUERY_LOG_NONE unless the
421  query log table is enabled.
422 
423  @retval QUERY_LOG_NONE, QUERY_LOG_SLOW or QUERY_LOG_GENERAL
424  */
426  bool check_if_opened) const;
427 };
428 
430 
431 /**
432  Create the name of the query log specified.
433 
434  This method forms a new path + file name for the log specified.
435 
436  @param[in] buff Location for building new string.
437  @param[in] log_type QUERY_LOG_SLOW or QUERY_LOG_GENERAL
438 
439  @returns Pointer to new string containing the name.
440 */
442 
443 /**
444  Check given log name against certain blacklisted names/extensions.
445 
446  @param name Log name to check
447  @param len Length of log name
448 
449  @returns true if name is valid, false otherwise.
450 */
451 bool is_valid_log_name(const char *name, size_t len);
452 
453 /**
454  Check whether we need to write the current statement (or its rewritten
455  version if it exists) to the slow query log.
456  As a side-effect, a digest of suppressed statements may be written.
457 
458  @param thd thread handle
459 
460  @retval
461  true statement needs to be logged
462  @retval
463  false statement does not need to be logged
464 */
465 bool log_slow_applicable(THD *thd);
466 
467 /**
468  Unconditionally writes the current statement (or its rewritten version if it
469  exists) to the slow query log.
470 
471  @param thd thread handle
472  @param query_start_status Pointer to a snapshot of thd->status_var taken
473  at the start of execution
474 */
475 void log_slow_do(THD *thd, struct System_status_var *query_start_status);
476 
477 /**
478  Check whether we need to write the current statement to the slow query
479  log. If so, do so. This is a wrapper for the two functions above;
480  most callers should use this wrapper. Only use the above functions
481  directly if you have expensive rewriting that you only need to do if
482  the query actually needs to be logged (e.g. SP variables / NAME_CONST
483  substitution when executing a PROCEDURE).
484  A digest of suppressed statements may be logged instead of the current
485  statement.
486 
487  @param thd thread handle
488  @param query_start_status Pointer to a snapshot of thd->status_var taken
489  at the start of execution
490 */
491 void log_slow_statement(THD *thd, struct System_status_var *query_start_status);
492 
493 /**
494  @class Log_throttle
495  @brief Base class for rate-limiting a log (slow query log etc.)
496 */
497 
499  /**
500  When will/did current window end?
501  */
503 
504  /**
505  Log no more than rate lines of a given type per window_size
506  (e.g. per minute, usually LOG_THROTTLE_WINDOW_SIZE).
507  */
509 
510  /**
511  There have been this many lines of this type in this window,
512  including those that we suppressed. (We don't simply stop
513  counting once we reach the threshold as we'll write a summary
514  of the suppressed lines later.)
515  */
517 
518  protected:
519  /**
520  Template for the summary line. Should contain %lu as the only
521  conversion specification.
522  */
523  const char *summary_template;
524 
525  /**
526  Start a new window.
527  */
528  void new_window(ulonglong now);
529 
530  /**
531  Increase count of logs we're handling.
532 
533  @param rate Limit on records to be logged during the throttling window.
534 
535  @retval true - log rate limit is exceeded, so record should be supressed.
536  @retval false - log rate limit is not exceeded, record should be logged.
537  */
538  bool inc_log_count(ulong rate) { return (++count > rate); }
539 
540  /**
541  Check whether we're still in the current window. (If not, the caller
542  will want to print a summary (if the logging of any lines was suppressed),
543  and start a new window.)
544  */
545  bool in_window(ulonglong now) const { return (now < window_end); }
546 
547  /**
548  Prepare a summary of suppressed lines for logging.
549  This function returns the number of queries that were qualified for
550  inclusion in the log, but were not printed because of the rate-limiting.
551  The summary will contain this count as well as the respective totals for
552  lock and execution time.
553  This function assumes that the caller already holds the necessary locks.
554 
555  @param rate Limit on records logged during the throttling window.
556  */
557  ulong prepare_summary(ulong rate);
558 
559  /**
560  @param window_usecs ... in this many micro-seconds
561  @param msg use this template containing %lu as only non-literal
562  */
563  Log_throttle(ulong window_usecs, const char *msg)
564  : window_end(0),
565  window_size(window_usecs),
566  count(0),
567  summary_template(msg) {}
568 
569  public:
570  /**
571  We're rate-limiting messages per minute; 60,000,000 microsecs = 60s
572  Debugging is less tedious with a window in the region of 5000000
573  */
574  static const ulong LOG_THROTTLE_WINDOW_SIZE = 60000000;
575 };
576 
577 /**
578  @class Slow_log_throttle
579  @brief Used for rate-limiting the slow query log.
580 */
581 
583  private:
584  /**
585  We're using our own (empty) security context during summary generation.
586  That way, the aggregate value of the suppressed queries isn't printed
587  with a specific user's name (i.e. the user who sent a query when or
588  after the time-window closes), as that would be misleading.
589  */
591 
592  /**
593  Total of the execution times of queries in this time-window for which
594  we suppressed logging. For use in summary printing.
595  */
597 
598  /**
599  Total of the lock times of queries in this time-window for which
600  we suppressed logging. For use in summary printing.
601  */
603 
604  /**
605  A reference to the threshold ("no more than n log lines per ...").
606  References a (system-?) variable in the server.
607  */
609 
610  /**
611  The routine we call to actually log a line (i.e. our summary).
612  The signature miraculously coincides with slow_log_print().
613  */
614  bool (*log_summary)(THD *, const char *, size_t, struct System_status_var *);
615 
616  /**
617  Slow_log_throttle is shared between THDs.
618  */
620 
621  /**
622  Start a new window.
623  */
624  void new_window(ulonglong now);
625 
626  /**
627  Actually print the prepared summary to log.
628  */
629  void print_summary(THD *thd, ulong suppressed, ulonglong print_lock_time,
630  ulonglong print_exec_time);
631 
632  public:
633  /**
634  @param threshold suppress after this many queries ...
635  @param lock mutex to use for consistency of calculations
636  @param window_usecs ... in this many micro-seconds
637  @param logger call this function to log a single line (our summary)
638  @param msg use this template containing %lu as only non-literal
639  */
640  Slow_log_throttle(ulong *threshold, mysql_mutex_t *lock, ulong window_usecs,
641  bool (*logger)(THD *, const char *, size_t,
642  struct System_status_var *),
643  const char *msg);
644 
645  /**
646  Prepare and print a summary of suppressed lines to log.
647  (For now, slow query log.)
648  The summary states the number of queries that were qualified for
649  inclusion in the log, but were not printed because of the rate-limiting,
650  and their respective totals for lock and execution time.
651  This wrapper for prepare_summary() and print_summary() handles the
652  locking/unlocking.
653 
654  @param thd The THD that tries to log the statement.
655  @retval false Logging was not supressed, no summary needed.
656  @retval true Logging was supressed; a summary was printed.
657  */
658  bool flush(THD *thd);
659 
660  /**
661  Top-level function.
662  @param thd The THD that tries to log the statement.
663  @param eligible Is the statement of the type we might suppress?
664  @retval true Logging should be supressed.
665  @retval false Logging should not be supressed.
666  */
667  bool log(THD *thd, bool eligible);
668 };
669 
670 /**
671  @class Slow_log_throttle
672  @brief Used for rate-limiting a error logs.
673 */
674 
676  private:
679  const char *subsys;
680 
681  /**
682  Actually print the prepared summary to log.
683  */
684  void print_summary(ulong suppressed) {
687  subsys, LOG_ITEM_LOG_MESSAGE, summary_template,
688  (unsigned long)suppressed);
689  }
690 
691  public:
692  /**
693  @param window_usecs ... in this many micro-seconds (see Log_throttle)
694  @param lvl severity of the incident (error, warning, info)
695  @param errcode MySQL error code (e.g. ER_STARTUP)
696  @param subsystem subsystem tag, or nullptr for none
697  @param msg use this message template containing %lu as only
698  non-literal (for "number of suppressed events",
699  see Log_throttle)
700  */
701  Error_log_throttle(ulong window_usecs, loglevel lvl, uint errcode,
702  const char *subsystem, const char *msg)
703  : Log_throttle(window_usecs, msg),
704  ll(lvl),
705  err_code(errcode),
706  subsys(subsystem) {}
707 
708  /**
709  Prepare and print a summary of suppressed lines to log.
710  (For now, slow query log.)
711  The summary states the number of queries that were qualified for
712  inclusion in the log, but were not printed because of the rate-limiting.
713 
714  @retval false Logging was not suppressed, no summary needed.
715  @retval true Logging was suppressed; a summary was printed.
716  */
717  bool flush();
718 
719  /**
720  Top-level function.
721  @retval true Logging should be suppressed.
722  @retval false Logging should not be suppressed.
723  */
724  bool log();
725 };
726 
728 
729 ////////////////////////////////////////////////////////////
730 //
731 // Error Log
732 //
733 ////////////////////////////////////////////////////////////
734 
735 /*
736  Set up some convenience defines to help us while we change
737  old-style ("sql_print_...()") calls to new-style ones
738  ("LogErr(...)"). New code should not use these, nor should
739  it use sql_print_...().
740 */
741 
742 /**
743  Set up basics, fetch message for "errcode", insert any va_args,
744  call the new error stack. A helper for the transition to the
745  new stack.
746 */
747 #define log_errlog(level, errcode, ...) \
748  log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
749  LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
750  (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
751  LOG_ITEM_LOG_LOOKUP, (longlong)errcode, ##__VA_ARGS__)
752 
753 /**
754  Default tags + freeform message. A helper for re#defining sql_print_*()
755  to go through the new error log service stack.
756 
757  Remember to never blindly LOG_MESSAGE a string you that may contain
758  user input as it may contain % which will be treated as substitutions.
759 
760  BAD: LOG_ITEM_LOG_MESSAGE, dodgy_message
761  OK: LOG_ITEM_LOG_MESSAGE, "%s", dodgy_message
762  GOOD: LOG_ITEM_LOG_VERBATIM, dodgy_message
763 */
764 #define log_errlog_formatted(level, ...) \
765  log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
766  LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
767  (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, \
768  LOG_ITEM_LOG_MESSAGE, ##__VA_ARGS__)
769 
770 /**
771  Set up the default tags, then let us add/override any key/value we like,
772  call the new error stack. A helper for the transition to the new stack.
773 */
774 #define log_errlog_rich(level, ...) \
775  log_message(LOG_TYPE_ERROR, LOG_ITEM_LOG_PRIO, (longlong)level, \
776  LOG_ITEM_SRV_SUBSYS, LOG_SUBSYSTEM_TAG, LOG_ITEM_SRC_LINE, \
777  (longlong)__LINE__, LOG_ITEM_SRC_FILE, MY_BASENAME, __VA_ARGS__)
778 
779 /**
780  Define sql_print_*() so they use the new log_message()
781  variadic convenience interface to logging. This lets
782  us switch over the bulk of the messages right away until
783  we can attend to them individually; it also verifies that
784  we no longer use function pointers to log functions.
785 
786  As before, sql_print_*() only accepts a printf-style
787  format string, and the arguments to same, if any.
788 */
789 #define sql_print_information(...) \
790  log_errlog_formatted(INFORMATION_LEVEL, ##__VA_ARGS__)
791 
792 #define sql_print_warning(...) \
793  log_errlog_formatted(WARNING_LEVEL, ##__VA_ARGS__)
794 
795 #define sql_print_error(...) log_errlog_formatted(ERROR_LEVEL, ##__VA_ARGS__)
796 
797 /**
798  Prints a printf style message to the error log.
799 
800  A thin wrapper around log_message() for local_message_hook,
801  Table_check_intact::report_error, and others.
802 
803  @param level The level of the msg significance
804  @param ecode Error code of the error message.
805  @param args va_list list of arguments for the message
806 */
807 void error_log_print(enum loglevel level, uint ecode, va_list args);
808 
809 /**
810  Initialize structures (e.g. mutex) needed by the error log.
811 
812  @note This function accesses shared resources without protection, so
813  it should only be called while the server is running single-threaded.
814 
815  @note The error log can still be used before this function is called,
816  but that should only be done single-threaded.
817 
818  @retval true an error occurred
819  @retval false basic error logging is now available in multi-threaded mode
820 */
821 bool init_error_log();
822 
823 /**
824  Open the error log and redirect stderr and optionally stdout
825  to the error log file. The streams are reopened only for
826  appending (writing at end of file).
827 
828  @note
829  On error, my_error() is not called here.
830  So, caller of this function should call my_error() to keep the protocol.
831 
832  @note This function also writes any error log messages that
833  have been buffered by calling flush_error_log_messages().
834 
835  @param filename Name of error log file
836  @param get_lock Should we acquire LOCK_error_log?
837 */
838 bool open_error_log(const char *filename, bool get_lock);
839 
840 /**
841  Free any error log resources.
842 
843  @note This function accesses shared resources without protection, so
844  it should only be called while the server is running single-threaded.
845 
846  @note The error log can still be used after this function is called,
847  but that should only be done single-threaded. All buffered messages
848  should be flushed before calling this function.
849 */
850 void destroy_error_log();
851 
852 /**
853  Flush any pending data to disk and reopen the error log.
854 */
855 bool reopen_error_log();
856 
857 /**
858  Discard all buffered messages and deallocate buffer without printing
859  anything. Needed when terminating launching process after daemon
860  has started. At this point we may have messages in the error log,
861  but we don't want to show them to stderr (the daemon will output
862  them in its error log).
863  */
865 
866 /**
867  We buffer all error log messages that have been printed before the
868  error log has been opened. This allows us to write them to the
869  correct file once the error log has been opened.
870 
871  This function will explicitly flush buffered messages to stderr.
872  It is only needed in cases where open_error_log() is not called
873  as it otherwise will be done there.
874 
875  This function also turns buffering off (there is no way to turn
876  buffering back on).
877 */
879 
880 /**
881  Modular logger: log line and key/value manipulation helpers.
882  Server-internal. External services should access these via
883  the log_builtins service API (cf. preamble for this file).
884 */
885 
886 /**
887  Compare two NUL-terminated byte strings
888 
889  Note that when comparing without length limit, the long string
890  is greater if they're equal up to the length of the shorter
891  string, but the shorter string will be considered greater if
892  its "value" up to that point is greater:
893 
894  compare 'abc','abcd': -100 (longer wins if otherwise same)
895  compare 'abca','abcd': -3 (higher value wins)
896  compare 'abcaaaaa','abcd': -3 (higher value wins)
897 
898  @param a the first string
899  @param b the second string
900  @param len compare at most this many characters --
901  0 for no limit
902  @param case_insensitive ignore upper/lower case in comparison
903 
904  @retval -1 a < b
905  @retval 0 a == b
906  @retval 1 a > b
907 */
908 int log_string_compare(const char *a, const char *b, size_t len,
909  bool case_insensitive);
910 
911 /**
912  Predicate used to determine whether a type is generic
913  (generic string, generic float, generic integer) rather
914  than a well-known type.
915 
916  @param t log item type to examine
917 
918  @retval true if generic type
919  @retval false if wellknown type
920 */
922 
923 /**
924  Predicate used to determine whether a class is a string
925  class (C-string or Lex-string).
926 
927  @param c log item class to examine
928 
929  @retval true if of a string class
930  @retval false if not of a string class
931 */
933 
934 /**
935  Predicate used to determine whether a class is a numeric
936  class (integer or float).
937 
938  @param c log item class to examine
939 
940  @retval true if of a numeric class
941  @retval false if not of a numeric class
942 */
944 
945 /**
946  Get an integer value from a log-item of float or integer type.
947 
948  @param li log item to get the value from
949  @param i longlong to store the value in
950 */
951 void log_item_get_int(log_item *li, longlong *i);
952 
953 /**
954  Get a float value from a log-item of float or integer type.
955 
956  @param li log item to get the value from
957  @param f float to store the value in
958 */
959 void log_item_get_float(log_item *li, double *f);
960 
961 /**
962  Get a string value from a log-item of C-string or Lex string type.
963 
964  @param li log item to get the value from
965  @param str char-pointer to store the pointer to the value in
966  @param len size_t pointer to store the length of the value in
967 */
968 void log_item_get_string(log_item *li, char **str, size_t *len);
969 
970 /**
971  Set an integer value on a log_item.
972  Fails gracefully if not log_item_data is supplied, so it can safely
973  wrap log_line_item_set[_with_key]().
974 
975  @param lid log_item_data struct to set the value on
976  @param i integer to set
977 
978  @retval true lid was nullptr (possibly: OOM, could not set up log_item)
979  @retval false all's well
980 */
982 
983 /**
984  Set a floating point value on a log_item.
985  Fails gracefully if not log_item_data is supplied, so it can safely
986  wrap log_line_item_set[_with_key]().
987 
988  @param lid log_item_data struct to set the value on
989  @param f float to set
990 
991  @retval true lid was nullptr (possibly: OOM, could not set up log_item)
992  @retval false all's well
993 */
994 bool log_item_set_float(log_item_data *lid, double f);
995 
996 /**
997  Set a string value on a log_item.
998  Fails gracefully if not log_item_data is supplied, so it can safely
999  wrap log_line_item_set[_with_key]().
1000 
1001  @param lid log_item_data struct to set the value on
1002  @param s pointer to string
1003  @param s_len length of string
1004 
1005  @retval true lid was nullptr (possibly: OOM, could not set up log_item)
1006  @retval false all's well
1007 */
1008 bool log_item_set_lexstring(log_item_data *lid, const char *s, size_t s_len);
1009 
1010 /**
1011  Set a string value on a log_item.
1012  Fails gracefully if not log_item_data is supplied, so it can safely
1013  wrap log_line_item_set[_with_key]().
1014 
1015  @param lid log_item_data struct to set the value on
1016  @param s pointer to NTBS
1017 
1018  @retval true lid was nullptr (possibly: OOM, could not set up log_item)
1019  @retval false all's well
1020 */
1021 bool log_item_set_cstring(log_item_data *lid, const char *s);
1022 
1023 /**
1024  See whether a string is a wellknown field name.
1025 
1026  @param key potential key starts here
1027  @param len length of the string to examine
1028 
1029  @retval LOG_ITEM_TYPE_RESERVED: reserved, but not "wellknown" key
1030  @retval LOG_ITEM_TYPE_NOT_FOUND: key not found
1031  @retval >0: index in array of wellknowns
1032 */
1033 int log_item_wellknown_by_name(const char *key, size_t len);
1034 
1035 /**
1036  See whether a type is wellknown.
1037 
1038  @param t log item type to examine
1039 
1040  @retval LOG_ITEM_TYPE_NOT_FOUND: key not found
1041  @retval >0: index in array of wellknowns
1042 */
1044 
1045 /**
1046  Accessor: from a record describing a wellknown key, get its name
1047 
1048  @param idx index in array of wellknowns, see log_item_wellknown_by_...()
1049 
1050  @retval name (NTBS)
1051 */
1052 const char *log_item_wellknown_get_name(uint idx);
1053 
1054 /**
1055  Accessor: from a record describing a wellknown key, get its type
1056 
1057  @param idx index in array of wellknowns, see log_item_wellknown_by_...()
1058 
1059  @retval the log item type for the wellknown key
1060 */
1062 
1063 /**
1064  Accessor: from a record describing a wellknown key, get its class
1065 
1066  @param idx index in array of wellknowns, see log_item_wellknown_by_...()
1067 
1068  @retval the log item class for the wellknown key
1069 */
1071 
1072 /**
1073  Release any of key and value on a log-item that were dynamically allocated.
1074 
1075  @param li log-item to release the payload of
1076 */
1077 void log_item_free(log_item *li);
1078 
1079 /**
1080  Predicate indicating whether a log line is "willing" to accept any more
1081  key/value pairs.
1082 
1083  @param ll the log-line to examine
1084 
1085  @retval false if not full / if able to accept another log_item
1086  @retval true if full
1087 */
1088 bool log_line_full(log_line *ll);
1089 
1090 /**
1091  How many items are currently set on the given log_line?
1092 
1093  @param ll the log-line to examine
1094 
1095  @retval the number of items set
1096 */
1097 int log_line_item_count(log_line *ll);
1098 
1099 /**
1100  Test whether a given type is presumed present on the log line.
1101 
1102  @param ll the log_line to examine
1103  @param m the log_type to test for
1104 
1105  @retval 0 not present
1106  @retval !=0 present
1107 */
1109 
1110 /**
1111  Initialize a log_line.
1112 
1113  @retval nullptr could not set up buffer (too small?)
1114  @retval other address of the newly initialized log_line
1115 */
1117 
1118 /**
1119  Release a log_line allocated with log_line_init.
1120 
1121  @retval nullptr could not set up buffer (too small?)
1122  @retval other address of the newly initialized log_line
1123 */
1124 void log_line_exit(log_line *ll);
1125 
1126 /**
1127  Release log line item (key/value pair) with the index elem in log line ll.
1128  This frees whichever of key and value were dynamically allocated.
1129  This leaves a "gap" in the bag that may immediately be overwritten
1130  with an updated element. If the intention is to remove the item without
1131  replacing it, use log_line_item_remove() instead!
1132 
1133  @param ll log_line
1134  @param elem index of the key/value pair to release
1135 */
1136 void log_line_item_free(log_line *ll, size_t elem);
1137 
1138 /**
1139  Release all log line items (key/value pairs) in log line ll.
1140  This frees whichever keys and values were dynamically allocated.
1141 
1142  @param ll log_line
1143 */
1145 
1146 /**
1147  Release log line item (key/value pair) with the index elem in log line ll.
1148  This frees whichever of key and value were dynamically allocated.
1149  This moves any trailing items to fill the "gap" and decreases the counter
1150  of elements in the log line. If the intention is to leave a "gap" in the
1151  bag that may immediately be overwritten with an updated element, use
1152  log_line_item_free() instead!
1153 
1154  @param ll log_line
1155  @param elem index of the key/value pair to release
1156 */
1157 void log_line_item_remove(log_line *ll, int elem);
1158 
1159 /**
1160  Find the (index of the) last key/value pair of the given name
1161  in the log line.
1162 
1163  @param ll log line
1164  @param key the key to look for
1165 
1166  @retval -1: none found
1167  @retval -2: invalid search-key given
1168  @retval -3: no log_line given
1169  @retval >=0: index of the key/value pair in the log line
1170 */
1171 int log_line_index_by_name(log_line *ll, const char *key);
1172 
1173 /**
1174  Find the last item matching the given key in the log line.
1175 
1176  @param ll log line
1177  @param key the key to look for
1178 
1179  @retval nullptr item not found
1180  @retval otherwise pointer to the item (not a copy thereof!)
1181 */
1182 log_item *log_line_item_by_name(log_line *ll, const char *key);
1183 
1184 /**
1185  Find the (index of the) first key/value pair of the given type
1186  in the log line.
1187 
1188  @param ll log line
1189  @param t the log item type to look for
1190 
1191  @retval <0: none found
1192  @retval >=0: index of the key/value pair in the log line
1193 */
1195 
1196 /**
1197  Find the (index of the) first key/value pair of the given type
1198  in the log line. This variant accepts a reference item and looks
1199  for an item that is of the same type (for wellknown types), or
1200  one that is of a generic type, and with the same key name (for
1201  generic types). For example, a reference item containing a
1202  generic string with key "foo" will a generic string, integer, or
1203  float with the key "foo".
1204 
1205  @param ll log line
1206  @param ref a reference item of the log item type to look for
1207 
1208  @retval <0: none found
1209  @retval >=0: index of the key/value pair in the log line
1210 */
1212 
1213 /**
1214  Initializes a log entry for use. This simply puts it in a defined
1215  state; if you wish to reset an existing item, see log_item_free().
1216 
1217  @param li the log-item to initialize
1218 */
1219 void log_item_init(log_item *li);
1220 
1221 /**
1222  Initializes an entry in a log line for use. This simply puts it in
1223  a defined state; if you wish to reset an existing item, see
1224  log_item_free().
1225  This resets the element beyond the last. The element count is not
1226  adjusted; this is for the caller to do once it sets up a valid
1227  element to suit its needs in the cleared slot. Finally, it is up
1228  to the caller to make sure that an element can be allocated.
1229 
1230  @param ll the log-line to initialize a log_item in
1231 
1232  @retval the address of the cleared log_item
1233 */
1235 
1236 /**
1237  Create new log item with key name "key", and allocation flags of
1238  "alloc" (see enum_log_item_free).
1239  Will return a pointer to the item's log_item_data struct for
1240  convenience.
1241  This is mostly interesting for filters and other services that create
1242  items that are not part of a log_line; sources etc. that intend to
1243  create an item for a log_line (the more common case) should usually
1244  use the below line_item_set_with_key() which creates an item (like
1245  this function does), but also correctly inserts it into a log_line.
1246 
1247  @param li the log_item to work on
1248  @param t the item-type
1249  @param key the key to set on the item.
1250  ignored for non-generic types (may pass nullptr for those)
1251  see alloc
1252  @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller
1253  LOG_ITEM_FREE_NONE if key was not allocated
1254  Allocated keys will automatically free()d when the
1255  log_item is.
1256  The log_item's alloc flags will be set to the
1257  submitted value; specifically, any pre-existing
1258  value will be clobbered. It is therefore WRONG
1259  a) to use this on a log_item that already has a key;
1260  it should only be used on freshly init'd log_items;
1261  b) to use this on a log_item that already has a
1262  value (specifically, an allocated one); the correct
1263  order is to init a log_item, then set up type and
1264  key, and finally to set the value. If said value is
1265  an allocated string, the log_item's alloc should be
1266  bitwise or'd with LOG_ITEM_FREE_VALUE.
1267 
1268  @retval a pointer to the log_item's log_data, for easy chaining:
1269  log_item_set_with_key(...)->data_integer= 1;
1270 */
1272  const char *key, uint32 alloc);
1273 
1274 /**
1275  Create new log item in log line "ll", with key name "key", and
1276  allocation flags of "alloc" (see enum_log_item_free).
1277  It is up to the caller to ensure the log_line can accept more items
1278  (e.g. by using log_line_full(ll)).
1279  On success, the number of registered items on the log line is increased,
1280  the item's type is added to the log_line's "seen" property,
1281  and a pointer to the item's log_item_data struct is returned for
1282  convenience.
1283 
1284  @param ll the log_line to work on
1285  @param t the item-type
1286  @param key the key to set on the item.
1287  ignored for non-generic types (may pass nullptr for those)
1288  see alloc
1289  @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller
1290  LOG_ITEM_FREE_NONE if key was not allocated
1291  Allocated keys will automatically free()d when the
1292  log_item is.
1293  The log_item's alloc flags will be set to the
1294  submitted value; specifically, any pre-existing
1295  value will be clobbered. It is therefore WRONG
1296  a) to use this on a log_item that already has a key;
1297  it should only be used on freshly init'd log_items;
1298  b) to use this on a log_item that already has a
1299  value (specifically, an allocated one); the correct
1300  order is to init a log_item, then set up type and
1301  key, and finally to set the value. If said value is
1302  an allocated string, the log_item's alloc should be
1303  bitwise or'd with LOG_ITEM_FREE_VALUE.
1304 
1305  @retval a pointer to the log_item's log_data, for easy chaining:
1306  log_line_item_set_with_key(...)->data_integer= 1;
1307 */
1309  const char *key, uint32 alloc);
1310 
1311 /**
1312  As log_item_set_with_key(), except that the key is automatically
1313  derived from the wellknown log_item_type t.
1314 
1315  Create new log item with type "t".
1316  Will return a pointer to the item's log_item_data struct for
1317  convenience.
1318  This is mostly interesting for filters and other services that create
1319  items that are not part of a log_line; sources etc. that intend to
1320  create an item for a log_line (the more common case) should usually
1321  use the below line_item_set_with_key() which creates an item (like
1322  this function does), but also correctly inserts it into a log_line.
1323 
1324  The allocation of this item will be LOG_ITEM_FREE_NONE;
1325  specifically, any pre-existing value will be clobbered.
1326  It is therefore WRONG
1327  a) to use this on a log_item that already has a key;
1328  it should only be used on freshly init'd log_items;
1329  b) to use this on a log_item that already has a
1330  value (specifically, an allocated one); the correct
1331  order is to init a log_item, then set up type and
1332  key, and finally to set the value. If said value is
1333  an allocated string, the log_item's alloc should be
1334  bitwise or'd with LOG_ITEM_FREE_VALUE.
1335 
1336  @param li the log_item to work on
1337  @param t the item-type
1338 
1339  @retval a pointer to the log_item's log_data, for easy chaining:
1340  log_item_set_with_key(...)->data_integer= 1;
1341 */
1343 
1344 /**
1345  Create a new log item of well-known type "t" in log line "ll".
1346  On success, the number of registered items on the log line is increased,
1347  the item's type is added to the log_line's "seen" property,
1348  and a pointer to the item's log_item_data struct is returned for
1349  convenience.
1350 
1351  It is up to the caller to ensure the log_line can accept more items
1352  (e.g. by using log_line_full(ll)).
1353 
1354  The allocation of this item will be LOG_ITEM_FREE_NONE;
1355  specifically, any pre-existing value will be clobbered.
1356  It is therefore WRONG
1357  a) to use this on a log_item that already has a key;
1358  it should only be used on freshly init'd log_items;
1359  b) to use this on a log_item that already has a
1360  value (specifically, an allocated one); the correct
1361  order is to init a log_item, then set up type and
1362  key, and finally to set the value. If said value is
1363  an allocated string, the log_item's alloc should be
1364  bitwise or'd with LOG_ITEM_FREE_VALUE.
1365 
1366  @param ll the log_line to work on
1367  @param t the item-type
1368 
1369  @retval a pointer to the log_item's log_data, for easy chaining:
1370  log_line_item_set_with_key(...)->data_integer= 1;
1371 */
1373 
1374 /**
1375  Convenience function: Derive a log label ("error", "warning",
1376  "information") from a severity.
1377 
1378  @param prio the severity/prio in question
1379 
1380  @return a label corresponding to that priority.
1381  @retval "ERROR" for prio of ERROR_LEVEL or higher
1382  @retval "Warning" for prio of WARNING_LEVEL
1383  @retval "Note" otherwise
1384 */
1385 const char *log_label_from_prio(int prio);
1386 
1387 /**
1388  Complete, filter, and write submitted log items.
1389 
1390  This expects a log_line collection of log-related key/value pairs,
1391  e.g. from log_message().
1392 
1393  Where missing, timestamp, priority, thread-ID (if any) and so forth
1394  are added.
1395 
1396  Log item source services, log item filters, and log item sinks are
1397  then called.
1398 
1399  @param ll key/value pairs describing info to log
1400 
1401  @retval int number of fields in created log line
1402 */
1403 int log_line_submit(log_line *ll);
1404 
1405 /**
1406  Make and return an ISO 8601 / RFC 3339 compliant timestamp.
1407  Heeds log_timestamps.
1408 
1409  @param buf A buffer of at least 26 bytes to store
1410  the timestamp in (19 + tzinfo tail + \0)
1411  @param utime Microseconds since the epoch
1412  @param mode if 0, use UTC; if 1, use local time
1413 
1414  @retval length of timestamp (excluding \0)
1415 */
1416 int make_iso8601_timestamp(char *buf, ulonglong utime, int mode);
1417 
1418 /**
1419  Set up custom error logging stack.
1420 
1421  @param conf The configuration string
1422  @param check_only If true, report on whether configuration is valid
1423  (i.e. whether all requested services are available),
1424  but do not apply the new configuration.
1425  if false, set the configuration (acquire the
1426  necessary services, update the hash by
1427  adding/deleting entries as necessary)
1428  @param[out] pos If an error occurs and this pointer is non-null,
1429  the position in the configuration string where
1430  the error occurred will be written to the
1431  pointed-to size_t.
1432 
1433  @retval 0 success
1434  @retval -1 expected delimiter not found
1435  @retval -2 one or more services not found
1436  @retval -3 failed to create service cache entry
1437  @retval -4 tried to open multiple instances of a singleton
1438  @retval -5 failed to create service instance entry
1439  @retval -6 last element in pipeline should be a sink
1440  @retval -101 service name may not start with a delimiter
1441  @retval -102 delimiters ',' and ';' may not be mixed
1442 */
1443 int log_builtins_error_stack(const char *conf, bool check_only, size_t *pos);
1444 
1445 /**
1446  Call flush() on all log_services.
1447  flush() function must not try to log anything, as we hold an
1448  exclusive lock on the stack.
1449 
1450  @retval 0 no problems
1451  @retval -1 error
1452 */
1454 
1455 /**
1456  Initialize the structured logging subsystem.
1457 
1458  Since we're initializing various locks here, we must call this late enough
1459  so this is clean, but early enough so it still happens while we're running
1460  single-threaded -- this specifically also means we must call it before we
1461  start plug-ins / storage engines / external components!
1462 
1463  @retval 0 no errors
1464  @retval -1 couldn't initialize stack lock
1465  @retval -2 couldn't initialize built-in default filter
1466  @retval -3 couldn't set up service hash
1467  @retval -4 couldn't initialize syseventlog lock
1468  @retval -5 couldn't set service pipeline
1469  @retval -6 couldn't initialize buffered logging lock
1470 */
1471 int log_builtins_init();
1472 
1473 /**
1474  De-initialize the structured logging subsystem.
1475 
1476  @retval 0 no errors
1477  @retval -1 not stopping, never started
1478 */
1479 int log_builtins_exit();
1480 
1481 /**
1482  Interim helper: write to the default error stream
1483 
1484  @param buffer buffer containing serialized error message
1485  @param length number of bytes in buffer
1486 */
1487 void log_write_errstream(const char *buffer, size_t length);
1488 
1489 #endif /* LOG_H */
bool slow_log_write(THD *thd, const char *query, size_t query_length, struct System_status_var *query_start_status)
Log slow query with all enabled log event handlers.
Definition: log.cc:1278
int log_line_index_by_item(log_line *ll, log_item *ref)
Find the (index of the) first key/value pair of the given type in the log line.
Definition: log_builtins.cc:877
unsigned long long int ulonglong
Definition: my_inttypes.h:69
void log_line_exit(log_line *ll)
Release a log_line allocated with log_line_init.
Definition: log_builtins.cc:656
Instrumentation helpers for mutexes.
loglevel ll
Definition: log.h:677
Class responsible for table based logging.
Definition: log.h:226
mysql_mutex_t * LOCK_log_throttle
Slow_log_throttle is shared between THDs.
Definition: log.h:619
log_line * log_line_init()
Initialize a log_line.
Definition: log_builtins.cc:643
virtual ~Log_event_handler()
Definition: log.h:161
bool log_item_generic_type(log_item_type t)
Predicate used to determine whether a type is generic (generic string, generic float, generic integer) rather than a well-known type.
Definition: log_builtins.cc:411
t pos
Definition: dbug_analyze.cc:148
virtual bool log_general(THD *thd, ulonglong event_utime, const char *user_host, size_t user_host_len, my_thread_id thread_id, const char *command_type, size_t command_type_len, const char *sql_text, size_t sql_text_len, const CHARSET_INFO *client_cs)
Definition: log.cc:852
void log_slow_do(THD *thd, struct System_status_var *query_start_status)
Unconditionally writes the current statement (or its rewritten version if it exists) to the slow quer...
Definition: log.cc:1618
log_item_data * log_line_item_set(log_line *ll, log_item_type t)
Create a new log item of well-known type "t" in log line "ll".
Definition: log_builtins.cc:1092
int log_builtins_init()
Initialize the structured logging subsystem.
Definition: log_builtins.cc:2548
static const uint MAX_LOG_HANDLERS_NUM
Currently we have only 2 kinds of logging functions: old-fashioned file logs and csv logging routines...
Definition: log.h:270
bool reopen_log_file(enum_log_table_type log_type)
Close file log for the given log type and the reopen it.
Definition: log.cc:1526
int log_line_index_by_name(log_line *ll, const char *key)
Find the (index of the) last key/value pair of the given name in the log line.
Definition: log_builtins.cc:807
ssize_t count
Definition: memcached.c:386
static char * query
Definition: myisam_ftdump.cc:44
const string name("\ame\)
uint err_code
Definition: log.h:678
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
bool log_item_set_cstring(log_item_data *lid, const char *s)
Set a string value on a log_item.
Definition: log_builtins.cc:1166
int log_message(int log_type,...)
Variadic convenience function for logging.
Definition: log.cc:2316
virtual bool log_slow(THD *thd, ulonglong current_utime, ulonglong query_start_arg, const char *user_host, size_t user_host_len, ulonglong query_utime, ulonglong lock_utime, bool is_command, const char *sql_text, size_t sql_text_len, struct System_status_var *query_start_status)
Definition: log.cc:979
void log_item_init(log_item *li)
Initializes a log entry for use.
Definition: log_builtins.cc:903
enum_log_table_type check_if_log_table(TABLE_LIST *table_list, bool check_if_opened) const
Check if given TABLE_LIST has a query log table name and optionally check if the query log is current...
Definition: log.cc:1534
Some integer typedefs for easier portability.
ulonglong total_exec_time
Total of the execution times of queries in this time-window for which we suppressed logging...
Definition: log.h:596
#define bool
Definition: config_static.h:42
Definition: log.h:675
Definition: log_shared.h:183
int log_builtins_error_stack_flush()
Call flush() on all log_services.
Definition: log_builtins.cc:2285
const char * subsys
Definition: log.h:679
enum enum_log_item_type log_item_type
item_type – what to log
struct module_t * m
Definition: dbug_analyze.cc:469
virtual bool log_slow(THD *thd, ulonglong current_utime, ulonglong query_start_arg, const char *user_host, size_t user_host_len, ulonglong query_utime, ulonglong lock_utime, bool is_command, const char *sql_text, size_t sql_text_len, struct System_status_var *query_start_status)=0
Log a query to the slow log.
Log_throttle(ulong window_usecs, const char *msg)
Definition: log.h:563
Class responsible for file based logging.
Definition: log.cc:1176
bool set_log_file(enum_log_table_type log_type)
Read log file name from global variable opt_*_logname.
Definition: log.cc:1505
bool activate_log_handler(THD *thd, enum_log_table_type log_type)
Activate log handlers for the given log type.
Definition: log.cc:1485
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:51
printf("== done ==\)
uint64 log_item_type_mask
a bit mask of log_types.
Definition: log_shared.h:213
void log_slow_statement(THD *thd, struct System_status_var *query_start_status)
Check whether we need to write the current statement to the slow query log.
Definition: log.cc:1645
log_line ("log event")
Definition: log_builtins_imp.h:85
void log_item_get_int(log_item *li, longlong *i)
Get an integer value from a log-item of float or integer type.
Definition: log_builtins.cc:448
Log_event_handler()
Definition: log.h:160
static const uint LOG_FILE
Definition: log.h:259
void init_query_log(enum_log_table_type log_type, ulonglong log_printer)
Setup log event handlers for the given log_type.
Definition: log.cc:1428
log_item_data * log_item_set(log_item *li, log_item_type t)
As log_item_set_with_key(), except that the key is automatically derived from the wellknown log_item_...
Definition: log_builtins.cc:1062
void log_line_item_free(log_line *ll, size_t elem)
Release log line item (key/value pair) with the index elem in log line ll.
Definition: log_builtins.cc:756
bool log_item_set_float(log_item_data *lid, double f)
Set a floating point value on a log_item.
Definition: log_builtins.cc:1126
int log_item_wellknown_by_type(log_item_type t)
See whether a type is wellknown.
Definition: log_builtins.cc:518
Definition: log_shared.h:70
void set_handlers(ulonglong log_printer)
Enable log event handlers for slow/general log.
Definition: log.cc:1476
ulonglong total_lock_time
Total of the lock times of queries in this time-window for which we suppressed logging.
Definition: log.h:602
Common definition between mysql server & client.
Class which manages slow and general log event handlers.
Definition: log.h:265
Used for rate-limiting the slow query log.
Definition: log.h:582
int log_item_wellknown_by_name(const char *key, size_t len)
See whether a string is a wellknown field name.
Definition: log_builtins.cc:495
ulong count
There have been this many lines of this type in this window, including those that we suppressed...
Definition: log.h:516
Query_logger()
Definition: log.h:297
bool activate_log(THD *thd, enum_log_table_type log_type)
Check if log table for given log type exists and can be opened.
Definition: log.cc:1142
Log_event_handler * slow_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
NULL-terminated arrays of log handlers.
Definition: log.h:284
my_thread_id log_get_thread_id(THD *thd)
A helper that we can stubify so we don&#39;t have to pull all of THD into the unit tests.
Definition: log.cc:2004
Performance schema instrumentation interface.
Error_log_throttle(ulong window_usecs, loglevel lvl, uint errcode, const char *subsystem, const char *msg)
Definition: log.h:701
bool log_slow_applicable(THD *thd)
Check whether we need to write the current statement (or its rewritten version if it exists) to the s...
Definition: log.cc:1578
const ulong window_size
Log no more than rate lines of a given type per window_size (e.g.
Definition: log.h:508
ulong * rate
A reference to the threshold ("no more than n log lines per ...").
Definition: log.h:608
Log_event_handler * general_log_handler_list[MAX_LOG_HANDLERS_NUM+1]
Definition: log.h:285
void init()
Perform basic log initialization: create file-based log handler.
Definition: log.cc:1264
bool is_log_file_enabled(enum_log_table_type log_type) const
Check if file logging is turned on for the given log type.
Definition: log.cc:1558
int log_vmessage(int log_type, va_list lili)
Write a message to a log (for now just used for error log).
Definition: log.cc:2049
Abstract superclass for handling logging to slow/general logs.
Definition: log.h:158
Header for compiler-dependent features.
Slow_log_throttle log_throttle_qni
void log_item_get_string(log_item *li, char **str, size_t *len)
Get a string value from a log-item of C-string or Lex string type.
Definition: log_builtins.cc:476
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
unsigned int len
Definition: dbug_analyze.cc:216
const char * summary_template
Template for the summary line.
Definition: log.h:523
unsigned int uint
Definition: uca-dump.cc:29
const char * log_label_from_prio(int prio)
Convenience function: Derive a log label ("error", "warning", "information") from a severity...
Definition: log_builtins.cc:1187
long long int longlong
Definition: my_inttypes.h:70
t
Definition: dbug_analyze.cc:147
mysql error code (numeric)
Definition: log_shared.h:129
char msg[1024]
Definition: test_sql_9_sessions.cc:282
static const uint LOG_TABLE
Definition: log.h:260
int log_line_item_count(log_line *ll)
How many items are currently set on the given log_line?
Definition: log_builtins.cc:730
char * make_query_log_name(char *buff, enum_log_table_type log_type)
Create the name of the query log specified.
Definition: log.cc:1564
Definition: m_ctype.h:358
Query_logger query_logger
Definition: log.cc:1562
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:47
#define window_size
Definition: log_event.cc:151
log_item_type_mask log_line_item_types_seen(log_line *ll, log_item_type_mask m)
Test whether a given type is presumed present on the log line.
Definition: log_builtins.cc:741
static const char * key
Definition: suite_stubs.c:14
log_item * log_line_item_by_name(log_line *ll, const char *key)
Find the last item matching the given key in the log line.
Definition: log_builtins.cc:834
static const uint LOG_NONE
Definition: log.h:258
Definition of the global "loglevel" enumeration.
void log_item_free(log_item *li)
Release any of key and value on a log-item that were dynamically allocated.
Definition: log_builtins.cc:624
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:50
void deactivate_log_handler(enum_log_table_type log_type)
Close file log for the given log type.
Definition: log.cc:1498
log_item_data * log_line_item_set_with_key(log_line *ll, log_item_type t, const char *key, uint32 alloc)
Create new log item in log line "ll", with key name "key", and allocation flags of "alloc" (see enum_...
Definition: log_builtins.cc:1016
void print_summary(ulong suppressed)
Actually print the prepared summary to log.
Definition: log.h:684
uint32 my_thread_id
Definition: my_thread_local.h:33
command
Definition: version_token.cc:278
virtual bool log_general(THD *thd, ulonglong event_utime, const char *user_host, size_t user_host_len, my_thread_id thread_id, const char *command_type, size_t command_type_len, const char *sql_text, size_t sql_text_len, const CHARSET_INFO *client_cs)=0
Log command to the general log.
int log_line_submit(log_line *ll)
Complete, filter, and write submitted log items.
Definition: log_builtins.cc:1766
Definition: log.h:149
bool log_line_full(log_line *ll)
Predicate indicating whether a log line is "willing" to accept any more key/value pairs...
Definition: log_builtins.cc:669
bool init_error_log()
Initialize structures (e.g.
Definition: log.cc:1876
log_item * log_line_item_init(log_line *ll)
Initializes an entry in a log line for use.
Definition: log_builtins.cc:918
Definition: log.h:151
bool inc_log_count(ulong rate)
Increase count of logs we&#39;re handling.
Definition: log.h:538
bool log_item_set_int(log_item_data *lid, longlong i)
Set an integer value on a log_item.
Definition: log_builtins.cc:1107
const char * filename
Definition: pfs_example_component_population.cc:64
Base class for rate-limiting a log (slow query log etc.)
Definition: log.h:498
bool is_valid_log_name(const char *name, size_t len)
Check given log name against certain blacklisted names/extensions.
Definition: log.cc:396
log_item_class log_item_wellknown_get_class(uint idx)
Accessor: from a record describing a wellknown key, get its class.
Definition: log_builtins.cc:559
Security_context aggregate_sctx
We&#39;re using our own (empty) security context during summary generation.
Definition: log.h:590
void discard_error_log_messages()
Discard all buffered messages and deallocate buffer without printing anything.
Definition: log.cc:1857
enum_log_table_type
Type of the log table.
Definition: log.h:148
Definition: log_shared.h:193
void flush(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:97
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool log_item_numeric_class(log_item_class c)
Predicate used to determine whether a class is a numeric class (integer or float).
Definition: log_builtins.cc:438
const char * log_item_wellknown_get_name(uint idx)
Accessor: from a record describing a wellknown key, get its name.
Definition: log_builtins.cc:537
bool log_item_string_class(log_item_class c)
Predicate used to determine whether a class is a string class (C-string or Lex-string).
Definition: log_builtins.cc:425
log_item_data * log_item_set_with_key(log_item *li, log_item_type t, const char *key, uint32 alloc)
Create new log item with key name "key", and allocation flags of "alloc" (see enum_log_item_free).
Definition: log_builtins.cc:958
ABI for instrumented mutexes.
void flush_error_log_messages()
We buffer all error log messages that have been printed before the error log has been opened...
Definition: log.cc:1861
static Logger logger
The "top-level" logger used when no connection context is given.
Definition: test_trace_plugin.cc:293
int log_line_index_by_type(log_line *ll, log_item_type t)
Find the (index of the) first key/value pair of the given type in the log line.
Definition: log_builtins.cc:849
Common #defines and includes for file and socket I/O.
int make_iso8601_timestamp(char *buf, ulonglong utime, int mode)
Make and return an ISO 8601 / RFC 3339 compliant timestamp.
Definition: log_builtins.cc:2006
void log_line_item_remove(log_line *ll, int elem)
Release log line item (key/value pair) with the index elem in log line ll.
Definition: log_builtins.cc:783
bool open_error_log(const char *filename, bool get_lock)
Open the error log and redirect stderr and optionally stdout to the error log file.
Definition: log.cc:1893
loglevel
Definition: my_loglevel.h:32
ulonglong window_end
When will/did current window end?
Definition: log.h:502
log_item_type log_item_wellknown_get_type(uint idx)
Accessor: from a record describing a wellknown key, get its type.
Definition: log_builtins.cc:548
void error_log_print(enum loglevel level, uint ecode, va_list args)
Prints a printf style message to the error log.
Definition: log.cc:2291
bool is_log_table_enabled(enum_log_table_type log_type) const
Check if table logging is turned on for the given log_type.
Definition: log.cc:1255
bool reopen_error_log()
Flush any pending data to disk and reopen the error log.
Definition: log.cc:1955
mysql_rwlock_t LOCK_logger
RW-lock protecting Query_logger.
Definition: log.h:277
void destroy_error_log()
Free any error log resources.
Definition: log.cc:1943
the message, format string
Definition: log_shared.h:147
Definition: log.h:150
Log_to_csv_event_handler table_log_handler
Available log handlers.
Definition: log.h:280
bool in_window(ulonglong now) const
Check whether we&#39;re still in the current window.
Definition: log.h:545
int log_string_compare(const char *a, const char *b, size_t len, bool case_insensitive)
Modular logger: log line and key/value manipulation helpers.
Definition: log_builtins.cc:383
void log_write_errstream(const char *buffer, size_t length)
Interim helper: write to the default error stream.
Definition: log.cc:1985
int log_builtins_exit()
De-initialize the structured logging subsystem.
Definition: log_builtins.cc:2507
void cleanup()
Free memory.
Definition: log.cc:1269
Definition: table.h:2439
bool general_log_write(THD *thd, enum_server_command command, const char *query, size_t query_length)
Write query to general query log.
Definition: log.cc:1358
Instrumentation helpers for rwlock.
Per thread status variables.
Definition: system_variables.h:394
bool general_log_print(THD *thd, enum_server_command command, const char *format,...)
Write printf style message to general query log.
Definition: log.cc:1395
unsigned long ulong
Definition: my_inttypes.h:46
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
log priority (error, warn, ...)
Definition: log_shared.h:144
enum enum_log_item_class log_item_class
void log_item_get_float(log_item *li, double *f)
Get a float value from a log-item of float or integer type.
Definition: log_builtins.cc:462
log called from subsystem ...
Definition: log_shared.h:137
Log_to_file_event_handler * file_log_handler
Definition: log.h:281
static int log_type
Definition: mi_log.cc:46
int log_builtins_error_stack(const char *conf, bool check_only, size_t *pos)
Set up custom error logging stack.
Definition: log_builtins.cc:2341
static my_thread_id thread_id
Definition: my_thr_init.cc:62
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
void log_line_item_free_all(log_line *ll)
Release all log line items (key/value pairs) in log line ll.
Definition: log_builtins.cc:767
bool log_item_set_lexstring(log_item_data *lid, const char *s, size_t s_len)
Set a string value on a log_item.
Definition: log_builtins.cc:1146