-
Notifications
You must be signed in to change notification settings - Fork 67
/
Error.cpp
91 lines (73 loc) · 2.13 KB
/
Error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*++
Module Name:
Error.cpp
Abstract:
SNAP error-message writer
Authors:
Bill Bolosky, Feburary, 2014
Environment:
User mode service.
Revision History:
--*/
#include "stdafx.h"
#include "Compat.h"
#include "Error.h"
#include "AlignerOptions.h"
#include "CommandProcessor.h"
void
WriteMessageToFile(FILE *file, const char *message)
{
if (AlignerOptions::useHadoopErrorMessages) {
fprintf(stderr,"reporter:status:%s", message); // Always use stderr in Hadoop mode, regardless of whether this is an error
fprintf(stderr, "%s", message); // And also print without the prefix, so it shows up in both logs
fflush(stderr);
} else {
if (AlignerOptions::outputToStdout && stdout == file) {
fprintf(stderr, "%s", message);
fflush(stderr);
} else {
fprintf(file, "%s", message);
fflush(file);
}
}
}
void
WriteErrorMessage(const char *message, ...)
{
va_list args;
va_start(args, message);
const size_t bufferSize = 10240;
char buffer[bufferSize];
vsnprintf(buffer, bufferSize - 1, message, args);
buffer[bufferSize - 1] = '\0'; // vsnprintf spec is vague on whether it null terminates a full buffer, so better safe than sorry
WriteMessageToFile(stderr, buffer);
if (NULL != CommandPipe) {
WriteToNamedPipe(CommandPipe, buffer);
}
}
void
WriteStatusMessage(const char *message, ...)
{
va_list args;
va_start(args, message);
const size_t bufferSize = 10240;
char buffer[bufferSize];
vsnprintf(buffer, bufferSize - 1, message, args);
buffer[bufferSize - 1] = '\0'; // vsnprintf spec is vague on whether it null terminates a full buffer, so better safe than sorry
WriteMessageToFile(stdout, buffer);
if (NULL != CommandPipe) {
WriteToNamedPipe(CommandPipe, buffer);
}
}
void
WriteProgressCounter(const char *counterName, _int64 increment)
{
if (!AlignerOptions::useHadoopErrorMessages) {
//
// No counters unless in Hadoop mode.
//
return;
}
fprintf(stderr,"reporter:counter:SNAP,%s,%lld\n", counterName, increment);
fflush(stderr);
}