Skip to content

Commit

Permalink
Refactored logger setup code to improve clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccoystephenson committed Feb 1, 2024
1 parent 346265b commit f10bc08
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
10 changes: 7 additions & 3 deletions include/acm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class ASN1_Codec : public tool::Tool {
const char* getEnvironmentVariable(const char* variableName);

/**
* @brief Create and setup the two loggers used for the ASN1_Codec. The locations and filenames for the logs can be specified
* @brief Create and setup the logger used for the ASN1_Codec. The locations and filenames for the logs can be specified
* using command line parameters. The CANNOT be set via the configuration file, since these loggers are setup
* prior to the configuration file being read.
*
Expand All @@ -231,8 +231,12 @@ class ASN1_Codec : public tool::Tool {
*
* @return true upon success; false if some failure occurred during logger setup.
*/
bool make_loggers( bool remove_files );
bool make_loggers_testing();
bool setup_logger( bool remove_files );

/**
* @brief Set up the logger for testing
*/
bool setup_logger_for_testing();

private:

Expand Down
2 changes: 1 addition & 1 deletion include/acm_blob_producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ACMBlobProducer : public tool::Tool {
*
* @return true upon success; false if some failure occurred during logger setup.
*/
bool make_loggers( bool remove_files );
bool setup_logger( bool remove_files );

private:

Expand Down
12 changes: 8 additions & 4 deletions src/acm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ bool ASN1_Codec::launch_consumer(){
return true;
}

bool ASN1_Codec::make_loggers( bool remove_files ) {
bool ASN1_Codec::setup_logger( bool remove_files ) {
// defaults.
std::string path{ "logs/" };
std::string logname{ "log.info" };
Expand Down Expand Up @@ -702,8 +702,12 @@ bool ASN1_Codec::make_loggers( bool remove_files ) {
return true;
}

bool ASN1_Codec::make_loggers_testing() {
logger = std::make_shared<AcmLogger>("testlog");
/**
* @brief This method is used to setup the logger for testing purposes.
*/
bool ASN1_Codec::setup_logger_for_testing() {
std::string TEST_LOGGER_FILE_NAME = "test_logger_file.log";
logger = std::make_shared<AcmLogger>(TEST_LOGGER_FILE_NAME);
return true;
}

Expand Down Expand Up @@ -1970,7 +1974,7 @@ int main( int argc, char* argv[] )
}

// can set levels if needed here.
if ( !asn1_codec.make_loggers( asn1_codec.optIsSet('R') )) {
if ( !asn1_codec.setup_logger( asn1_codec.optIsSet('R') )) {
std::exit( EXIT_FAILURE );
}

Expand Down
4 changes: 2 additions & 2 deletions src/acm_blob_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bool ACMBlobProducer::launch_producer()
return true;
}

bool ACMBlobProducer::make_loggers( bool remove_files )
bool ACMBlobProducer::setup_logger( bool remove_files )
{
// defaults.
std::string path{ "logs/" };
Expand Down Expand Up @@ -533,7 +533,7 @@ int main(int argc, char* argv[])
}

// can set levels if needed here.
if (!acm_blob_producer.make_loggers((acm_blob_producer.optIsSet('R')))) {
if (!acm_blob_producer.setup_logger((acm_blob_producer.optIsSet('R')))) {
std::exit(EXIT_FAILURE);
}

Expand Down
20 changes: 10 additions & 10 deletions src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const char *ASD_ONE609_HEX = "44400000000084782786283B90A7148D2B0A89C49F8A85A776
*/
// TEST_CASE("Encode BSM", "[encoding]" ) { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out1;
// CHECK(asn1_codec.file_test("unit-test-data/BSM.xml", out1) == EXIT_SUCCESS);
Expand All @@ -60,7 +60,7 @@ TEST_CASE("Encode ASD", "[encoding]" ) {
std::cout << "=== Encode ASD ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out2;
CHECK(asn1_codec.file_test("unit-test-data/ASD.xml", out2) == EXIT_SUCCESS);
Expand All @@ -79,7 +79,7 @@ TEST_CASE("Encode ASD", "[encoding]" ) {
*/
// TEST_CASE("Encode ASD_BSM", "[encoding]" ) { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();
// std::stringstream out3;
// CHECK(asn1_codec.file_test("unit-test-data/ASD_BSM.xml", out3) == EXIT_SUCCESS);
// parse_result = output_doc.load(out3, pugi::parse_default | pugi::parse_declaration | pugi::parse_doctype | pugi::parse_trim_pcdata);
Expand All @@ -98,7 +98,7 @@ TEST_CASE("Encode 1609", "[encoding]" ) {
std::cout << "=== Encode 1609 ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out4;
CHECK(asn1_codec.file_test("unit-test-data/1609.xml", out4) == EXIT_SUCCESS);
Expand All @@ -115,7 +115,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
std::cout << "=== Encode ASD_1609 ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out5;
CHECK(asn1_codec.file_test("unit-test-data/ASD_1609.xml", out5) == EXIT_SUCCESS);
Expand All @@ -137,7 +137,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
*/
// TEST_CASE("Encode 1609_BSM", "[encoding]") { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out6;
// CHECK(asn1_codec.file_test("unit-test-data/1609_BSM.xml", out6) == EXIT_SUCCESS);
Expand All @@ -159,7 +159,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
*/
// TEST_CASE("Encode ASD_1609_BSM", "[encoding]") { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out7;
// CHECK(asn1_codec.file_test("unit-test-data/ASD_1609_BSM.xml", out7) == EXIT_SUCCESS);
Expand All @@ -182,7 +182,7 @@ TEST_CASE("Encode TIM with payload type 'OdeTimPayload'", "[encoding][odetimpayl
std::cout << "=== Encode TIM with payload type 'OdeTimPayload' ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out8;
CHECK(asn1_codec.file_test("data/InputData.encoding.tim.odetimpayload.xml", out8) == EXIT_SUCCESS);
Expand All @@ -196,7 +196,7 @@ TEST_CASE("Encode TIM with payload type 'OdeAsdPayload'", "[encoding][odeasdpayl
std::cout << "=== Encode TIM with payload type 'OdeAsdPayload' ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out8;
CHECK(asn1_codec.file_test("data/InputData.encoding.tim.odeasdpayload.xml", out8) == EXIT_SUCCESS);
Expand All @@ -212,7 +212,7 @@ TEST_CASE("Decode BSM", "[decoding]") {
std::cout << "=== Decode BSM ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out9;
CHECK(asn1_codec.file_test("data/InputData.decoding.bsm.xml", out9, false) == EXIT_SUCCESS);
Expand Down

0 comments on commit f10bc08

Please sign in to comment.