Skip to content

Commit 164aa3c

Browse files
committed
Fix #393 consistent logging
1 parent 17a81d7 commit 164aa3c

File tree

10 files changed

+41
-54
lines changed

10 files changed

+41
-54
lines changed

src/collector/launch.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void cmd_execute(char **args) {
210210
int pid;
211211

212212
// Get a child process.
213-
LogInfo("Launcher: fork child.");
213+
LogVerbose("Launcher: fork child.");
214214
if ((pid = fork()) < 0) {
215215
LogError("Can't fork: %s", strerror(errno));
216216
return;
@@ -223,7 +223,7 @@ static void cmd_execute(char **args) {
223223
}
224224

225225
// we are the parent
226-
LogInfo("Launcher: child exec done.");
226+
LogVerbose("Launcher: child exec done.");
227227
/* empty */
228228

229229
} // End of cmd_execute
@@ -382,18 +382,18 @@ void launcher(void *commbuff, FlowSource_t *FlowSource, char *process, int expir
382382
}
383383
}
384384
if (child_exit) {
385-
LogInfo("launcher child exit %d children.", child_exit);
385+
LogVerbose("launcher child exit %d children.", child_exit);
386386
while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) {
387387
if (WIFEXITED(stat)) {
388-
LogInfo("launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
388+
LogVerbose("launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
389389
}
390390
if (WIFSIGNALED(stat)) {
391391
LogError("launcher child %i died due to signal %i", pid, WTERMSIG(stat));
392392
}
393393

394394
child_exit--;
395395
}
396-
LogInfo("launcher waiting children done. %d children", child_exit);
396+
LogVerbose("launcher waiting children done. %d children", child_exit);
397397
child_exit = 0;
398398
}
399399
if (done) {

src/collector/metric.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int OpenMetric(char *path, int interval) {
115115
socket_path = path;
116116
int fd = OpenSocket();
117117
if (fd == 0) {
118-
LogInfo("metric socket unreachable");
118+
LogError("metric socket unreachable");
119119
} else {
120120
close(fd);
121121
}
@@ -296,7 +296,7 @@ __attribute__((noreturn)) void *MetricThread(void *arg) {
296296
offset += sizeof(metric_record_t);
297297

298298
metric_chain = metric_chain->next;
299-
LogInfo("Message sent for '%s', exporter: %d\n", metric_record->ident, exporterID);
299+
LogVerbose("Message sent for '%s', exporter: %d\n", metric_record->ident, exporterID);
300300
}
301301
ssize_t ret = write(fd, message, offset);
302302
if (ret < 0) {

src/lib/util.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ int InitLog(int want_syslog, char *name, char *facility, int verbose_log) {
196196
int i;
197197
char *logname;
198198

199+
#ifdef DEVEL
200+
verbose_log = 2;
201+
#endif
202+
199203
verbose = verbose_log;
200204
if (!want_syslog) {
201205
if (verbose) {
@@ -265,7 +269,7 @@ void LogInfo(char *format, ...) {
265269
va_end(var_args);
266270
syslog(LOG_INFO, "%s", string);
267271
dbg_printf("%s\n", string);
268-
} else if (verbose) {
272+
} else {
269273
va_start(var_args, format);
270274
vsnprintf(string, 511, format, var_args);
271275
fprintf(stderr, "%s\n", string);

src/netflow/netflow_v1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int Init_v1(int verbose) {
123123
printRecord = verbose > 2;
124124
baseRecordSize = sizeof(recordHeaderV3_t) + EXgenericFlowSize + EXipv4FlowSize + EXflowMiscSize + EXipNextHopV4Size;
125125

126-
LogInfo("Init v1");
126+
LogVerbose("Init v1");
127127
return 1;
128128
} // End of Init_v1
129129

src/netflow/netflow_v5_v7.c

-2
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ int Init_v5_v7(int verbose, int32_t sampling) {
177177

178178
if (sampling < 0) {
179179
LogInfo("Init v5/v7: Overwrite sampling: %d", -defaultSampling);
180-
dbg_printf("Init v5/v7: Overwrite sampling: %d\n", -defaultSampling);
181180
} else {
182181
LogInfo("Init v5/v7: Default sampling: %d", defaultSampling);
183-
dbg_printf("Init v5/v7: Default sampling: %d\n", defaultSampling);
184182
}
185183

186184
baseRecordSize = sizeof(recordHeaderV3_t) + EXgenericFlowSize + EXipv4FlowSize + EXflowMiscSize + EXasRoutingSize + EXipNextHopV4Size;

src/netflow/netflow_v9.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,8 @@ int Init_v9(int verbose, int32_t sampling) {
308308

309309
if (sampling < 0) {
310310
LogInfo("Init v9: Max number of v9 tags: %u, overwrite sampling: %d", i, -defaultSampling);
311-
dbg_printf("Initv9: Overwrite sampling: %d\n", -defaultSampling);
312311
} else {
313312
LogInfo("Init v9: Max number of v9 tags: %u, default sampling: %d", i, defaultSampling);
314-
dbg_printf("Initv9: Default sampling: %d\n", defaultSampling);
315313
}
316314

317315
return 1;
@@ -412,7 +410,6 @@ static inline exporterDomain_t *getExporter(FlowSource_t *fs, uint32_t exporter_
412410
dbg_printf("Add static sampler for default sampling: %u\n", defaultSampling);
413411
}
414412

415-
dbg_printf("Process_v9: New v9 exporter: SysID: %u, Domain: %u, IP: %s\n", (*e)->info.sysid, exporter_id, ipstr);
416413
LogInfo("Process_v9: New v9 exporter: SysID: %u, Domain: %u, IP: %s\n", (*e)->info.sysid, exporter_id, ipstr);
417414

418415
return (*e);
@@ -441,8 +438,6 @@ static void InsertSampler(FlowSource_t *fs, exporterDomain_t *exporter, sampler_
441438
AppendToBuffer(fs->nffile, &(sampler->record), sampler->record.size);
442439
LogInfo("Add new sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u", sampler_record->id, sampler_record->algorithm,
443440
sampler_record->packetInterval, sampler_record->spaceInterval);
444-
dbg_printf("Add new sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u\n", sampler_record->id, sampler_record->algorithm,
445-
sampler_record->packetInterval, sampler_record->spaceInterval);
446441

447442
} else {
448443
sampler = exporter->sampler;
@@ -458,8 +453,6 @@ static void InsertSampler(FlowSource_t *fs, exporterDomain_t *exporter, sampler_
458453
AppendToBuffer(fs->nffile, &(sampler->record), sampler->record.size);
459454
LogInfo("Update existing sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u", sampler_record->id,
460455
sampler_record->algorithm, sampler_record->packetInterval, sampler_record->spaceInterval);
461-
dbg_printf("Update existing sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u\n", sampler_record->id,
462-
sampler_record->algorithm, sampler_record->packetInterval, sampler_record->spaceInterval);
463456
} else {
464457
dbg_printf("Sampler unchanged!\n");
465458
}
@@ -485,8 +478,6 @@ static void InsertSampler(FlowSource_t *fs, exporterDomain_t *exporter, sampler_
485478
AppendToBuffer(fs->nffile, &(sampler->record), sampler->record.size);
486479
LogInfo("Append new sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u", sampler_record->id,
487480
sampler_record->algorithm, sampler_record->packetInterval, sampler_record->spaceInterval);
488-
dbg_printf("Append new sampler id: %lli, algorithm: %u, packet interval: %u, packet space: %u\n", sampler_record->id,
489-
sampler_record->algorithm, sampler_record->packetInterval, sampler_record->spaceInterval);
490481
break;
491482
}
492483

@@ -1063,7 +1054,7 @@ static inline void Process_v9_data(exporterDomain_t *exporter, void *data_flowse
10631054
}
10641055

10651056
// request new and empty buffer
1066-
LogInfo("Process v9: Sequencer run - resize output buffer");
1057+
LogVerbose("Process v9: Sequencer run - resize output buffer");
10671058
buffAvail = CheckBufferSpace(fs->nffile, buffAvail + 1);
10681059
if (buffAvail == 0) {
10691060
// this should really never occur, because the buffer gets flushed ealier
@@ -1466,7 +1457,7 @@ static void Process_v9_nbar_option_data(exporterDomain_t *exporter, FlowSource_t
14661457
fs->nffile->buff_ptr += nbarHeader->size;
14671458

14681459
if (size_left > 7) {
1469-
LogInfo("Proces nbar data record - %u extra bytes", size_left);
1460+
LogVerbose("Proces nbar data record - %u extra bytes", size_left);
14701461
}
14711462
processed_records++;
14721463

@@ -1591,7 +1582,7 @@ static void Process_v9_ifvrf_option_data(exporterDomain_t *exporter, FlowSource_
15911582
fs->nffile->buff_ptr += nameHeader->size;
15921583

15931584
if (size_left > 7) {
1594-
LogInfo("Proces ifvrf data record - %u extra bytes", size_left);
1585+
LogVerbose("Proces ifvrf data record - %u extra bytes", size_left);
15951586
}
15961587
processed_records++;
15971588

src/nfcapd/nfcapd.c

+9-17
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,7 @@ static void IntHandler(int signal) {
213213
} /* End of IntHandler */
214214

215215
static void format_file_block_header(dataBlock_t *header) {
216-
printf(
217-
"\n"
218-
"File Block Header: \n"
219-
" Type = %10u\n"
220-
" Size = %10u\n"
221-
" NumRecords = %10u\n",
222-
header->type, header->size, header->NumRecords);
223-
216+
printf("File Block Header: type: %u, size: %u, NumRecords: %u\n", header->type, header->size, header->NumRecords);
224217
} // End of format_file_block_header
225218

226219
#include "collector_inline.c"
@@ -350,8 +343,7 @@ static void run(packet_function_t receive_packet, int socket, repeater_t *repeat
350343
char error[255];
351344
nffile_t *nffile = fs->nffile;
352345

353-
if (verbose) {
354-
// Dump to stdout
346+
if (verbose > 1) {
355347
format_file_block_header(nffile->block_header);
356348
}
357349

@@ -446,13 +438,13 @@ static void run(packet_function_t receive_packet, int socket, repeater_t *repeat
446438
commbuff->fname[MAXPATHLEN - 1] = '\0';
447439

448440
if (launcher_alive) {
449-
LogInfo("Signal launcher");
441+
LogVerbose("Signal launcher");
450442
kill(launcher_pid, SIGHUP);
451443
} else
452444
LogError("ERROR: Launcher died unexpectedly!");
453445
}
454446

455-
LogInfo("Total ignored packets: %u", ignored_packets);
447+
if (ignored_packets) LogInfo("Total ignored packets: %u", ignored_packets);
456448
ignored_packets = 0;
457449

458450
if (done) break;
@@ -752,7 +744,7 @@ int main(int argc, char **argv) {
752744
}
753745
break;
754746
case 'l':
755-
LogInfo("-l is a legacy option and may get removed in future. Please use -w next time");
747+
LogError("-l is a legacy option and may get removed in future. Please use -w to set output directory");
756748
case 'w':
757749
if (!CheckPath(optarg, S_IFDIR)) {
758750
LogError("No valid directory: %s", optarg);
@@ -892,7 +884,7 @@ int main(int argc, char **argv) {
892884
repeater[i].sockfd =
893885
Unicast_send_socket(repeater[i].hostname, repeater[i].port, repeater[i].family, bufflen, &repeater[i].addr, &repeater[i].addrlen);
894886
if (repeater[i].sockfd <= 0) exit(EXIT_FAILURE);
895-
LogInfo("Replay flows to host: %s port: %s", repeater[i].hostname, repeater[i].port);
887+
LogVerbose("Replay flows to host: %s port: %s", repeater[i].hostname, repeater[i].port);
896888
i++;
897889
}
898890

@@ -950,7 +942,7 @@ int main(int argc, char **argv) {
950942
default:
951943
// parent
952944
launcher_alive = 1;
953-
LogInfo("Launcher[%i] forked", launcher_pid);
945+
LogVerbose("Launcher[%i] forked", launcher_pid);
954946
}
955947
}
956948

@@ -985,7 +977,7 @@ int main(int argc, char **argv) {
985977
sigaction(SIGALRM, &act, NULL);
986978
sigaction(SIGCHLD, &act, NULL);
987979

988-
LogInfo("Startup.");
980+
LogInfo("Startup nfcapd.");
989981
run(receive_packet, sock, repeater, twin, t_start, report_sequence, subdir_index, time_extension, compress);
990982

991983
// shutdown
@@ -1000,7 +992,7 @@ int main(int argc, char **argv) {
1000992
if (expire == 0 && ReadStatInfo(fs->datadir, &dirstat, LOCK_IF_EXISTS) == STATFILE_OK) {
1001993
UpdateDirStat(dirstat, fs->bookkeeper);
1002994
WriteStatInfo(dirstat);
1003-
LogInfo("Updating statinfo in directory '%s'", datadir);
995+
LogVerbose("Updating statinfo in directory '%s'", datadir);
1004996
}
1005997

1006998
ReleaseBookkeeper(fs->bookkeeper, DESTROY_BOOKKEEPER);

src/nfpcapd/flowtree.c

-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ int Link_RevNode(struct FlowNode *node) {
341341

342342
uint32_t Flush_FlowTree(NodeList_t *NodeList, time_t when) {
343343
struct FlowNode *node, *nxt;
344-
uint32_t n = NumFlows;
345344

346345
// Dump all incomplete flows to the file
347346
nxt = NULL;
@@ -355,8 +354,6 @@ uint32_t Flush_FlowTree(NodeList_t *NodeList, time_t when) {
355354
}
356355
}
357356

358-
if (NumFlows != 0) LogInfo("Flush_FlowTree() flushed flows: %u\n", NumFlows);
359-
360357
node = New_Node();
361358
node->timestamp = when;
362359
node->nodeType = SIGNAL_NODE;

src/nfpcapd/nfpcapd.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,12 @@ int main(int argc, char *argv[]) {
411411
device = optarg;
412412
break;
413413
case 'l':
414-
LogInfo("-l is a legacy option and may get removed in future. Please use -w next time");
414+
LogError("-l is a legacy option and may get removed in future. Please use -w to set output directory");
415415
case 'w':
416416
datadir = optarg;
417417
err = stat(datadir, &fstat);
418418
if (!(fstat.st_mode & S_IFDIR)) {
419-
LogError(
420-
"No such directory: "
421-
"'%s'",
422-
datadir);
419+
LogError("No valid directory: '%s'", datadir);
423420
break;
424421
}
425422
break;
@@ -669,7 +666,7 @@ int main(int argc, char *argv[]) {
669666
exit(EXIT_FAILURE);
670667
}
671668

672-
LogInfo("Startup.");
669+
LogInfo("Startup nfpcapd.");
673670
// prepare signal mask for all threads
674671
// block signals, as they are handled by the main thread
675672
// mask is inherited by all threads
@@ -767,7 +764,7 @@ int main(int argc, char *argv[]) {
767764
if (expire == 0 && ReadStatInfo(fs->datadir, &dirstat, LOCK_IF_EXISTS) == STATFILE_OK) {
768765
UpdateDirStat(dirstat, fs->bookkeeper);
769766
WriteStatInfo(dirstat);
770-
LogInfo("Updating statinfo in directory '%s'", datadir);
767+
LogVerbose("Updating statinfo in directory '%s'", datadir);
771768
}
772769
ReleaseBookkeeper(fs->bookkeeper, DESTROY_BOOKKEEPER);
773770
}

src/sflow/sfcapd.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ static void IntHandler(int signal) {
207207

208208
} /* End of IntHandler */
209209

210+
static void format_file_block_header(dataBlock_t *header) {
211+
printf("File Block Header: type: %u, size: %u, NumRecords: %u\n", header->type, header->size, header->NumRecords);
212+
} // End of format_file_block_header
213+
210214
#include "collector_inline.c"
211215
#include "nffile_inline.c"
212216

@@ -331,6 +335,10 @@ static void run(packet_function_t receive_packet, int socket, repeater_t *repeat
331335
char error[255];
332336
nffile_t *nffile = fs->nffile;
333337

338+
if (verbose > 1) {
339+
format_file_block_header(nffile->block_header);
340+
}
341+
334342
// prepare filename
335343
if (subdir) {
336344
if (SetupSubDir(fs->datadir, subdir, error, 255)) {
@@ -428,7 +436,7 @@ static void run(packet_function_t receive_packet, int socket, repeater_t *repeat
428436
LogError("ERROR: Launcher died unexpectedly!");
429437
}
430438

431-
LogInfo("Total ignored packets: %u", ignored_packets);
439+
if (ignored_packets) LogInfo("Total ignored packets: %u", ignored_packets);
432440
ignored_packets = 0;
433441

434442
if (done) break;
@@ -694,7 +702,7 @@ int main(int argc, char **argv) {
694702
report_sequence = 1;
695703
break;
696704
case 'l':
697-
LogInfo("-l is a legacy option and may get removed in future. Please use -w next time");
705+
LogError("-l is a legacy option and may get removed in future. Please use -w to set output directory");
698706
case 'w':
699707
if (!CheckPath(optarg, S_IFDIR)) {
700708
LogError("No valid directory: %s", optarg);
@@ -924,7 +932,7 @@ int main(int argc, char **argv) {
924932
sigaction(SIGALRM, &act, NULL);
925933
sigaction(SIGCHLD, &act, NULL);
926934

927-
LogInfo("Startup.");
935+
LogInfo("Startup sfcapd.");
928936
run(receive_packet, sock, repeater, twin, t_start, report_sequence, subdir_index, time_extension, compress);
929937
close(sock);
930938
kill_launcher(launcher_pid);
@@ -937,7 +945,7 @@ int main(int argc, char **argv) {
937945
if (expire == 0 && ReadStatInfo(fs->datadir, &dirstat, LOCK_IF_EXISTS) == STATFILE_OK) {
938946
UpdateDirStat(dirstat, fs->bookkeeper);
939947
WriteStatInfo(dirstat);
940-
LogInfo("Updating statinfo in directory '%s'", datadir);
948+
LogVerbose("Updating statinfo in directory '%s'", datadir);
941949
}
942950

943951
ReleaseBookkeeper(fs->bookkeeper, DESTROY_BOOKKEEPER);

0 commit comments

Comments
 (0)