~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log.h

  • Committer: Monty Taylor
  • Date: 2008-10-04 03:14:52 UTC
  • mfrom: (438.1.5 drizzle)
  • Revision ID: monty@inaugust.com-20081004031452-v1evilfl3nvmztgl
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
  friend class Log_event;
200
200
};
201
201
 
202
 
class DRIZZLE_QUERY_LOG: public DRIZZLE_LOG
203
 
{
204
 
public:
205
 
  DRIZZLE_QUERY_LOG() : last_time(0) {}
206
 
  void reopen_file();
207
 
  bool write(time_t event_time, const char *user_host,
208
 
             uint user_host_len, int thread_id,
209
 
             const char *command_type, uint command_type_len,
210
 
             const char *sql_text, uint sql_text_len);
211
 
  bool write(THD *thd, time_t current_time, time_t query_start_arg,
212
 
             const char *user_host, uint user_host_len,
213
 
             uint64_t query_utime, uint64_t lock_utime, bool is_command,
214
 
             const char *sql_text, uint sql_text_len);
215
 
  bool open_slow_log(const char *log_name)
216
 
  {
217
 
    char buf[FN_REFLEN];
218
 
    return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0,
219
 
                WRITE_CACHE);
220
 
  }
221
 
  bool open_query_log(const char *log_name)
222
 
  {
223
 
    char buf[FN_REFLEN];
224
 
    return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
225
 
                WRITE_CACHE);
226
 
  }
227
 
 
228
 
private:
229
 
  time_t last_time;
230
 
};
231
 
 
232
202
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG
233
203
{
234
204
 private:
399
369
  virtual bool init()= 0;
400
370
  virtual void cleanup()= 0;
401
371
 
402
 
  virtual bool log_slow(THD *thd, time_t current_time,
403
 
                        time_t query_start_arg, const char *user_host,
404
 
                        uint user_host_len, uint64_t query_utime,
405
 
                        uint64_t lock_utime, bool is_command,
406
 
                        const char *sql_text, uint sql_text_len)= 0;
407
372
  virtual bool log_error(enum loglevel level, const char *format,
408
373
                         va_list args)= 0;
409
 
  virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
410
 
                           uint user_host_len, int thread_id,
411
 
                           const char *command_type, uint command_type_len,
412
 
                           const char *sql_text, uint sql_text_len,
413
 
                           const CHARSET_INFO * const client_cs)= 0;
414
374
  virtual ~Log_event_handler() {}
415
375
};
416
376
 
417
377
 
418
 
/* type of the log table */
419
 
#define QUERY_LOG_SLOW 1
420
 
#define QUERY_LOG_GENERAL 2
421
 
 
422
 
class Log_to_file_event_handler: public Log_event_handler
423
 
{
424
 
  DRIZZLE_QUERY_LOG mysql_log;
425
 
  DRIZZLE_QUERY_LOG mysql_slow_log;
426
 
  bool is_initialized;
427
 
public:
428
 
  Log_to_file_event_handler(): is_initialized(false)
429
 
  {}
430
 
  virtual bool init();
431
 
  virtual void cleanup();
432
 
 
433
 
  virtual bool log_slow(THD *thd, time_t current_time,
434
 
                        time_t query_start_arg, const char *user_host,
435
 
                        uint user_host_len, uint64_t query_utime,
436
 
                        uint64_t lock_utime, bool is_command,
437
 
                        const char *sql_text, uint sql_text_len);
438
 
  virtual bool log_error(enum loglevel level, const char *format,
439
 
                         va_list args);
440
 
  virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
441
 
                           uint user_host_len, int thread_id,
442
 
                           const char *command_type, uint command_type_len,
443
 
                           const char *sql_text, uint sql_text_len,
444
 
                           const CHARSET_INFO * const client_cs);
445
 
  void flush();
446
 
  void init_pthread_objects();
447
 
  DRIZZLE_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
448
 
  DRIZZLE_QUERY_LOG *get_mysql_log() { return &mysql_log; }
449
 
};
450
 
 
451
 
 
452
378
/* Class which manages slow, general and error log event handlers */
453
379
class LOGGER
454
380
{
456
382
  /* flag to check whether logger mutex is initialized */
457
383
  uint inited;
458
384
 
459
 
  /* available log handlers */
460
 
  Log_to_file_event_handler *file_log_handler;
461
 
 
462
385
  /* NULL-terminated arrays of log handlers */
463
386
  Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
464
 
  Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
465
 
  Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
466
387
 
467
388
public:
468
389
 
469
 
  LOGGER() : inited(0), file_log_handler(NULL)
 
390
  LOGGER() : inited(0)
470
391
  {}
471
392
  void lock_shared() { rw_rdlock(&LOCK_logger); }
472
393
  void lock_exclusive() { rw_wrlock(&LOCK_logger); }
487
408
  void cleanup_end();
488
409
  bool error_log_print(enum loglevel level, const char *format,
489
410
                      va_list args);
490
 
  bool slow_log_print(THD *thd, const char *query, uint query_length,
491
 
                      uint64_t current_utime);
492
 
  bool general_log_print(THD *thd,enum enum_server_command command,
493
 
                         const char *format, va_list args);
494
 
  bool general_log_write(THD *thd, enum enum_server_command command,
495
 
                         const char *query, uint query_length);
496
 
 
497
411
  /* we use this function to setup all enabled log event handlers */
498
 
  int set_handlers(uint error_log_printer,
499
 
                   uint slow_log_printer,
500
 
                   uint general_log_printer);
 
412
  int set_handlers(uint error_log_printer);
501
413
  void init_error_log(uint error_log_printer);
502
 
  void init_slow_log(uint slow_log_printer);
503
 
  void init_general_log(uint general_log_printer);
504
 
  void deactivate_log_handler(THD* thd, uint log_type);
505
 
  bool activate_log_handler(THD* thd, uint log_type);
506
 
  DRIZZLE_QUERY_LOG *get_slow_log_file_handler()
507
 
  { 
508
 
    if (file_log_handler)
509
 
      return file_log_handler->get_mysql_slow_log();
510
 
    return NULL;
511
 
  }
512
 
  DRIZZLE_QUERY_LOG *get_log_file_handler()
513
 
  { 
514
 
    if (file_log_handler)
515
 
      return file_log_handler->get_mysql_log();
516
 
    return NULL;
517
 
  }
518
414
};
519
415
 
520
416
enum enum_binlog_format {
546
442
int error_log_print(enum loglevel level, const char *format,
547
443
                    va_list args);
548
444
 
549
 
bool slow_log_print(THD *thd, const char *query, uint query_length,
550
 
                    uint64_t current_utime);
551
 
 
552
 
bool general_log_print(THD *thd, enum enum_server_command command,
553
 
                       const char *format,...);
554
 
 
555
 
bool general_log_write(THD *thd, enum enum_server_command command,
556
 
                       const char *query, uint query_length);
557
 
 
558
445
#endif /* DRIZZLE_SERVER_LOG_H */