have LOGF macros add a newline, so user code doesn't need to.

This commit is contained in:
Nils O. Selåsdal
2014-10-06 21:52:28 +02:00
parent 33b48c4276
commit 9bd1336d26
4 changed files with 95 additions and 94 deletions
+70 -70
View File
@@ -53,15 +53,15 @@ START_TEST (test_logfile_location)
uc_log_add_destination(dest);
uc_log_add_destination(dest); //adding this twice should do nothing
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2\n");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3\n");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4\n");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5\n");
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 380, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_logfile_delete_destination)
@@ -87,28 +87,28 @@ START_TEST (test_logfile_delete_destination)
uc_log_add_destination(dest);
uc_log_add_destination(dest); //adding this twice should do nothing
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2\n");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3\n");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4\n");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5\n");
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 380, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
uc_log_delete_destination(dest);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2\n");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3\n");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4\n");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5\n");
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson 2");
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson 3");
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson 4");
UC_LOGF(UC_LL_ERROR, 0, "Lorum ipson 5");
//since we deleted destinatiion, no more logging should appear in the file
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 380, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
END_TEST
@@ -134,12 +134,12 @@ START_TEST (test_logfile_no_location)
fail_if(dest == NULL);
uc_log_add_destination(dest);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 52*2, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 52*2, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_logfile_loglevel_surpressed_dest)
@@ -169,9 +169,9 @@ START_TEST (test_logfile_loglevel_surpressed_dest)
UC_LOGF(UC_LL_INFO, 1, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_logfile_loglevel_surpressed_module)
@@ -201,9 +201,9 @@ START_TEST (test_logfile_loglevel_surpressed_module)
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 100);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_logfile_reopen_files)
@@ -228,24 +228,24 @@ START_TEST (test_logfile_reopen_files)
fail_if(dest == NULL);
uc_log_add_destination(dest);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
rc = remove(FILE_NAME);
fail_if(rc != 0, "Remove failed %s\n", strerror(errno));
fail_if(rc != 0, "Remove failed %s", strerror(errno));
rc = uc_log_reopen_files();
fail_if(rc != 0, "uc_log_reopen_files failed: %d\n", rc);
fail_if(rc != 0, "uc_log_reopen_files failed: %d", rc);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "2. stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 77, "was %ld\n", (long)st.st_size);//should only one line there now
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
fail_if(st.st_size != 77, "was %ld", (long)st.st_size);//should only one line there now
END_TEST
@@ -277,29 +277,29 @@ START_TEST (test_logfile_remove_dest)
uc_log_add_destination(dest1);
uc_log_add_destination(dest2);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
uc_log_remove_destination(dest1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1); //should not be logged now
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1); //should not be logged now
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "2. stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld\n", (long)st.st_size);//should be same size
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
//removing the last destination should be fine too
uc_log_remove_destination(dest2);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "2. stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld\n", (long)st.st_size);//should be same size
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
END_TEST
@@ -326,9 +326,9 @@ START_TEST (test_logfile_full_filesystem)
uc_log_add_destination(dest);
for (i = 0; i < 1024; i++) {
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1);
}
END_TEST
@@ -370,7 +370,7 @@ START_TEST (test_logfile_invalid_file_after_reopen)
int rc;
uc_log_init(&mods);
printf("SUBDIR_FILE_NAME= " SUBDIR_FILE_NAME " \n");
printf("SUBDIR_FILE_NAME= " SUBDIR_FILE_NAME " ");
dest = uc_log_new_file(SUBDIR_FILE_NAME, UC_LL_DEBUG, 1);
fail_if(dest == NULL);
@@ -378,18 +378,18 @@ START_TEST (test_logfile_invalid_file_after_reopen)
logging_rm_subdir();
rc = access(SUBDIR_FILE_NAME, W_OK);
fail_if(rc == 0, "Test setup is wrong. Can still access" SUBDIR_FILE_NAME "\n");
fail_if(rc == 0, "Test setup is wrong. Can still access" SUBDIR_FILE_NAME "");
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1);
uc_log_reopen_files();
//this should not crash now.
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d", 1);
END_TEST
@@ -419,8 +419,8 @@ START_TEST (test_logfile_raw)
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_logfile_dest_mask)
@@ -454,19 +454,19 @@ START_TEST (test_logfile_dest_mask)
uc_log_add_destination(dest);
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
uc_log_destination_set_mask(dest, "MOD1=DEBUG:mod2=Debug");
UC_LOGFR(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGFR(UC_LL_DEBUG, 1, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 14*2, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_loglevel_module_none)
@@ -494,8 +494,8 @@ START_TEST (test_loglevel_module_none)
UC_LOGFR(UC_LL_ERROR, 0, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
END_TEST
START_TEST (test_loglevel_dest_none)
@@ -523,8 +523,8 @@ START_TEST (test_loglevel_dest_none)
UC_LOGFR(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
rc = stat(FILE_NAME, &st);
fail_if(rc != 0, "stat failed: %s\n", strerror(errno));
fail_if(st.st_size != 0, "was %ld\n", (long)st.st_size);
fail_if(rc != 0, "stat failed: %s", strerror(errno));
fail_if(st.st_size != 0, "was %ld", (long)st.st_size);
END_TEST