[med-svn] [htslib] 02/10: Replaced fprintf(stderr, ...) calls with hts_log_<level> calls.

Andreas Tille tille at debian.org
Wed Jul 19 19:54:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to annotated tag 1.5
in repository htslib.

commit f0fc3eea33477ed45f5f9ffa34f6fea7365513d8
Author: Anders Kaplan <anders.kaplan at magasin1.se>
Date:   Sat Jun 3 22:01:27 2017 +0200

    Replaced fprintf(stderr, ...) calls with hts_log_<level> calls.
---
 faidx.c             | 19 +++++++++----------
 hts.c               |  8 ++++----
 htslib/vcf.h        |  2 +-
 knetfile.c          | 24 ++++++++++++------------
 regidx.c            | 16 ++++++++--------
 sam.c               | 14 +++++++-------
 synced_bcf_reader.c | 46 ++++++++++++++++++++++++++--------------------
 tbx.c               |  5 +++--
 vcf.c               | 10 ++++------
 9 files changed, 74 insertions(+), 70 deletions(-)

diff --git a/faidx.c b/faidx.c
index bdd98cb..f85ffb5 100644
--- a/faidx.c
+++ b/faidx.c
@@ -63,7 +63,7 @@ struct __faidx_t {
 static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len, int line_len, int line_blen, uint64_t offset)
 {
     if (!name) {
-        fprintf(stderr, "[fai_build_core] malformed line\n");
+        hts_log_error("Malformed line");
         return -1;
     }
 
@@ -73,7 +73,7 @@ static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len,
     faidx1_t *v = &kh_value(idx->hash, k);
 
     if (! absent) {
-        fprintf(stderr, "[fai_build_core] ignoring duplicate sequence \"%s\" at byte offset %"PRIu64"\n", name, offset);
+        hts_log_warning("Ignoring duplicate sequence \"%s\" at byte offset %"PRIu64"", name, offset);
         free(name_key);
         return 0;
     }
@@ -82,7 +82,7 @@ static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len,
         char **tmp;
         idx->m = idx->m? idx->m<<1 : 16;
         if (!(tmp = (char**)realloc(idx->name, sizeof(char*) * idx->m))) {
-            fprintf(stderr, "[fai_build_core] out of memory\n");
+            hts_log_error("Out of memory");
             return -1;
         }
         idx->name = tmp;
@@ -130,7 +130,7 @@ faidx_t *fai_build_core(BGZF *bgzf)
             kputsn("", 0, &name);
 
             if ( c<0 ) {
-                fprintf(stderr, "[fai_build_core] the last entry has no sequence\n");
+                hts_log_error("The last entry has no sequence");
                 goto fail;
             }
             if (c != '\n') while ( (c=bgzf_getc(bgzf))>=0 && c != '\n');
@@ -138,7 +138,7 @@ faidx_t *fai_build_core(BGZF *bgzf)
             offset = bgzf_utell(bgzf);
         } else {
             if (state == 3) {
-                fprintf(stderr, "[fai_build_core] inlined empty line is not allowed in sequence '%s'.\n", name.s);
+                hts_log_error("Inlined empty line is not allowed in sequence '%s'", name.s);
                 goto fail;
             }
             if (state == 2) state = 3;
@@ -148,7 +148,7 @@ faidx_t *fai_build_core(BGZF *bgzf)
                 if (isgraph(c)) ++l2;
             } while ( (c=bgzf_getc(bgzf))>=0 && c != '\n');
             if (state == 3 && l2) {
-                fprintf(stderr, "[fai_build_core] different line length in sequence '%s'.\n", name.s);
+                hts_log_error("Different line length in sequence '%s'", name.s);
                 goto fail;
             }
             ++l1; len += l2;
@@ -498,7 +498,7 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len)
         }
     } else iter = kh_get(s, h, str);
     if(iter == kh_end(h)) {
-        fprintf(stderr, "[fai_fetch] Warning - Reference %s not found in FASTA file, returning empty sequence\n", str);
+        hts_log_warning("Reference %s not found in FASTA file, returning empty sequence", str);
         free(s);
         *len = -2;
         return 0;
@@ -523,8 +523,7 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len)
         // Check for out of range numbers.  Only going to be a problem on
         // 32-bit platforms with >2Gb sequence length.
         if (errno == ERANGE && (uint64_t) val.len > LONG_MAX) {
-            fprintf(stderr, "[fai_fetch] Positions in range %s are too large"
-                    " for this platform.\n", s);
+            hts_log_error("Positions in range %s are too large for this platform", s);
             free(s);
             *len = -2;
             return NULL;
@@ -572,7 +571,7 @@ char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p
     if (iter == kh_end(fai->hash))
     {
         *len = -2;
-        fprintf(stderr, "[fai_fetch_seq] The sequence \"%s\" not found\n", c_name);
+        hts_log_error("The sequence \"%s\" not found", c_name);
         return NULL;
     }
     val = kh_value(fai->hash, iter);
diff --git a/hts.c b/hts.c
index 2736456..355d51d 100644
--- a/hts.c
+++ b/hts.c
@@ -568,7 +568,7 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) {
         case 'k': case 'K': o->val.i *= 1024; break;
         case '\0': break;
         default:
-            fprintf(stderr, "Unrecognised cache size suffix '%c'\n", *endp);
+            hts_log_error("Unrecognised cache size suffix '%c'", *endp);
             free(o->arg);
             free(o);
             return -1;
@@ -588,7 +588,7 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) {
         o->opt = CRAM_OPT_PREFIX, o->val.s = val;
 
     else {
-        fprintf(stderr, "Unknown option '%s'\n", o->arg);
+        hts_log_error("Unknown option '%s'", o->arg);
         free(o->arg);
         free(o);
         return -1;
@@ -902,7 +902,7 @@ int hts_close(htsFile *fp)
         if (!fp->is_write) {
             switch (cram_eof(fp->fp.cram)) {
             case 2:
-                fprintf(stderr, "[W::%s] EOF marker is absent. The input is probably truncated.\n", __func__);
+                hts_log_warning("EOF marker is absent. The input is probably truncated");
                 break;
             case 0:  /* not at EOF, but may not have wanted all seqs */
             default: /* case 1, expected EOF */
@@ -1072,7 +1072,7 @@ int hts_getline(htsFile *fp, int delimiter, kstring_t *str)
 {
     int ret;
     if (! (delimiter == KS_SEP_LINE || delimiter == '\n')) {
-        fprintf(stderr, "[hts_getline] unexpected delimiter %d\n", delimiter);
+        hts_log_error("Unexpected delimiter %d", delimiter);
         abort();
     }
 
diff --git a/htslib/vcf.h b/htslib/vcf.h
index 55d6b3b..4ee8739 100644
--- a/htslib/vcf.h
+++ b/htslib/vcf.h
@@ -914,7 +914,7 @@ static inline void bcf_format_gt(bcf_fmt_t *fmt, int isample, kstring_t *str)
         case BCF_BT_INT16: BRANCH(int16_t, bcf_int16_missing, bcf_int16_vector_end); break;
         case BCF_BT_INT32: BRANCH(int32_t, bcf_int32_missing, bcf_int32_vector_end); break;
         case BCF_BT_NULL:  kputc('.', str); break;
-        default: fprintf(stderr,"FIXME: type %d in bcf_format_gt?\n", fmt->type); abort(); break;
+        default: hts_log_error("Unexpected type %d", fmt->type); abort(); break;
     }
     #undef BRANCH
 }
diff --git a/knetfile.c b/knetfile.c
index 9e8af13..dc20782 100644
--- a/knetfile.c
+++ b/knetfile.c
@@ -76,9 +76,9 @@ static int socket_wait(int fd, int is_read)
 	if (ret == -1) perror("select");
 #else
 	if (ret == 0)
-		fprintf(stderr, "select time-out\n");
+		hts_log_warning("Select timed out");
 	else if (ret == SOCKET_ERROR)
-		fprintf(stderr, "select: %d\n", WSAGetLastError());
+		hts_log_error("Select returned error %d", WSAGetLastError());
 #endif
 	return ret;
 }
@@ -99,7 +99,7 @@ static int socket_connect(const char *host, const char *port)
 	hints.ai_socktype = SOCK_STREAM;
 	/* In Unix/Mac, getaddrinfo() is the most convenient way to get
 	 * server information. */
-	if ((ai_err = getaddrinfo(host, port, &hints, &res)) != 0) { fprintf(stderr, "can't resolve %s:%s: %s\n", host, port, gai_strerror(ai_err)); return -1; }
+	if ((ai_err = getaddrinfo(host, port, &hints, &res)) != 0) { hts_log_error("Can't resolve %s:%s: %s", host, port, gai_strerror(ai_err)); return -1; }
 	if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) __err_connect("socket");
 	/* The following two setsockopt() are used by ftplib
 	 * (http://nbpfaus.net/~pfau/ftplib/). I am not sure if they
@@ -150,10 +150,10 @@ void knet_win32_destroy()
  * non-Windows OS, I do not use this one. */
 static SOCKET socket_connect(const char *host, const char *port)
 {
-#define __err_connect(func)										\
-	do {														\
-		fprintf(stderr, "%s: %d\n", func, WSAGetLastError());	\
-		return -1;												\
+#define __err_connect(func) \
+	do { \
+		hts_log_error("The %s operation returned error %d", func, WSAGetLastError()); \
+		return -1; \
 	} while (0)
 
 	int on = 1;
@@ -261,7 +261,7 @@ static int kftp_pasv_connect(knetFile *ftp)
 {
 	char host[80], port[10];
 	if (ftp->pasv_port == 0) {
-		fprintf(stderr, "[kftp_pasv_connect] kftp_pasv_prep() is not called before hand.\n");
+		hts_log_error("Must call kftp_pasv_prep() first");
 		return -1;
 	}
 	sprintf(host, "%d.%d.%d.%d", ftp->pasv_ip[0], ftp->pasv_ip[1], ftp->pasv_ip[2], ftp->pasv_ip[3]);
@@ -356,7 +356,7 @@ int kftp_connect_file(knetFile *fp)
 	kftp_pasv_connect(fp);
 	ret = kftp_get_response(fp);
 	if (ret != 150) {
-		fprintf(stderr, "[kftp_connect_file] %s\n", fp->response);
+		hts_log_error("%s", fp->response);
 		netclose(fp->fd);
 		fp->fd = -1;
 		return -1;
@@ -467,7 +467,7 @@ knetFile *knet_open(const char *fn, const char *mode)
 {
 	knetFile *fp = 0;
 	if (mode[0] != 'r') {
-		fprintf(stderr, "[knet_open] only mode \"r\" is supported.\n");
+		hts_log_error("Only mode \"r\" is supported");
 		errno = ENOTSUP;
 		return 0;
 	}
@@ -563,7 +563,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence)
 		return fp->offset;
 	} else if (fp->type == KNF_TYPE_HTTP) {
 		if (whence == SEEK_END) { // FIXME: can we allow SEEK_END in future?
-			fprintf(stderr, "[knet_seek] SEEK_END is not supported for HTTP. Offset is unchanged.\n");
+			hts_log_error("SEEK_END is not supported for HTTP. Offset is unchanged");
 			errno = ESPIPE;
 			return -1;
 		}
@@ -574,7 +574,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence)
 		return fp->offset;
 	}
 	errno = EINVAL;
-	fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
+	hts_log_error("%s", strerror(errno));
 	return -1;
 }
 
diff --git a/regidx.c b/regidx.c
index 68f92c4..5c4c77d 100644
--- a/regidx.c
+++ b/regidx.c
@@ -154,9 +154,9 @@ int regidx_insert(regidx_t *idx, char *line)
     if ( idx->rid_prev==rid )
     {
         if ( idx->start_prev > reg.start || (idx->start_prev==reg.start && idx->end_prev>reg.end) ) 
-        { 
-            fprintf(stderr,"The regions are not sorted: %s:%d-%d is before %s:%d-%d\n", 
-                idx->str.s,idx->start_prev+1,idx->end_prev+1,idx->str.s,reg.start+1,reg.end+1); 
+        {
+            hts_log_error("The regions are not sorted: %s:%d-%d is before %s:%d-%d",
+                idx->str.s,idx->start_prev+1,idx->end_prev+1,idx->str.s,reg.start+1,reg.end+1);
             return -1;
         }
     }
@@ -293,18 +293,18 @@ int regidx_parse_bed(const char *line, char **chr_beg, char **chr_end, reg_t *re
     
     char *se = ss;
     while ( *se && !isspace_c(*se) ) se++;
-    if ( !*se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; }
+    if ( !*se ) { hts_log_error("Could not parse bed line: %s", line); return -2; }
 
     *chr_beg = ss;
     *chr_end = se-1;
 
     ss = se+1;
     reg->start = hts_parse_decimal(ss, &se, 0);
-    if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; }
+    if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; }
 
     ss = se+1;
     reg->end = hts_parse_decimal(ss, &se, 0) - 1;
-    if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; }
+    if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; }
     
     return 0;
 }
