36
36
* When writing a Command to the log, we calculate the length of the
37
37
* Command to be written. We then increment log_offset by the length
38
38
* of the Command plus sizeof(uint64_t) and store this new offset in a
39
* local off_t called cur_offset (see SerialEventLog::apply(). This
39
* local off_t called cur_offset (see CommandLog::apply(). This
40
40
* compare and set is done in an atomic instruction.
42
42
* We then adjust the local off_t (cur_offset) back to the original
66
66
using namespace std;
69
* Serial Event Log plugin system variable - Is the log enabled? Only used on init().
70
* The enable() and disable() methods of the SerialEventLog class control online
69
* Command Log plugin system variable - Is the log enabled? Only used on init().
70
* The enable() and disable() methods of the CommandLog class control online
73
static bool sysvar_serial_event_log_enabled= false;
74
/** Serial Event Log plugin system variable - The path to the log file used */
75
static char* sysvar_serial_event_log_file= NULL;
76
/** Serial Event Log plugin system variable - A debugging variable to assist in truncating the log file. */
77
static bool sysvar_serial_event_log_truncate_debug= false;
78
static const char DEFAULT_LOG_FILE_PATH[]= "event.log"; /* In datadir... */
73
static bool sysvar_command_log_enabled= false;
74
/** Command Log plugin system variable - The path to the log file used */
75
static char* sysvar_command_log_file= NULL;
76
/** Command Log plugin system variable - A debugging variable to assist in truncating the log file. */
77
static bool sysvar_command_log_truncate_debug= false;
78
static const char DEFAULT_LOG_FILE_PATH[]= "command.log"; /* In datadir... */
80
SerialEventLog::SerialEventLog(const char *in_log_file_path)
80
CommandLog::CommandLog(const char *in_log_file_path)
82
82
drizzled::plugin::Applier(),
83
state(SerialEventLog::OFFLINE),
83
state(CommandLog::OFFLINE),
84
84
log_file_path(in_log_file_path)
86
86
is_enabled= true; /* If constructed, the plugin is enabled until taken offline with disable() */
90
90
log_file= open(log_file_path, O_APPEND|O_CREAT|O_SYNC|O_WRONLY, S_IRWXU);
91
91
if (log_file == -1)
93
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to open serial event log file. Got error: %s"), strerror(errno));
93
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to open command log file. Got error: %s"), strerror(errno));
102
102
log_offset= lseek(log_file, 0, SEEK_END);
104
state= SerialEventLog::ONLINE;
104
state= CommandLog::ONLINE;
108
SerialEventLog::~SerialEventLog()
108
CommandLog::~CommandLog()
110
110
/* Clear up any resources we've consumed */
111
111
if (isActive() && log_file != -1)
117
bool SerialEventLog::isActive()
117
bool CommandLog::isActive()
119
119
return is_enabled && is_active;
122
void SerialEventLog::apply(drizzled::message::Command *to_apply)
122
void CommandLog::apply(drizzled::message::Command *to_apply)
124
124
std::string buffer; /* Buffer we will write serialized command to */
163
163
* not be active, therefore a caller could have been ready
164
164
* to write...but the log is crashed.
166
if (unlikely(state == SerialEventLog::CRASHED))
166
if (unlikely(state == CommandLog::CRASHED))
169
169
/* We always write in network byte order */
202
202
* Quick safety...if an error occurs above in another writer, the log
203
203
* file will be in a crashed state.
205
if (unlikely(state == SerialEventLog::CRASHED))
205
if (unlikely(state == CommandLog::CRASHED))
208
208
* Reset the log's offset in case we want to produce a decent error message including
262
262
is_enabled= orig_is_enabled;
265
static SerialEventLog *serial_event_log= NULL; /* The singleton serial log */
265
static CommandLog *command_log= NULL; /* The singleton command log */
267
267
static int init(PluginRegistry ®istry)
269
if (sysvar_serial_event_log_enabled)
269
if (sysvar_command_log_enabled)
271
serial_event_log= new SerialEventLog(sysvar_serial_event_log_file);
272
registry.add(serial_event_log);
271
command_log= new CommandLog(sysvar_command_log_file);
272
registry.add(command_log);
277
277
static int deinit(PluginRegistry ®istry)
279
if (serial_event_log)
281
registry.remove(serial_event_log);
282
delete serial_event_log;
281
registry.remove(command_log);
290
290
* The const void * save comes directly from the check function,
291
291
* which should simply return the result from the set statement.
293
fprintf(stdout, "Holy crap.\n");
294
if (serial_event_log)
295
294
if (*(bool *)save != false)
296
serial_event_log->truncate();
295
command_log->truncate();
299
298
static DRIZZLE_SYSVAR_BOOL(enable,
300
sysvar_serial_event_log_enabled,
299
sysvar_command_log_enabled,
301
300
PLUGIN_VAR_NOCMDARG,
302
N_("Enable serial event log"),
301
N_("Enable command log"),
303
302
NULL, /* check func */
304
303
NULL, /* update func */
305
304
false /* default */);
307
306
static DRIZZLE_SYSVAR_BOOL(truncate_debug,
308
sysvar_serial_event_log_truncate_debug,
307
sysvar_command_log_truncate_debug,
309
308
PLUGIN_VAR_NOCMDARG,
310
N_("DEBUGGING - Truncate serial event log"),
309
N_("DEBUGGING - Truncate command log"),
311
310
NULL, /* check func */
312
311
set_truncate_debug, /* update func */
313
312
false /* default */);
315
314
static DRIZZLE_SYSVAR_STR(log_file,
316
sysvar_serial_event_log_file,
315
sysvar_command_log_file,
317
316
PLUGIN_VAR_READONLY,
318
N_("Path to the file to use for serial event log."),
317
N_("Path to the file to use for command log."),
319
318
NULL, /* check func */
320
319
NULL, /* update func*/
321
320
DEFAULT_LOG_FILE_PATH /* default */);
330
drizzle_declare_plugin(serial_event_log)
329
drizzle_declare_plugin(command_log)
335
N_("Default Serial Event Log"),
334
N_("Simple Command Message Log"),
336
335
PLUGIN_LICENSE_GPL,
337
336
init, /* Plugin Init */
338
337
deinit, /* Plugin Deinit */