Browse code

stats.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 19:23:10
Showing 1 changed files
... ...
@@ -92,20 +92,19 @@ static int sipStatusCodes_handler(struct sip_snmp_obj *o, enum handler_op op);
92 92
 
93 93
 int init_stats(int nr_of_processes)
94 94
 {
95
-	LOG(L_DBG,"init_stats(): initializing stats for %d processes\n", 
95
+	LM_DBG("initializing stats for %d processes\n", 
96 96
 		nr_of_processes);
97 97
 
98 98
 
99 99
 	global_stats = shm_malloc(nr_of_processes*sizeof(struct stats_s));
100 100
 	if(!global_stats) {
101
-		LOG(L_ERR, "Out of memory\n");
101
+		LM_ERR("Out of memory\n");
102 102
 		return -1;
103 103
 	}
104 104
 	stats_segments = nr_of_processes;
105 105
 
106 106
 	if(stats_register() == -1)
107
-		LOG(L_WARN, "init_stats(): Couldn't register stats"
108
-					" with snmp module\n");
107
+		LM_WARN("Couldn't register stats with snmp module\n");
109 108
 
110 109
 
111 110
 	return 0;
... ...
@@ -115,13 +114,13 @@ int init_stats(int nr_of_processes)
115 114
 void setstats(int child_index)
116 115
 {
117 116
 	if(stats_segments == -1 || !global_stats) {
118
-		LOG(L_ERR, "Stats not initialized. Cannot set them\n");
117
+		LM_ERR("Stats not initialized. Cannot set them\n");
119 118
 		stats = NULL;
120 119
 		return;
121 120
 	}
122 121
 	if(child_index < 0 || child_index >= stats_segments) {
123 122
 		stats = NULL;
124
-		LOG(L_ERR, "Invalid index %d while setting statistics. Only have "
123
+		LM_ERR("Invalid index %d while setting statistics. Only have "
125 124
 			"space for %d processes\n", child_index, stats_segments);
126 125
 		return;
127 126
 	}
... ...
@@ -139,7 +138,7 @@ int dump_statistic(FILE *fp, struct stats_s *istats, int printheader)
139 138
 	struct tm res;
140 139
 	char t[256];
141 140
 	if(stats_segments == -1 || !global_stats) {
142
-		LOG(L_ERR, "Stats \"engine\" not initialized\n");
141
+		LM_ERR("Stats \"engine\" not initialized\n");
143 142
 		return -1;
144 143
 	}
145 144
 
... ...
@@ -205,18 +204,18 @@ int dump_all_statistic()
205 204
 	FILE *stat_fp = NULL;
206 205
 
207 206
 	if(stats_segments == -1 || !global_stats) {
208
-		LOG(L_ERR, "%s: Can't dump statistics, not initialized!\n", __func__);
207
+		LM_ERR("%s: Can't dump statistics, not initialized!\n", __func__);
209 208
 		return -1;
210 209
 	}
211 210
 
212 211
 	if(!stat_file) {
213
-		LOG(L_ERR, "%s: Can't dump statistics, invalid stats file\n", __func__);
212
+		LM_ERR("%s: Can't dump statistics, invalid stats file\n", __func__);
214 213
 		return -1;
215 214
 	}
216 215
 
217 216
 	stat_fp = fopen(stat_file, "a");
218 217
 	if(!stat_fp) {
219
-		LOG(L_ERR, "%s: Couldn't open stats file %s: %s\n", __func__, stat_file,
218
+		LM_ERR("%s: Couldn't open stats file %s: %s\n", __func__, stat_file,
220 219
 				strerror(errno));
221 220
 		return -1;
222 221
 	}
... ...
@@ -230,7 +229,7 @@ int dump_all_statistic()
230 229
 	c = global_stats;
231 230
 	for(i=0; i<stats_segments; i++) {
232 231
 		if(dump_statistic(stat_fp, c, 1) == -1) {
233
-			LOG(L_ERR, "Error dumping statistics for process %d\n", i);
232
+			LM_ERR("Error dumping statistics for process %d\n", i);
234 233
 			goto end;
235 234
 		}
236 235
 		c++;
... ...
@@ -240,16 +239,16 @@ int dump_all_statistic()
240 239
 	if(!g)
241 240
 		g = calloc(1, sizeof(struct stats_s));
242 241
 	if(!g) {
243
-		LOG(L_ERR, "Couldn't dump global stats: %s\n", strerror(errno));
242
+		LM_ERR("Couldn't dump global stats: %s\n", strerror(errno));
244 243
 		goto end;
245 244
 	}
246 245
 	
247 246
 	if(collect_stats(g) == -1) {
248
-		LOG(L_ERR, "%s: Couldn't dump global stats\n", __func__);
247
+		LM_ERR("%s: Couldn't dump global stats\n", __func__);
249 248
 		goto end;
250 249
 	}
251 250
 	if(dump_statistic(stat_fp, g, 0) == -1) {
252
-		LOG(L_ERR, "Couldn't dump global stats\n");
251
+		LM_ERR("Couldn't dump global stats\n");
253 252
 		goto end;
254 253
 	}
255 254
 end:
... ...
@@ -264,11 +263,11 @@ static int collect_stats(struct stats_s *s)
264 263
 	register int i;
265 264
 	register struct stats_s *c;
266 265
 	if(!s) {
267
-		LOG(L_ERR, "collect_stats(): Invalid stats pointer passed\n");
266
+		LM_ERR("Invalid stats pointer passed\n");
268 267
 		return -1;
269 268
 	}
270 269
 	if(!global_stats || stats_segments == -1) {
271
-		LOG(L_ERR, "Can't collect statistics, not initialized!!\n");
270
+		LM_ERR("Can't collect statistics, not initialized!!\n");
272 271
 		return -1;
273 272
 	}
274 273
 
... ...
@@ -327,7 +326,7 @@ static int collect_stats(struct stats_s *s)
327 326
 
328 327
 #define reg(t) \
329 328
 	if(t##_register(&f) == -1) {	\
330
-		LOG(L_ERR, "%s: Failed registering SNMP handlers\n", func);	\
329
+		LM_ERR("%s: Failed registering SNMP handlers\n", func);	\
331 330
 		return -1;	\
332 331
 	}
333 332
 
... ...
@@ -340,8 +339,8 @@ int stats_register()
340 339
 	f.new_func = (void*) find_export("snmp_new_handler", 1, 0);
341 340
 	f.free_func = (void*) find_export("snmp_free_handler", 1, 0);
342 341
 	if(!f.reg_func || !f.new_func || !f.free_func) {
343
-		LOG(L_INFO, "%s: Couldn't find SNMP module\n", func);
344
-		LOG(L_INFO, "%s: Not reporting stats through SNMP\n", func);
342
+		LM_INFO("%s: Couldn't find SNMP module\n", func);
343
+		LM_INFO("%s: Not reporting stats through SNMP\n", func);
345 344
 		return 0;
346 345
 	}
347 346
 
... ...
@@ -368,7 +367,7 @@ static int sipSummaryStatsTable_register(const struct stats_funcs *f)
368 367
 
369 368
 	h = f->new_func(sizeof(unsigned long));
370 369
 	if(!h) {
371
-		LOG(L_ERR, "%s: Error creating handler\n", func);
370
+		LM_ERR("%s: Error creating handler\n", func);
372 371
 		return -1;
373 372
 	}
374 373
 	o = h->sip_obj;
... ...
@@ -383,7 +382,7 @@ static int sipSummaryStatsTable_register(const struct stats_funcs *f)
383 382
 	h->on_get = collect_InReqs;
384 383
 	h->on_set = h->on_end = NULL;
385 384
 	if(f->reg_func("sipSummaryInRequests", h) == -1) {
386
-		LOG(L_ERR, "%s: Error registering sipSummaryInRequests\n", func);
385
+		LM_ERR("%s: Error registering sipSummaryInRequests\n", func);
387 386
 		f->free_func(h);
388 387
 		return -1;
389 388
 	}
... ...
@@ -391,7 +390,7 @@ static int sipSummaryStatsTable_register(const struct stats_funcs *f)
391 390
 	/* sipSummaryOutRequests */
392 391
 	h->on_get = collect_OutReqs;
393 392
 	if(f->reg_func("sipSummaryOutRequests", h) == -1) {
394
-		LOG(L_ERR, "%s: Error registering sipSummaryOutRequests\n", func);
393
+		LM_ERR("%s: Error registering sipSummaryOutRequests\n", func);
395 394
 		f->free_func(h);
396 395
 		return -1;
397 396
 	}
... ...
@@ -399,7 +398,7 @@ static int sipSummaryStatsTable_register(const struct stats_funcs *f)
399 398
 	/* sipSummaryInResponses */
400 399
 	h->on_get = collect_InResp;
401 400
 	if(f->reg_func("sipSummaryInResponses", h) == -1) {
402
-		LOG(L_ERR, "%s: Error registering sipSummaryInResponses\n", func);
401
+		LM_ERR("%s: Error registering sipSummaryInResponses\n", func);
403 402
 		f->free_func(h);
404 403
 		return -1;
405 404
 	}
... ...
@@ -407,7 +406,7 @@ static int sipSummaryStatsTable_register(const struct stats_funcs *f)
407 406
 	/* sipSummaryOutResponses */
408 407
 	h->on_get = collect_OutResp;
409 408
 	if(f->reg_func("sipSummaryOutResponses", h) == -1) {
410
-		LOG(L_ERR, "%s: Error registering sipSummaryOutResponses\n", func);
409
+		LM_ERR("%s: Error registering sipSummaryOutResponses\n", func);
411 410
 		f->free_func(h);
412 411
 		return -1;
413 412
 	}
... ...
@@ -444,7 +443,7 @@ static int sipMethodStatsTable_register(const struct stats_funcs *f)
444 443
 
445 444
 	h = f->new_func(sizeof(unsigned long));
446 445
 	if(!h) {
447
-		LOG(L_ERR, "%s: Error creating handler\n", func);
446
+		LM_ERR("%s: Error creating handler\n", func);
448 447
 		return -1;
449 448
 	}
450 449
 	o = h->sip_obj;
... ...
@@ -457,7 +456,7 @@ static int sipMethodStatsTable_register(const struct stats_funcs *f)
457 456
 
458 457
 	for(i=0; i<num; i++) {
459 458
 		if(f->reg_func(objs[i], h) == -1) {
460
-			LOG(L_ERR, "%s: Error registering %s\n", func, objs[i]);
459
+			LM_ERR("%s: Error registering %s\n", func, objs[i]);
461 460
 			f->free_func(h);
462 461
 			return -1;
463 462
 		}
... ...
@@ -493,7 +492,7 @@ static int sipStatusCodesTable_register(const struct stats_funcs *f)
493 492
 
494 493
 	h = f->new_func(sizeof(unsigned long));
495 494
 	if(!h) {
496
-		LOG(L_ERR, "%s: Error creating handler\n", func);
495
+		LM_ERR("%s: Error creating handler\n", func);
497 496
 		return -1;
498 497
 	}
499 498
 	o = h->sip_obj;
... ...
@@ -506,7 +505,7 @@ static int sipStatusCodesTable_register(const struct stats_funcs *f)
506 505
 
507 506
 	for(i=0; i<num; i++) {
508 507
 		if(f->reg_func(objs[i], h) == -1) {
509
-			LOG(L_ERR, "%s: Error registering %s\n", func, objs[i]);
508
+			LM_ERR("%s: Error registering %s\n", func, objs[i]);
510 509
 			f->free_func(h);
511 510
 			return -1;
512 511
 		}
... ...
@@ -527,20 +526,20 @@ static int collect_InReqs(struct sip_snmp_obj *o, enum handler_op op)
527 526
 	const char *func = __FUNCTION__;
528 527
 
529 528
 	if(!global_stats || stats_segments == -1) {
530
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized."
529
+		LM_ERR("%s: Can't collect stats, they have not been initialized."
531 530
 			"Did you call init_stats()?\n", func);
532 531
 		return -1;
533 532
 	}
534 533
 
535 534
 	if(op != SER_GET) {
536
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
535
+		LM_ERR("%s: Invalid handler operation passed\n", func);
537 536
 		return -1;
538 537
 	}
539 538
 
540 539
 	if(!o->value.integer) {
541 540
 		o->value.integer = calloc(1, sizeof(unsigned long));
542 541
 		if(!o->value.integer) {
543
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
542
+			LM_ERR("%s: %s\n", func, strerror(errno));
544 543
 			return -1;
545 544
 		}
546 545
 	}
... ...
@@ -570,20 +569,20 @@ static int collect_OutReqs(struct sip_snmp_obj *o, enum handler_op op)
570 569
 	const char *func = __FUNCTION__;
571 570
 
572 571
 	if(!global_stats || stats_segments == -1) {
573
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized."
572
+		LM_ERR("%s: Can't collect stats, they have not been initialized."
574 573
 			"Did you call init_stats()?\n", func);
575 574
 		return -1;
576 575
 	}
577 576
 
578 577
 	if(op != SER_GET) {
579
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
578
+		LM_ERR("%s: Invalid handler operation passed\n", func);
580 579
 		return -1;
581 580
 	}
582 581
 
583 582
 	if(!o->value.integer) {
584 583
 		o->value.integer = calloc(1, sizeof(unsigned long));
585 584
 		if(!o->value.integer) {
586
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
585
+			LM_ERR("%s: %s\n", func, strerror(errno));
587 586
 			return -1;
588 587
 		}
589 588
 	}
... ...
@@ -613,20 +612,20 @@ static int collect_InResp(struct sip_snmp_obj *o, enum handler_op op)
613 612
 	const char *func = __FUNCTION__;
614 613
 
615 614
 	if(!global_stats || stats_segments == -1) {
616
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized."
615
+		LM_ERR("%s: Can't collect stats, they have not been initialized."
617 616
 			"Did you call init_stats()?\n", func);
618 617
 		return -1;
619 618
 	}
620 619
 
621 620
 	if(op != SER_GET) {
622
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
621
+		LM_ERR("%s: Invalid handler operation passed\n", func);
623 622
 		return -1;
624 623
 	}
625 624
 
626 625
 	if(!o->value.integer) {
627 626
 		o->value.integer = calloc(1, sizeof(unsigned long));
628 627
 		if(!o->value.integer) {
629
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
628
+			LM_ERR("%s: %s\n", func, strerror(errno));
630 629
 			return -1;
631 630
 		}
632 631
 	}
... ...
@@ -658,20 +657,20 @@ static int collect_OutResp(struct sip_snmp_obj *o, enum handler_op op)
658 657
 	const char *func = __FUNCTION__;
659 658
 
660 659
 	if(!global_stats || stats_segments == -1) {
661
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized\n",
660
+		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
662 661
 			func);
663 662
 		return -1;
664 663
 	}
665 664
 
666 665
 	if(op != SER_GET) {
667
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
666
+		LM_ERR("%s: Invalid handler operation passed\n", func);
668 667
 		return -1;
669 668
 	}
670 669
 
671 670
 	if(!o->value.integer) {
672 671
 		o->value.integer = calloc(1, sizeof(unsigned long));
673 672
 		if(!o->value.integer) {
674
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
673
+			LM_ERR("%s: %s\n", func, strerror(errno));
675 674
 			return -1;
676 675
 		}
677 676
 	}
... ...
@@ -712,25 +711,25 @@ static int sipStatsMethod_handler(struct sip_snmp_obj *o, enum handler_op op)
712 711
 	const char *func = __FUNCTION__;
713 712
 
714 713
 	if(!o) {
715
-		LOG(L_ERR, "%s: Invalid sip SNMP object passed\n", func);
714
+		LM_ERR("%s: Invalid sip SNMP object passed\n", func);
716 715
 		return -1;
717 716
 	}
718 717
 
719 718
 	if(!global_stats || stats_segments == -1) {
720
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized\n",
719
+		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
721 720
 			func);
722 721
 		return -1;
723 722
 	}
724 723
 
725 724
 	if(op != SER_GET) {
726
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
725
+		LM_ERR("%s: Invalid handler operation passed\n", func);
727 726
 		return -1;
728 727
 	}
729 728
 
730 729
 	if(!o->value.integer) {
731 730
 		o->value.integer = calloc(1, sizeof(unsigned long));
732 731
 		if(!o->value.integer) {
733
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
732
+			LM_ERR("%s: %s\n", func, strerror(errno));
734 733
 			return -1;
735 734
 		}
736 735
 	}
... ...
@@ -791,25 +790,25 @@ static int sipStatusCodes_handler(struct sip_snmp_obj *o, enum handler_op op)
791 790
 	const char *func = __FUNCTION__;
792 791
 
793 792
 	if(!o) {
794
-		LOG(L_ERR, "%s: Invalid sip SNMP object passed\n", func);
793
+		LM_ERR("%s: Invalid sip SNMP object passed\n", func);
795 794
 		return -1;
796 795
 	}
797 796
 
798 797
 	if(!global_stats || stats_segments == -1) {
799
-		LOG(L_ERR, "%s: Can't collect stats, they have not been initialized\n",
798
+		LM_ERR("%s: Can't collect stats, they have not been initialized\n",
800 799
 			func);
801 800
 		return -1;
802 801
 	}
803 802
 
804 803
 	if(op != SER_GET) {
805
-		LOG(L_ERR, "%s: Invalid handler operation passed\n", func);
804
+		LM_ERR("%s: Invalid handler operation passed\n", func);
806 805
 		return -1;
807 806
 	}
808 807
 
809 808
 	if(!o->value.integer) {
810 809
 		o->value.integer = calloc(1, sizeof(unsigned long));
811 810
 		if(!o->value.integer) {
812
-			LOG(L_ERR, "%s: %s\n", func, strerror(errno));
811
+			LM_ERR("%s: %s\n", func, strerror(errno));
813 812
 			return -1;
814 813
 		}
815 814
 	}