@@ -318,14 +318,14 @@ int regidx_parse_tab(const char *line, char **chr_beg, char **chr_end, reg_t *re
     
     char *se = ss;
     while ( *se && !isspace_c(*se) ) se++;
-    if ( !*se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; }
+    if ( !*se ) { hts_log_error("Could not parse bed line: %s", line); return -2; }
 
     *chr_beg = ss;
     *chr_end = se-1;
 
     ss = se+1;
     reg->start = hts_parse_decimal(ss, &se, 0) - 1;
-    if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; }
+    if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; }
 
     if ( !se[0] || !se[1] )
         reg->end = reg->start;
diff --git a/sam.c b/sam.c
index a18168a..5e9c20d 100644
--- a/sam.c
+++ b/sam.c
@@ -578,7 +578,7 @@ static int sam_bam_cram_readrec(BGZF *bgzfp, void *fpv, void *bv, int *tid, int
     case cram:  return cram_get_bam_seq(fp->fp.cram, &b);
     default:
         // TODO Need headers available to implement this for SAM files
-        fprintf(stderr, "[sam_bam_cram_readrec] Not implemented for SAM files -- Exiting\n");
+        hts_log_error("Not implemented for SAM files");
         abort();
     }
 }
@@ -658,7 +658,7 @@ static hts_itr_t *cram_itr_query(const hts_idx_t *idx, int tid, int beg, int end
         iter->finished = 1;
         break;
     default:
-        fprintf(stderr, "[cram_itr_query] tid=%d not implemented for CRAM files -- Exiting\n", tid);
+        hts_log_error("Query with tid=%d not implemented for CRAM files", tid);
         abort();
         break;
     }
@@ -2035,7 +2035,7 @@ static inline int cigar_iref2iseq_set(uint32_t **cigar, uint32_t *cigar_max, int
             (*cigar)++; *icig = 0; *iref += ncig;
             continue;
         }
-        fprintf(stderr,"todo: cigar %d\n", cig);
+        hts_log_error("Unexpected cigar %d", cig);
         assert(0);
     }
     *iseq = -1;
@@ -2058,7 +2058,7 @@ static inline int cigar_iref2iseq_next(uint32_t **cigar, uint32_t *cigar_max, in
         if ( cig==BAM_CINS ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
         if ( cig==BAM_CSOFT_CLIP ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; }
         if ( cig==BAM_CHARD_CLIP || cig==BAM_CPAD ) { (*cigar)++; *icig = 0; continue; }
-        fprintf(stderr,"todo: cigar %d\n", cig);
+        hts_log_error("Unexpected cigar %d", cig);
         assert(0);
     }
     *iseq = -1;
@@ -2228,7 +2228,7 @@ const bam_pileup1_t *bam_plp_next(bam_plp_t iter, int *_tid, int *_pos, int *_n_
         // update iter->tid and iter->pos
         if (iter->head != iter->tail) {
             if (iter->tid > iter->head->b.core.tid) {
-                fprintf(stderr, "[%s] unsorted input. Pileup aborts.\n", __func__);
+                hts_log_error("Unsorted input. Pileup aborts");
                 iter->error = 1;
                 *_n_plp = -1;
                 return NULL;
@@ -2267,12 +2267,12 @@ int bam_plp_push(bam_plp_t iter, const bam1_t *b)
         iter->tail->end = bam_endpos(b);
         iter->tail->s = g_cstate_null; iter->tail->s.end = iter->tail->end - 1; // initialize cstate_t
         if (b->core.tid < iter->max_tid) {
-            fprintf(stderr, "[bam_pileup_core] the input is not sorted (chromosomes out of order)\n");
+            hts_log_error("The input is not sorted (chromosomes out of order)");
             iter->error = 1;
             return -1;
         }
         if ((b->core.tid == iter->max_tid) && (iter->tail->beg < iter->max_pos)) {
-            fprintf(stderr, "[bam_pileup_core] the input is not sorted (reads out of order)\n");
+            hts_log_error("The input is not sorted (reads out of order)");
             iter->error = 1;
             return -1;
         }
diff --git a/synced_bcf_reader.c b/synced_bcf_reader.c
index 9c2de9d..47715da 100644
--- a/synced_bcf_reader.c
+++ b/synced_bcf_reader.c
@@ -149,7 +149,7 @@ int bcf_sr_set_regions(bcf_srs_t *readers, const char *regions, int is_file)
     assert( !readers->regions );
     if ( readers->nreaders )
     {
-        fprintf(stderr,"[%s:%d %s] Error: bcf_sr_set_regions() must be called before bcf_sr_add_reader()\n", __FILE__,__LINE__,__FUNCTION__);
+        hts_log_error("Must call bcf_sr_set_regions() before bcf_sr_add_reader()");
         return -1;
     }
     readers->regions = bcf_sr_regions_init(regions,is_file,0,1,-2);
@@ -220,7 +220,7 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname)
         BGZF *bgzf = hts_get_bgzfp(reader->file);
         if ( bgzf && bgzf_check_EOF(bgzf) == 0 ) {
             files->errnum = no_eof;
-            fprintf(stderr,"[%s] Warning: no BGZF EOF marker; file may be truncated.\n", fname);
+            hts_log_warning("No BGZF EOF marker; file '%s' may be truncated", fname);
         }
         if (files->p)
             bgzf_thread_pool(bgzf, files->p->pool, files->p->qsize);
@@ -284,13 +284,13 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname)
     if ( files->streaming && files->nreaders>1 )
     {
         files->errnum = api_usage_error;
-        fprintf(stderr,"[%s:%d %s] Error: %d readers, yet require_index not set\n", __FILE__,__LINE__,__FUNCTION__,files->nreaders);
+        hts_log_error("Must set require_index when the number of readers is greater than one");
         return 0;
     }
     if ( files->streaming && files->regions )
     {
         files->errnum = api_usage_error;
-        fprintf(stderr,"[%s:%d %s] Error: cannot tabix-jump in streaming mode\n", __FILE__,__LINE__,__FUNCTION__);
+        hts_log_error("Cannot tabix-jump in streaming mode");
         return 0;
     }
     if ( !reader->header )
@@ -422,7 +422,7 @@ static int _reader_seek(bcf_sr_t *reader, const char *seq, int start, int end)
 {
     if ( end>=MAX_CSI_COOR )
     {
-        fprintf(stderr,"The coordinate is out of csi index limit: %d\n", end+1);
+        hts_log_error("The coordinate is out of csi index limit: %d", end+1);
         exit(1);
     }
     if ( reader->itr )
@@ -443,8 +443,10 @@ static int _reader_seek(bcf_sr_t *reader, const char *seq, int start, int end)
         if ( tid==-1 ) return -1;    // the sequence not present in this file
         reader->itr = bcf_itr_queryi(reader->bcf_idx,tid,start,end+1);
     }
-    if ( !reader->itr ) fprintf(stderr,"Could not seek: %s:%d-%d\n",seq,start+1,end+1);
-    assert(reader->itr);
+    if (!reader->itr) {
+        hts_log_error("Could not seek: %s:%d-%d", seq, start + 1, end + 1);
+        assert(0);
+    }
     return 0;
 }
 
@@ -517,7 +519,7 @@ static void _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader)
             }
             else
             {
-                fprintf(stderr,"[%s:%d %s] fixme: not ready for this\n", __FILE__,__LINE__,__FUNCTION__);
+                hts_log_error("Fixme: not ready for this");
                 exit(1);
             }
         }
