set up log files

This commit is contained in:
Nam Tran
2020-11-24 18:36:58 -06:00
parent 14070f8017
commit a561e6b428
2 changed files with 18 additions and 8 deletions

View File

@@ -25,10 +25,10 @@ Channel::Channel(char const * ptr, size_t len) {
void Channel::Print(){ void Channel::Print(){
if (valid) { if (valid) {
spdlog::info("channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}", spdlog::get("zynqDump")->info("channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}",
id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]); id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]);
} }
else { else {
spdlog::info("Invalid channel"); spdlog::get("zynqDump")->info("Invalid channel");
} }
} }

View File

@@ -15,6 +15,7 @@
#include <csignal> #include <csignal>
#include "channel.h" #include "channel.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"
const char * HOST = "192.168.30.89"; const char * HOST = "192.168.30.89";
const uint32_t PORT = 9999; const uint32_t PORT = 9999;
@@ -123,7 +124,7 @@ int main(int argc, char * argv[])
else{ else{
// read in first 4 bytes // read in first 4 bytes
nread = recv(sock, char_buffer, 4, 0); nread = recv(sock, char_buffer, 4, 0);
spdlog::info("read in {:d} bytes: 0x{:X}", nread, wordData[0]); spdlog::get("zynqDump")->debug("read in {:d} bytes: 0x{:X}", nread, wordData[0]);
// if not A5 marker, go to next iteration (read in 4 more bytes) // if not A5 marker, go to next iteration (read in 4 more bytes)
if ((char_buffer[0] & 0xFF) != 0xA5){ if ((char_buffer[0] & 0xFF) != 0xA5){
bad_data = true; bad_data = true;
@@ -140,14 +141,14 @@ int main(int argc, char * argv[])
} }
else { else {
// ok, this seems to be good data // ok, this seems to be good data
spdlog::info("next {:d} bytes (expecting {:d}): {:X} {:X} {:X} {:X}", spdlog::get("zynqDump")->debug("next {:d} bytes (expecting {:d}): {:X} {:X} {:X} {:X}",
nread, frameSize - 4, wordData[0], wordData[1], wordData[2], wordData[3]); nread, frameSize - 4, wordData[0], wordData[1], wordData[2], wordData[3]);
spdlog::info("{:X} {:X} {:X} {:X}", wordData[4], wordData[5], wordData[6], wordData[7]); spdlog::get("zynqDump")->debug("{:X} {:X} {:X} {:X}", wordData[4], wordData[5], wordData[6], wordData[7]);
uint8_t board_id = (wordData[0] >> 24) & 0xFF; uint8_t board_id = (wordData[0] >> 24) & 0xFF;
uint8_t version = wordData[0] & 0xFF; uint8_t version = wordData[0] & 0xFF;
uint16_t spill_id = (wordData[1] & 0x00FFFF00) >> 8; uint16_t spill_id = (wordData[1] & 0x00FFFF00) >> 8;
uint8_t channel_count = (wordData[1]) & 0x000000FF; uint8_t channel_count = (wordData[1]) & 0x000000FF;
spdlog::info("board {}, version {}, spill {}, channel_count {}", spdlog::get("zynqDump")->info("board {}, version {}, spill {}, channel_count {}",
static_cast<uint32_t>(board_id), static_cast<uint32_t>(board_id),
static_cast<uint32_t>(version), static_cast<uint32_t>(version),
static_cast<uint32_t>(spill_id), static_cast<uint32_t>(spill_id),
@@ -164,7 +165,7 @@ int main(int argc, char * argv[])
bytes_processed += process_channel(char_buffer + 2 * sizeof(uint32_t) + bytes_processed, bytes_processed += process_channel(char_buffer + 2 * sizeof(uint32_t) + bytes_processed,
bytes_left - bytes_processed); bytes_left - bytes_processed);
} }
spdlog::info("Done, {} bytes processed.", bytes_processed); spdlog::get("zynqDump")->debug("Done, {} bytes processed.", bytes_processed);
} }
} }
@@ -177,7 +178,7 @@ int main(int argc, char * argv[])
} }
void signalHandler( int signum ) { void signalHandler( int signum ) {
spdlog::info("Interrupt signal ({}) received, exiting...", signum); spdlog::get("zynqDump")->info("Interrupt signal ({}) received, exiting...", signum);
running = false; running = false;
} }
@@ -206,4 +207,13 @@ int open_socket(){
} }
void setup_logger(){ void setup_logger(){
try {
auto max_size = 1048576 * 5;
auto max_files = 3;
auto logger = spdlog::rotating_logger_mt("zynqDump", "logs/dump.txt", max_size, max_files);
}
catch (const spdlog::spdlog_ex &ex) {
std::cerr << "Log init failed: " << ex.what() << std::endl;
exit(-1);
}
} }