mirror of https://github.com/pvnis/srsRAN_4G.git
Upgrade the swapping logic of the file sink to use the new srslog functionality.
parent
54a864e021
commit
63bd43fa52
@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* \section COPYRIGHT
|
|
||||||
*
|
|
||||||
* Copyright 2013-2020 Software Radio Systems Limited
|
|
||||||
*
|
|
||||||
* By using this file, you agree to the terms and conditions set
|
|
||||||
* forth in the LICENSE file which can be found at the top level of
|
|
||||||
* the distribution.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SRSUE_TTCN3_SWAPPABLE_LOG_H
|
|
||||||
#define SRSUE_TTCN3_SWAPPABLE_LOG_H
|
|
||||||
|
|
||||||
#include "srslte/common/logger_srslog_wrapper.h"
|
|
||||||
|
|
||||||
/// This is a log wrapper that allows hot swapping the underlying log instance.
|
|
||||||
class swappable_log : public srslte::logger
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit swappable_log(std::unique_ptr<srslte::srslog_wrapper> log) : l(std::move(log)) {}
|
|
||||||
|
|
||||||
void log(unique_log_str_t msg) override
|
|
||||||
{
|
|
||||||
assert(l && "Missing log instance");
|
|
||||||
l->log(std::move(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Swaps the underlying log wrapper.
|
|
||||||
void swap_log(std::unique_ptr<srslte::srslog_wrapper> new_log) { l = std::move(new_log); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<srslte::srslog_wrapper> l;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SRSUE_TTCN3_SWAPPABLE_LOG_H
|
|
@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2020 Software Radio Systems Limited
|
||||||
|
*
|
||||||
|
* By using this file, you agree to the terms and conditions set
|
||||||
|
* forth in the LICENSE file which can be found at the top level of
|
||||||
|
* the distribution.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRSUE_TTCN3_SWAPPABLE_SINK_H
|
||||||
|
#define SRSUE_TTCN3_SWAPPABLE_SINK_H
|
||||||
|
|
||||||
|
#include "srslte/srslog/sink.h"
|
||||||
|
|
||||||
|
/// A custom sink implementation that allows hot swapping file sinks so that loggers can write to different files
|
||||||
|
/// dynamically.
|
||||||
|
class swappable_sink : public srslog::sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
swappable_sink(const std::string& filename, std::unique_ptr<srslog::log_formatter> f) :
|
||||||
|
srslog::sink(std::move(f)), s(&srslog::fetch_file_sink(filename))
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// Identifier of this custom sink.
|
||||||
|
static const char* name() { return "swappable_sink"; }
|
||||||
|
|
||||||
|
srslog::detail::error_string write(srslog::detail::memory_buffer buffer) override { return s->write(buffer); }
|
||||||
|
|
||||||
|
srslog::detail::error_string flush() override { return s->flush(); }
|
||||||
|
|
||||||
|
/// Swaps the current file sink with a new sink that will write to the specified file name.
|
||||||
|
void swap_sink(const std::string& filename)
|
||||||
|
{
|
||||||
|
srslog::flush();
|
||||||
|
s = &srslog::fetch_file_sink(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
srslog::sink* s;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SRSUE_TTCN3_SWAPPABLE_SINK_H
|
Loading…
Reference in New Issue