@@ -693,7 +695,7 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file)
         smpl = hts_readlist(fname, is_file, &nsmpl);
         if ( !smpl )
         {
-            fprintf(stderr,"Could not read the file: \"%s\"\n", fname);
+            hts_log_error("Could not read the file: \"%s\"", fname);
             return 0;
         }
         if ( exclude )
@@ -723,7 +725,8 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file)
         }
         if ( n_isec!=files->nreaders )
         {
-            fprintf(stderr,"Warning: The sample \"%s\" was not found in %s, skipping\n", smpl[i], files->readers[n_isec].fname);
+            hts_log_warning("The sample \"%s\" was not found in %s, skipping",
+                smpl[i], files->readers[n_isec].fname);
             continue;
         }
 
@@ -741,7 +744,7 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file)
     if ( !files->n_smpl )
     {
         if ( files->nreaders>1 )
-            fprintf(stderr,"No samples in common.\n");
+            hts_log_warning("No samples in common");
         return 0;
     }
     for (i=0; i<files->nreaders; i++)
@@ -828,7 +831,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str)
             from = hts_parse_decimal(sp,(char**)&ep,0);
             if ( sp==ep )
             {
-                fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str);
+                hts_log_error("Could not parse the region(s): %s", str);
                 free(reg); free(tmp.s); return NULL;
             }
             if ( !*ep || *ep==',' )
