srsLTE/lib/include/srslte/common/logger_file.h

72 lines
2.1 KiB
C
Raw Normal View History

2019-04-26 12:27:38 -07:00
/*
* Copyright 2013-2019 Software Radio Systems Limited
2017-06-23 07:29:46 -07:00
*
2019-04-26 12:27:38 -07:00
* This file is part of srsLTE.
2017-06-23 07:29:46 -07:00
*
2019-04-26 12:27:38 -07:00
* srsLTE is free software: you can redistribute it and/or modify
2017-06-23 07:29:46 -07:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
2019-04-26 12:27:38 -07:00
* srsLTE is distributed in the hope that it will be useful,
2017-06-23 07:29:46 -07:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* File: logger_file.h
* Description: Common log object. Maintains a queue of log messages
* and runs a thread to read messages and write to file.
* Multiple producers, single consumer. If full, producers
* increase queue size. If empty, consumer blocks.
*****************************************************************************/
2018-03-31 10:04:04 -07:00
#ifndef SRSLTE_LOGGER_FILE_H
#define SRSLTE_LOGGER_FILE_H
2017-06-23 07:29:46 -07:00
#include <stdio.h>
#include <deque>
#include <string>
#include "srslte/common/logger.h"
#include "srslte/common/threads.h"
namespace srslte {
typedef std::string* str_ptr;
class logger_file : public thread, public logger
{
public:
logger_file();
logger_file(std::string file);
~logger_file();
2018-01-16 03:44:22 -08:00
void init(std::string file, int max_length = -1);
2017-06-23 07:29:46 -07:00
// Implementation of log_out
void log(str_ptr msg);
void log(const char *msg);
private:
void run_thread();
void flush();
2018-01-16 03:44:22 -08:00
uint32_t name_idx;
int64_t max_length;
int64_t cur_length;
2017-06-23 07:29:46 -07:00
FILE* logfile;
bool is_running;
2017-06-23 07:29:46 -07:00
std::string filename;
pthread_cond_t not_empty;
pthread_mutex_t mutex;
std::deque<str_ptr> buffer;
2017-06-23 07:29:46 -07:00
};
2018-03-31 10:04:04 -07:00
} // namespace srslte
2017-06-23 07:29:46 -07:00
2018-03-31 10:04:04 -07:00
#endif // SRSLTE_LOGGER_FILE_H