1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
16
#ifndef DRIZZLE_SERVER_LOG_H
21
17
#define DRIZZLE_SERVER_LOG_H
23
#include <mysys/iocache.h>
25
19
class Relay_log_info;
27
21
class Format_description_log_event;
201
195
friend class Log_event;
198
class DRIZZLE_QUERY_LOG: public DRIZZLE_LOG
201
DRIZZLE_QUERY_LOG() : last_time(0) {}
203
bool write(time_t event_time, const char *user_host,
204
uint user_host_len, int thread_id,
205
const char *command_type, uint command_type_len,
206
const char *sql_text, uint sql_text_len);
207
bool write(THD *thd, time_t current_time, time_t query_start_arg,
208
const char *user_host, uint user_host_len,
209
uint64_t query_utime, uint64_t lock_utime, bool is_command,
210
const char *sql_text, uint sql_text_len);
211
bool open_slow_log(const char *log_name)
214
return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0,
217
bool open_query_log(const char *log_name)
220
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
204
228
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG
317
343
bool write(Log_event* event_info); // binary log write
318
bool write(Session *session, IO_CACHE *cache, Log_event *commit_event);
344
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
320
346
int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync);
322
void start_union_events(Session *session, query_id_t query_id_param);
323
void stop_union_events(Session *session);
324
bool is_query_in_union(Session *session, query_id_t query_id_param);
348
void start_union_events(THD *thd, query_id_t query_id_param);
349
void stop_union_events(THD *thd);
350
bool is_query_in_union(THD *thd, query_id_t query_id_param);
327
353
v stands for vector
328
354
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
330
bool appendv(const char* buf,uint32_t len,...);
356
bool appendv(const char* buf,uint len,...);
331
357
bool append(Log_event* ev);
333
359
void make_log_name(char* buf, const char* log_ident);
334
360
bool is_active(const char* log_file_name);
335
361
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
336
void rotate_and_purge(uint32_t flags);
362
void rotate_and_purge(uint flags);
337
363
bool flush_and_sync();
338
364
int purge_logs(const char *to_log, bool included,
339
365
bool need_mutex, bool need_update_threads,
340
366
uint64_t *decrease_log_space);
341
367
int purge_logs_before_date(time_t purge_time);
342
368
int purge_first_log(Relay_log_info* rli, bool included);
343
bool reset_logs(Session* session);
344
void close(uint32_t exiting);
369
bool reset_logs(THD* thd);
370
void close(uint exiting);
346
372
// iterating through the log index file
347
373
int find_log_pos(LOG_INFO* linfo, const char* log_name,
369
395
virtual bool init()= 0;
370
396
virtual void cleanup()= 0;
398
virtual bool log_slow(THD *thd, time_t current_time,
399
time_t query_start_arg, const char *user_host,
400
uint user_host_len, uint64_t query_utime,
401
uint64_t lock_utime, bool is_command,
402
const char *sql_text, uint sql_text_len)= 0;
372
403
virtual bool log_error(enum loglevel level, const char *format,
373
404
va_list args)= 0;
405
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
406
uint user_host_len, int thread_id,
407
const char *command_type, uint command_type_len,
408
const char *sql_text, uint sql_text_len,
409
const CHARSET_INFO * const client_cs)= 0;
374
410
virtual ~Log_event_handler() {}
414
/* type of the log table */
415
#define QUERY_LOG_SLOW 1
416
#define QUERY_LOG_GENERAL 2
418
class Log_to_file_event_handler: public Log_event_handler
420
DRIZZLE_QUERY_LOG mysql_log;
421
DRIZZLE_QUERY_LOG mysql_slow_log;
424
Log_to_file_event_handler(): is_initialized(false)
427
virtual void cleanup();
429
virtual bool log_slow(THD *thd, time_t current_time,
430
time_t query_start_arg, const char *user_host,
431
uint user_host_len, uint64_t query_utime,
432
uint64_t lock_utime, bool is_command,
433
const char *sql_text, uint sql_text_len);
434
virtual bool log_error(enum loglevel level, const char *format,
436
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
437
uint user_host_len, int thread_id,
438
const char *command_type, uint command_type_len,
439
const char *sql_text, uint sql_text_len,
440
const CHARSET_INFO * const client_cs);
442
void init_pthread_objects();
443
DRIZZLE_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
444
DRIZZLE_QUERY_LOG *get_mysql_log() { return &mysql_log; }
378
448
/* Class which manages slow, general and error log event handlers */
381
451
rw_lock_t LOCK_logger;
382
452
/* flag to check whether logger mutex is initialized */
455
/* available log handlers */
456
Log_to_file_event_handler *file_log_handler;
385
458
/* NULL-terminated arrays of log handlers */
386
459
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
460
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
461
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
465
LOGGER() : inited(0), file_log_handler(NULL)
392
467
void lock_shared() { rw_rdlock(&LOCK_logger); }
393
468
void lock_exclusive() { rw_wrlock(&LOCK_logger); }
394
469
void unlock() { rw_unlock(&LOCK_logger); }
395
bool log_command(Session *session, enum enum_server_command command);
470
bool log_command(THD *thd, enum enum_server_command command);
398
473
We want to initialize all log mutexes as soon as possible,
403
478
void init_base();
404
bool flush_logs(Session *session);
479
bool flush_logs(THD *thd);
405
480
/* Perform basic logger cleanup. this will leave e.g. error log open. */
406
481
void cleanup_base();
407
482
/* Free memory. Nothing could be logged after this function is called */
408
483
void cleanup_end();
409
484
bool error_log_print(enum loglevel level, const char *format,
486
bool slow_log_print(THD *thd, const char *query, uint query_length,
487
uint64_t current_utime);
488
bool general_log_print(THD *thd,enum enum_server_command command,
489
const char *format, va_list args);
490
bool general_log_write(THD *thd, enum enum_server_command command,
491
const char *query, uint query_length);
411
493
/* we use this function to setup all enabled log event handlers */
412
int set_handlers(uint32_t error_log_printer);
413
void init_error_log(uint32_t error_log_printer);
494
int set_handlers(uint error_log_printer,
495
uint slow_log_printer,
496
uint general_log_printer);
497
void init_error_log(uint error_log_printer);
498
void init_slow_log(uint slow_log_printer);
499
void init_general_log(uint general_log_printer);
500
void deactivate_log_handler(THD* thd, uint log_type);
501
bool activate_log_handler(THD* thd, uint log_type);
502
DRIZZLE_QUERY_LOG *get_slow_log_file_handler()
504
if (file_log_handler)
505
return file_log_handler->get_mysql_slow_log();
508
DRIZZLE_QUERY_LOG *get_log_file_handler()
510
if (file_log_handler)
511
return file_log_handler->get_mysql_log();
416
516
enum enum_binlog_format {
442
542
int error_log_print(enum loglevel level, const char *format,
445
void sql_perror(const char *message);
545
bool slow_log_print(THD *thd, const char *query, uint query_length,
546
uint64_t current_utime);
548
bool general_log_print(THD *thd, enum enum_server_command command,
549
const char *format,...);
551
bool general_log_write(THD *thd, enum enum_server_command command,
552
const char *query, uint query_length);
448
554
#endif /* DRIZZLE_SERVER_LOG_H */