Skip to content
Snippets Groups Projects
Commit dcdeefd5 authored by Daniel Agar's avatar Daniel Agar Committed by Lorenz Meier
Browse files

new logger

parent 9a0e962c
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@ then
then
fi
else
if logger start -b 20
if logger start -b 32
then
fi
fi
......
......@@ -22,23 +22,11 @@ LogWriter::LogWriter(uint8_t *buffer, size_t buffer_size) :
void LogWriter::start_log(const char *filename)
{
::strncpy(_filename, filename, sizeof(_filename));
_fd = ::open(_filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
if (_fd < 0) {
PX4_WARN("can't open log file %s", _filename);
_should_run = false;
return;
} else {
PX4_WARN("opened log file: %s", _filename);
_should_run = true;
_running = true;
}
// Clear buffer and counters
_head = 0;
_count = 0;
_total_written = 0;
_should_run = true;
notify();
}
......@@ -102,7 +90,21 @@ void LogWriter::run()
}
while (!_exit_thread) {
// Outer endless loop
// Outer endless loop, start new file each time
// _filename must be set before setting _should_run = true
_fd = ::open(_filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
if (_fd < 0) {
PX4_WARN("can't open log file %s", _filename);
_should_run = false;
continue;
}
PX4_WARN("started, log file: %s", _filename);
_should_run = true;
int poll_count = 0;
int written = 0;
......@@ -162,25 +164,22 @@ void LogWriter::run()
_total_written += written;
}
if (_running && !_should_run && written == static_cast<int>(available) && !is_part) {
if (!_should_run && written == static_cast<int>(available) && !is_part) {
// Stop only when all data written
_running = false;
_head = 0;
_count = 0;
int res = ::close(_fd);
break;
}
}
if (res) {
PX4_WARN("error closing log file");
_head = 0;
_count = 0;
} else {
PX4_WARN("closed logfile: %s, bytes written: %zu", _filename, _total_written);
}
int res = ::close(_fd);
break;
}
if (res) {
PX4_WARN("error closing log file");
}
PX4_WARN("stopped, bytes written: %zu", _total_written);
}
}
......
......@@ -63,7 +63,6 @@ private:
size_t _count = 0;
size_t _total_written = 0;
bool _should_run = false;
bool _running = false;
bool _exit_thread = false;
pthread_mutex_t _mtx;
pthread_cond_t _cv;
......
......@@ -356,7 +356,7 @@ void Logger::run()
struct mallinfo alloc_info = {};
#endif /* DBGPRINT */
PX4_WARN("logger started");
PX4_WARN("started");
int mkdir_ret = mkdir(LOG_ROOT, S_IRWXU | S_IRWXG | S_IRWXO);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment