]> git.imager.perl.org - imager.git/blobdiff - log.c
allow coverage testing to test only .c code coverage
[imager.git] / log.c
diff --git a/log.c b/log.c
index 7f3f663ec1585b087a4e65d4ecff8fd2ecd9ed45..34e4a73751619c946387d3b8a155a111fe6e86e5 100644 (file)
--- a/log.c
+++ b/log.c
@@ -30,21 +30,30 @@ im_vloog(pIMCTX, int level, const char *fmt, va_list ap);
 int
 im_init_log(pIMCTX, const char* name,int level) {
   i_clear_error();
+
+  if (aIMCTX->lg_file) {
+    if (aIMCTX->own_log)
+      fclose(aIMCTX->lg_file);
+    aIMCTX->lg_file = NULL;
+  }
+  
   aIMCTX->log_level = level;
   if (level < 0) {
     aIMCTX->lg_file = NULL;
   } else {
     if (name == NULL) {
       aIMCTX->lg_file = stderr;
+      aIMCTX->own_log = 0;
     } else {
       if (NULL == (aIMCTX->lg_file = fopen(name, "w+")) ) { 
        im_push_errorf(aIMCTX, errno, "Cannot open file '%s': (%d)", name, errno);
        return 0;
       }
+      aIMCTX->own_log = 1;
+      setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
     }
   }
   if (aIMCTX->lg_file) {
-    setvbuf(aIMCTX->lg_file, NULL, _IONBF, BUFSIZ);
     im_log((aIMCTX, 0,"Imager - log started (level = %d)\n", level));
   }
 
@@ -157,7 +166,7 @@ void i_lhead(const char *file, int line) {
  * Logging is inactive - insert dummy functions
  */
 
-int i_init_log(const char* name,int onoff) {
+int im_init_log(pIMCTX, const char* name,int onoff) {
   i_clear_error();
   i_push_error(0, "Logging disabled");
   return 0;
@@ -170,7 +179,14 @@ void
 i_loog(int level,const char *fmt, ... ) {
 }
 
+void
+im_loog(pIMCTX, int level,const char *fmt, ... ) {
+}
+
 void
 i_lhead(const char *file, int line) { }
 
+void
+im_lhead(pIMCTX, const char *file, int line) { }
+
 #endif