@@ -839,7 +842,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str)
             }
             if ( *ep!='-' )
             {
-                fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str);
+                hts_log_error("Could not parse the region(s): %s", str);
                 free(reg); free(tmp.s); return NULL;
             }
             ep++;
@@ -847,7 +850,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str)
             to = hts_parse_decimal(sp,(char**)&ep,0);
             if ( *ep && *ep!=',' )
             {
-                fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str);
+                hts_log_error("Could not parse the region(s): %s", str);
                 free(reg); free(tmp.s); return NULL;
             }
             if ( sp==ep ) to = MAX_CSI_COOR-1;
@@ -939,7 +942,7 @@ bcf_sr_regions_t *bcf_sr_regions_init(const char *regions, int is_file, int ichr
     reg->file = hts_open(regions, "rb");
     if ( !reg->file )
     {
-        fprintf(stderr,"[%s:%d %s] Could not open file: %s\n", __FILE__,__LINE__,__FUNCTION__,regions);
+        hts_log_error("Could not open file: %s", regions);
         free(reg);
         return NULL;
     }
@@ -965,7 +968,8 @@ bcf_sr_regions_t *bcf_sr_regions_init(const char *regions, int is_file, int ichr
                     ret = _regions_parse_line(reg->line.s, ichr,ifrom,ifrom, &chr,&chr_end,&from,&to);
                 if ( ret<0 )
                 {
-                    fprintf(stderr,"[%s:%d] Could not parse the file %s, using the columns %d,%d[,%d]\n", __FILE__,__LINE__,regions,ichr+1,ifrom+1,ito+1);
+                    hts_log_error("Could not parse the file %s, using the columns %d,%d[,%d]",
+                        regions,ichr+1,ifrom+1,ito+1);
                     hts_close(reg->file); reg->file = NULL; free(reg);
                     return NULL;
                 }
@@ -1092,7 +1096,7 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg)
                 reg->file = hts_open(reg->fname, "r");
                 if ( !reg->file )
                 {
-                    fprintf(stderr,"[%s:%d %s] Could not open file: %s\n", __FILE__,__LINE__,__FUNCTION__,reg->fname);
+                    hts_log_error("Could not open file: %s", reg->fname);
                     reg->file = NULL;
                     bcf_sr_regions_destroy(reg);
                     return -1;
@@ -1107,7 +1111,8 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg)
         ret = _regions_parse_line(reg->line.s, ichr,ifrom,ito, &chr,&chr_end,&from,&to);
         if ( ret<0 )
         {
-            fprintf(stderr,"[%s:%d] Could not parse the file %s, using the columns %d,%d,%d\n", __FILE__,__LINE__,reg->fname,ichr+1,ifrom+1,ito+1);
+            hts_log_error("Could not parse the file %s, using the columns %d,%d,%d",
+                reg->fname,ichr+1,ifrom+1,ito+1);
             return -1;
         }
     }
