mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-01 04:56:29 -04:00
LogFile puts timestamp before entry, CRLF after.
This commit is contained in:
parent
76845c4335
commit
bfcd25d857
5 changed files with 34 additions and 29 deletions
|
@ -21,6 +21,11 @@
|
|||
|
||||
#include "log_file.hpp"
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
LogFile::~LogFile() {
|
||||
close();
|
||||
}
|
||||
|
@ -48,6 +53,20 @@ bool LogFile::is_ready() {
|
|||
return !f_error(&f);
|
||||
}
|
||||
|
||||
bool LogFile::write_entry(const std::string entry) {
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
std::string timestamp =
|
||||
to_string_dec_uint(datetime.year(), 4, '0') +
|
||||
to_string_dec_uint(datetime.month(), 2, '0') +
|
||||
to_string_dec_uint(datetime.day(), 2, '0') +
|
||||
to_string_dec_uint(datetime.hour(), 2, '0') +
|
||||
to_string_dec_uint(datetime.minute(), 2, '0') +
|
||||
to_string_dec_uint(datetime.second(), 2, '0');
|
||||
|
||||
return write(timestamp + " " + entry + "\r\n");
|
||||
}
|
||||
|
||||
bool LogFile::write(const std::string message) {
|
||||
const auto puts_result = f_puts(message.c_str(), &f);
|
||||
const auto sync_result = f_sync(&f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue