Branch Coverage

Logger.xs
Criterion Covered Total %
branch 130 184 70.6


line true false branch
20 71 0 if ( sv && SvPOK(sv) )
71 0 if ( sv && SvPOK(sv) )
21 71 0 path = SvPV_nolen( sv );
30 34 34 if ( strlen(self->filepath) )
53 0 100 if ( level == LOG_DISABLE ) /* to move earlier */
61 63 37 if ( mylogger ) { /* we got a mylogger pointer */
64 50 13 if ( mylogger->pid && mylogger->pid != pid ) {
1 49 if ( mylogger->pid && mylogger->pid != pid ) {
65 1 0 if (mylogger->fhandle) fclose(mylogger->fhandle);
68 14 49 if ( ! mylogger->fhandle ) {
69 0 14 if ( (fhandle = fopen( path, "a" )) == NULL ) /* open in append mode */
74 14 0 ACQUIRE_LOCK_ONCE(fhandle); /* get a lock before moving to the end */
83 0 37 if ( (fhandle = fopen( path, "a" )) == NULL ) /* open in append mode */
86 37 0 ACQUIRE_LOCK_ONCE(fhandle); /* get a lock before moving to the end */
90 100 0 if ( fhandle ) {
93 58 42 if (num_args) va_start(args, num_args);
95 49 51 ACQUIRE_LOCK_ONCE(fhandle);
99 63 37 if ( mylogger && mylogger->use_color ) {
56 7 if ( mylogger && mylogger->use_color ) {
100 56 0 M_FPRINTF( fhandle, "[%s %s%02d%02d] %s%-5s%s",
3 53 M_FPRINTF( fhandle, "[%s %s%02d%02d] %s%-5s%s",
3 0 M_FPRINTF( fhandle, "[%s %s%02d%02d] %s%-5s%s",
108 44 0 M_FPRINTF( fhandle, "[%s %s%02d%02d] %-5s",
37 7 M_FPRINTF( fhandle, "[%s %s%02d%02d] %-5s",
37 0 M_FPRINTF( fhandle, "[%s %s%02d%02d] %-5s",
119 0 100 if ( !SvPOK(dollar_0) ) { /* probably a better helper to simply get the PV at all cost */
120 0 0 if ( SvIOK(dollar_0) )
121 0 0 SvUPGRADE(dollar_0, SVt_PVIV);
125 0 100 str_dollar_0 = SvPV_nolen( dollar_0 );
126 40 60 M_FPRINTF( fhandle, " %u [%s] ", (unsigned int) pid, str_dollar_0 ); /* print the source */
134 100 0 if ( fmt && (len=strlen(fmt)) ) {
58 42 if ( fmt && (len=strlen(fmt)) ) {
135 0 58 if (num_args == 0) /* no need to use sprintf when not needed */
136 0 0 M_FPUTS( fmt, fhandle )
138 25 33 M_VFPRINTF( fhandle, fmt, args )
25 33 M_VFPRINTF( fhandle, fmt, args )
141 58 42 if ( !len || fmt[len-1] != '\n')
57 1 if ( !len || fmt[len-1] != '\n')
142 40 59 M_FPUTS( "\n", fhandle );
144 63 37 if (has_logger_object) fflush(fhandle); /* otherwise we are going to close the ffhandle just after */
145 58 42 if (num_args) va_end(args);
148 100 0 RELEASE_LOCK(fhandle); /* only release if acquired before */
150 37 63 if ( !has_logger_object ) fclose( fhandle );
178 16 5 if( items > 1 ) { /* could also probably use va_start, va_list, ... */
181 16 0 if ( SvROK(extra) && SvTYPE(SvRV(extra)) == SVt_PVHV )
16 0 if ( SvROK(extra) && SvTYPE(SvRV(extra)) == SVt_PVHV )
187 16 5 if ( opts ) {
188 3 13 if ( (svp = hv_fetchs(opts, "color", FALSE)) ) {
189 0 3 if (!SvIOK(*svp)) croak("invalid color option value: should be a boolean 1/0");
190 3 0 mylogger->use_color = (bool) SvIV(*svp);
192 6 10 if ( (svp = hv_fetchs(opts, "level", FALSE)) ) {
193 0 6 if (!SvIOK(*svp)) croak("invalid log level: should be one integer");
194 6 0 mylogger->level = (logLevel) SvIV(*svp);
196 13 3 if ( (svp = hv_fetchs(opts, "quiet", FALSE)) ) {
197 0 13 if (!SvIOK(*svp)) croak("invalid quiet value: should be one integer 0 or 1");
198 13 0 mylogger->quiet = (logLevel) SvIV(*svp);
200 13 3 if ( (svp = hv_fetchs(opts, "logfile", FALSE)) || (svp = hv_fetchs(opts, "path", FALSE)) ) {
3 10 if ( (svp = hv_fetchs(opts, "logfile", FALSE)) || (svp = hv_fetchs(opts, "path", FALSE)) ) {
204 0 6 if (!SvPOK(*svp)) croak("invalid logfile path: must be a string");
205 6 0 src = SvPV(*svp, len);
206 0 6 if (len >= sizeof(mylogger->filepath))
265 100 15 if ( items && SvROK(ST(0)) && SvOBJECT(SvRV(ST(0))) ) { /* check if self is an object */
78 22 if ( items && SvROK(ST(0)) && SvOBJECT(SvRV(ST(0))) ) { /* check if self is an object */
78 0 if ( items && SvROK(ST(0)) && SvOBJECT(SvRV(ST(0))) ) { /* check if self is an object */
268 78 0 mylogger = INT2PTR(MyLogger*, SvIV(SvRV(self)));
270 10 68 if ( level < mylogger->level )
274 105 10 if (dolog) {
276 42 63 if ( items < (1 + args_start_at) ) {
279 58 5 } else if ( items <= ( 11 + args_start_at ) ) { /* set a cap on the maximum of item we can use: 10 arguments + 1 format + 1 for self */
284 125 58 for ( i = args_start_at ; i < items ; ++i ) {
286 0 125 if ( !SvOK(sv) )
0 0 if ( !SvOK(sv) )
0 0 if ( !SvOK(sv) )
290 58 67 if ( i == args_start_at ) { /* the first entry shoulkd be the format */
291 1 57 if ( !SvPOK(sv) ) { /* maybe upgrade to a PV */
292 1 0 if ( SvIOK(sv) )
293 1 0 SvUPGRADE(sv, SVt_PVIV);
297 57 1 fmt = SvPV_nolen( sv );
301 61 6 if ( SvIOK(sv) ) { /* SvTYPE(sv) == SVt_IV */
302 61 0 targs[ix].ival = SvIV(sv);
303 1 5 } else if ( SvNOK(sv) ) { // not working for now
306 1 0 targs[ix].fval = SvNV(sv);
308 5 0 targs[ix].sval = SvPV_nolen(sv);
381 24 86 if ( should_die ) /* maybe fatal needs to exit */ {
447 0 1 if ( !SvIOK(value) ) croak("invalid level: must be interger.");
448 1 0 self->level = SvIV(value);
451 0 1 if ( !SvIOK(value) ) croak("invalid quiet value: must be interger.");
452 1 0 self->quiet = SvIV(value);
469 21 0 if ( self ) {
471 13 8 if ( self->fhandle )
477 21 0 if (PL_markstack_ptr != temp) {
502 8 1 if ( ! SvPOK(sv) ) { /* preserve any value set before loading the module */