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
20
#ifndef DRIZZLE_SERVER_LOG_H
21
#define DRIZZLE_SERVER_LOG_H
23
#include <mysys/iocache.h>
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 */
25
19
class Relay_log_info;
50
int open(const char *opt_name __attribute__((unused)))
44
int open(const char *opt_name __attribute__((__unused__)))
52
46
void close(void) { }
53
int log_xid(THD *thd __attribute__((unused)),
54
my_xid xid __attribute__((unused))) { return 1; }
55
void unlog(ulong cookie __attribute__((unused)),
56
my_xid xid __attribute__((unused))) { }
47
int log_xid(THD *thd __attribute__((__unused__)),
48
my_xid xid __attribute__((__unused__))) { return 1; }
49
void unlog(ulong cookie __attribute__((__unused__)),
50
my_xid xid __attribute__((__unused__))) { }
182
177
enum cache_type io_cache_type_arg);
183
178
void init(enum_log_type log_type_arg,
184
179
enum cache_type io_cache_type_arg);
185
void close(uint32_t exiting);
180
void close(uint exiting);
186
181
inline bool is_open() { return log_state != LOG_CLOSED; }
187
182
const char *generate_name(const char *log_name, const char *suffix,
188
183
bool strip_ext, char *buff);
201
196
friend class Log_event;
204
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG
199
class MYSQL_QUERY_LOG: public MYSQL_LOG
202
MYSQL_QUERY_LOG() : last_time(0) {}
204
bool write(time_t event_time, const char *user_host,
205
uint user_host_len, int thread_id,
206
const char *command_type, uint command_type_len,
207
const char *sql_text, uint sql_text_len);
208
bool write(THD *thd, time_t current_time, time_t query_start_arg,
209
const char *user_host, uint user_host_len,
210
uint64_t query_utime, uint64_t lock_utime, bool is_command,
211
const char *sql_text, uint sql_text_len);
212
bool open_slow_log(const char *log_name)
215
return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0,
218
bool open_query_log(const char *log_name)
221
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
229
class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
207
232
/* LOCK_log and LOCK_index are inited by init_pthread_objects() */
327
354
v stands for vector
328
355
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
330
bool appendv(const char* buf,uint32_t len,...);
357
bool appendv(const char* buf,uint len,...);
331
358
bool append(Log_event* ev);
333
360
void make_log_name(char* buf, const char* log_ident);
334
361
bool is_active(const char* log_file_name);
335
362
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
336
void rotate_and_purge(uint32_t flags);
363
void rotate_and_purge(uint flags);
337
364
bool flush_and_sync();
338
365
int purge_logs(const char *to_log, bool included,
339
366
bool need_mutex, bool need_update_threads,
369
396
virtual bool init()= 0;
370
397
virtual void cleanup()= 0;
399
virtual bool log_slow(THD *thd, time_t current_time,
400
time_t query_start_arg, const char *user_host,
401
uint user_host_len, uint64_t query_utime,
402
uint64_t lock_utime, bool is_command,
403
const char *sql_text, uint sql_text_len)= 0;
372
404
virtual bool log_error(enum loglevel level, const char *format,
373
405
va_list args)= 0;
406
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
407
uint user_host_len, int thread_id,
408
const char *command_type, uint command_type_len,
409
const char *sql_text, uint sql_text_len,
410
CHARSET_INFO *client_cs)= 0;
374
411
virtual ~Log_event_handler() {}
415
/* type of the log table */
416
#define QUERY_LOG_SLOW 1
417
#define QUERY_LOG_GENERAL 2
419
class Log_to_file_event_handler: public Log_event_handler
421
MYSQL_QUERY_LOG mysql_log;
422
MYSQL_QUERY_LOG mysql_slow_log;
425
Log_to_file_event_handler(): is_initialized(false)
428
virtual void cleanup();
430
virtual bool log_slow(THD *thd, time_t current_time,
431
time_t query_start_arg, const char *user_host,
432
uint user_host_len, uint64_t query_utime,
433
uint64_t lock_utime, bool is_command,
434
const char *sql_text, uint sql_text_len);
435
virtual bool log_error(enum loglevel level, const char *format,
437
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
438
uint user_host_len, int thread_id,
439
const char *command_type, uint command_type_len,
440
const char *sql_text, uint sql_text_len,
441
CHARSET_INFO *client_cs);
443
void init_pthread_objects();
444
MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
445
MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
378
449
/* Class which manages slow, general and error log event handlers */
381
452
rw_lock_t LOCK_logger;
382
453
/* flag to check whether logger mutex is initialized */
456
/* available log handlers */
457
Log_to_file_event_handler *file_log_handler;
385
459
/* NULL-terminated arrays of log handlers */
386
460
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
461
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
462
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
466
LOGGER() : inited(0), file_log_handler(NULL)
392
468
void lock_shared() { rw_rdlock(&LOCK_logger); }
393
469
void lock_exclusive() { rw_wrlock(&LOCK_logger); }
408
484
void cleanup_end();
409
485
bool error_log_print(enum loglevel level, const char *format,
487
bool slow_log_print(THD *thd, const char *query, uint query_length,
488
uint64_t current_utime);
489
bool general_log_print(THD *thd,enum enum_server_command command,
490
const char *format, va_list args);
491
bool general_log_write(THD *thd, enum enum_server_command command,
492
const char *query, uint query_length);
411
494
/* 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);
495
int set_handlers(uint error_log_printer,
496
uint slow_log_printer,
497
uint general_log_printer);
498
void init_error_log(uint error_log_printer);
499
void init_slow_log(uint slow_log_printer);
500
void init_general_log(uint general_log_printer);
501
void deactivate_log_handler(THD* thd, uint log_type);
502
bool activate_log_handler(THD* thd, uint log_type);
503
MYSQL_QUERY_LOG *get_slow_log_file_handler()
505
if (file_log_handler)
506
return file_log_handler->get_mysql_slow_log();
509
MYSQL_QUERY_LOG *get_log_file_handler()
511
if (file_log_handler)
512
return file_log_handler->get_mysql_log();
416
517
enum enum_binlog_format {
431
532
extern TYPELIB binlog_format_typelib;
433
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
434
void sql_print_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
435
void sql_print_warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
436
void sql_print_information(const char *format, ...)
437
__attribute__((format(printf, 1, 2)));
438
typedef void (*sql_print_message_func)(const char *format, ...)
439
__attribute__((format(printf, 1, 2)));
440
extern sql_print_message_func sql_print_message_handlers[];
442
int error_log_print(enum loglevel level, const char *format,
445
#endif /* DRIZZLE_SERVER_LOG_H */