You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
/*
|
|
* LogCommand.cpp
|
|
*
|
|
* Created on: Jul 8, 2021
|
|
* Author: Andreas Berthoud
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <string>
|
|
|
|
#include "LogCommand.hpp"
|
|
|
|
|
|
void log_debug(const char * format, int nargs, ...) {
|
|
va_list args;
|
|
va_start(args, nargs);
|
|
push_command(new LogCommand(format, args, LOG_LEVEL_DEBUG));
|
|
va_end(args);
|
|
}
|
|
|
|
void log_info(const char * format, int nargs, ...) {
|
|
va_list args;
|
|
va_start(args, nargs);
|
|
push_command(new LogCommand(format, args, LOG_LEVEL_INFO));
|
|
va_end(args);
|
|
}
|
|
|
|
void log_warning(const char * format, int nargs, ...) {
|
|
va_list args;
|
|
va_start(args, nargs);
|
|
push_command(new LogCommand(format, args, LOG_LEVEL_WARNING));
|
|
va_end(args);
|
|
}
|
|
|
|
void log_error(const char * format, int nargs, ...) {
|
|
va_list args;
|
|
va_start(args, nargs);
|
|
push_command(new LogCommand(format, args, LOG_LEVEL_ERROR));
|
|
va_end(args);
|
|
}
|
|
|
|
LogCommand::LogCommand(
|
|
const char * format,
|
|
va_list args,
|
|
LoggingLevel logging_level) : Notification() {
|
|
|
|
uint16_t max_payload_size = NOTIFICATION_COMMAND_FREE_BUFFER - this->get_payload_size();
|
|
|
|
this->payload_ptr[0] = logging_level;
|
|
|
|
char * message = (char *)(this->payload_ptr + 1);
|
|
vsnprintf(message, max_payload_size - 1, format, args);
|
|
this->add_to_payload_size(strlen(message) + 1);
|
|
}
|
|
|