~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to sql/backup/logger.cc

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "../mysql_priv.h"
2
2
 
3
3
#include "logger.h"
 
4
#include "image_info.h"
 
5
 
 
6
/** @file
 
7
 
 
8
 @todo Log errors to progress tables
 
9
 */ 
4
10
 
5
11
namespace backup {
6
12
 
17
23
                     for other messages set to 0
18
24
  @param msg         message text
19
25
 
 
26
  @note It should be possible to use this method (and other error reporting
 
27
  methods relying on it) right after creation of the Logger object instance.
 
28
  The message should be written to these destinations which are available at
 
29
  the moment. Destinations which are not ready/initialized yet should be 
 
30
  silently ignored.
 
31
 
20
32
  @returns 0 on success.
21
33
 */
22
34
int Logger::write_message(log_level::value level, int error_code,
23
35
                          const char *msg)
24
36
{
25
 
   const char *prefix= m_type == BACKUP ? "Backup" : "Restore";
26
37
   char buf[ERRMSGSIZE + 30];
27
 
 
28
 
   my_snprintf(buf,sizeof(buf),"%s: %s",prefix,msg);
29
 
 
 
38
   const char *out= msg;
 
39
 
 
40
   if (m_state == READY || m_state == RUNNING)
 
41
   {
 
42
     my_snprintf(buf, sizeof(buf), "%s: %s", 
 
43
                 m_type == BACKUP ? "Backup" : "Restore" , msg);
 
44
     out= buf;
 
45
   }
 
46
   
30
47
   switch (level) {
31
48
   case log_level::ERROR:
32
49
     if (m_save_errors)
33
 
       errors.push_front(new MYSQL_ERROR(::current_thd,error_code,
34
 
                                         MYSQL_ERROR::WARN_LEVEL_ERROR,msg));
35
 
     sql_print_error(buf);
 
50
       errors.push_front(new MYSQL_ERROR(::current_thd, error_code,
 
51
                                         MYSQL_ERROR::WARN_LEVEL_ERROR, msg));
 
52
     sql_print_error(out);
36
53
     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
37
54
                         error_code, msg);
38
 
     DBUG_PRINT("backup_log",("[ERROR] %s",buf));
 
55
     DBUG_PRINT("backup_log",("[ERROR] %s", out));
 
56
     
 
57
     if (m_state == READY || m_state == RUNNING)
 
58
       report_ob_error(m_thd, m_op_id, error_code);
 
59
     
39
60
     return 0;
40
61
 
41
62
   case log_level::WARNING:
42
 
     sql_print_warning(buf);
 
63
     sql_print_warning(out);
43
64
     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
44
65
                         error_code, msg);
45
 
     DBUG_PRINT("backup_log",("[Warning] %s",buf));
 
66
     DBUG_PRINT("backup_log",("[Warning] %s", out));
46
67
     return 0;
47
68
 
48
69
   case log_level::INFO:
49
 
     sql_print_information(buf);
50
 
     DBUG_PRINT("backup_log",("[Info] %s",buf));
 
70
     sql_print_information(out);
 
71
     DBUG_PRINT("backup_log",("[Info] %s", out));
51
72
     return 0;
52
73
 
53
74
   default: return ERROR;
67
88
 */
68
89
int Logger::v_report_error(log_level::value level, int error_code, va_list args)
69
90
{
70
 
  return v_write_message(level,error_code,ER_SAFE(error_code),args);
 
91
  return v_write_message(level, error_code, ER_SAFE(error_code), args);
71
92
}
72
93
 
73
94
/**
82
103
{
83
104
  char buf[ERRMSGSIZE + 20];
84
105
 
85
 
  my_vsnprintf(buf,sizeof(buf),format,args);
86
 
  return write_message(level,error_code,buf);
87
 
}
88
 
 
 
106
  my_vsnprintf(buf, sizeof(buf), format, args);
 
107
  return write_message(level, error_code, buf);
 
108
}
 
109
 
 
110
/**
 
111
  Report statistics from backup/restore catalogue before the main operation
 
112
  starts.
 
113
 */ 
 
114
void Logger::report_stats_pre(const Image_info &info)
 
115
{
 
116
  DBUG_ASSERT(m_state == RUNNING);
 
117
  
 
118
  report_ob_num_objects(m_thd, m_op_id, info.table_count());
 
119
}
 
120
 
 
121
/**
 
122
  Report statistics from backup/restore catalogue after the operation is
 
123
  completed.
 
124
 */ 
 
125
void Logger::report_stats_post(const Image_info &info)
 
126
{
 
127
  DBUG_ASSERT(m_state == RUNNING);
 
128
  
 
129
  report_ob_size(m_thd, m_op_id, info.data_size);
 
130
}
89
131
 
90
132
} // backup namespace