@@ -1116,7 +1121,8 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg)
     *chr_end = 0;
     if ( khash_str2int_get(reg->seq_hash, chr, &reg->iseq)<0 )
     {
-        fprintf(stderr,"Broken tabix index? The sequence \"%s\" not in dictionary [%s]\n", chr,reg->line.s);
+        hts_log_error("Broken tabix index? The sequence \"%s\" not in dictionary [%s]",
+            chr, reg->line.s);
         exit(1);
     }
     *chr_end = '\t';
@@ -1131,7 +1137,7 @@ static int _regions_match_alleles(bcf_sr_regions_t *reg, int als_idx, bcf1_t *re
     if ( reg->regs )
     {
         // payload is not supported for in-memory regions, switch to regidx instead in future
-        fprintf(stderr,"Error: Compressed and indexed targets file is required\n");
+        hts_log_error("Compressed and indexed targets file is required");
         exit(1);
     }
 
diff --git a/tbx.c b/tbx.c
index e92d2d7..1d4b6b5 100644
--- a/tbx.c
+++ b/tbx.c
@@ -158,7 +158,8 @@ static inline int get_intv(tbx_t *tbx, kstring_t *str, tbx_intv_t *intv, int is_
             case TBX_UCSC: type = "TBX_UCSC"; break;
             default: type = "TBX_GENERIC"; break;
         }
-        fprintf(stderr, "[E::%s] failed to parse %s, was wrong -p [type] used?\nThe offending line was: \"%s\"\n", __func__, type, str->s);
+        hts_log_error("Failed to parse %s, was wrong -p [type] used?\nThe offending line was: \"%s\"",
+            type, str->s);
         return -1;
     }
 }
@@ -319,7 +320,7 @@ tbx_t *tbx_index_load2(const char *fn, const char *fnidx)
     // of whatever it reads.
     for (; p - nm < l_nm; p += strlen(p) + 1) {
         if (get_tid(tbx, p, 1) < 0) {
-            fprintf(stderr, "[E::%s] %s\n", __func__, strerror(errno));
+            hts_log_error("%s", strerror(errno));
             goto fail;
         }
     }
diff --git a/vcf.c b/vcf.c
index 2214dd4..e1f871e 100644
--- a/vcf.c
+++ b/vcf.c
@@ -496,15 +496,13 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec)
     }
     if (hrec->type == BCF_HL_INFO || hrec->type == BCF_HL_FMT) {
         if (type == -1) {
-            if (hts_verbose >= 2)
-                fprintf(stderr, "[E::%s] %s %s field has no Type defined. Assuming String\n",
-                        __func__, *hrec->key == 'I' ? "An" : "A", hrec->key);
+            hts_log_warning("%s %s field has no Type defined. Assuming String",
+                *hrec->key == 'I' ? "An" : "A", hrec->key);
             type = BCF_HT_STR;
         }
         if (var == -1) {
-            if (hts_verbose >= 2)
-                fprintf(stderr, "[E::%s] %s %s field has no Number defined. Assuming '.'\n",
-                        __func__, *hrec->key == 'I' ? "An" : "A", hrec->key);
+            hts_log_warning("%s %s field has no Number defined. Assuming '.'",
+                *hrec->key == 'I' ? "An" : "A", hrec->key);
             var = BCF_VL_VAR;
         }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/htslib.git



More information about the debian-med-commit mailing list