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