3
3
#include < filesystem>
4
4
#include < stdlib.h>
5
5
#include < optional>
6
+ #include < unistd.h>
6
7
7
8
#define LEVEL_REGEX_PATTERN " trace|debug|info|warning|error|critical|no_logs"
8
9
@@ -57,8 +58,8 @@ std::vector<std::string> Log::collectLevelRulesAndReturnProblems(const char* env
57
58
if (auto levels = getEnvOr (envVar, nullptr )) {
58
59
// expect comma-separated <glob pattern>:<log severity>
59
60
std::regex comma{" ," };
60
- std::regex levelAssignment{R"( (?:([*./\w]+)|(?:out:(bin|text|console))):( )" LEVEL_REGEX_PATTERN
61
- " )" };
61
+ std::regex levelAssignment{
62
+ R"( (?:([*./\w]+)|(?:out:(binary|text|console|diagnostics))):( )" LEVEL_REGEX_PATTERN " )" };
62
63
std::cregex_token_iterator begin{levels, levels + strlen (levels), comma, -1 };
63
64
std::cregex_token_iterator end{};
64
65
for (auto it = begin; it != end; ++it) {
@@ -76,12 +77,14 @@ std::vector<std::string> Log::collectLevelRulesAndReturnProblems(const char* env
76
77
sourceRules.emplace_back (pattern, level);
77
78
} else {
78
79
auto out = matchToView (match[2 ]);
79
- if (out == " bin " ) {
80
+ if (out == " binary " ) {
80
81
binary.level = level;
81
82
} else if (out == " text" ) {
82
83
text.level = level;
83
84
} else if (out == " console" ) {
84
85
console.level = level;
86
+ } else if (out == " diagnostics" ) {
87
+ diagnostics.level = level;
85
88
}
86
89
}
87
90
} else {
@@ -95,12 +98,14 @@ std::vector<std::string> Log::collectLevelRulesAndReturnProblems(const char* env
95
98
void Log::configure () {
96
99
// as we are configuring logging right now, we collect problems and log them at the end
97
100
auto problems = collectLevelRulesAndReturnProblems (" CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS" );
98
- auto now = std::to_string (std::chrono::system_clock::now ().time_since_epoch ().count ());
101
+ auto logBaseName = std::to_string (std::chrono::system_clock::now ().time_since_epoch ().count ());
102
+ logBaseName += ' -' ;
103
+ logBaseName += std::to_string (getpid ());
99
104
if (text || binary) {
100
105
std::filesystem::path logFile = getEnvOr (" CODEQL_EXTRACTOR_SWIFT_LOG_DIR" , " extractor-out/log" );
101
106
logFile /= " swift" ;
102
107
logFile /= programName;
103
- logFile /= now ;
108
+ logFile /= logBaseName ;
104
109
std::error_code ec;
105
110
std::filesystem::create_directories (logFile.parent_path (), ec);
106
111
if (!ec) {
@@ -130,7 +135,7 @@ void Log::configure() {
130
135
std::filesystem::path diagFile =
131
136
getEnvOr (" CODEQL_EXTRACTOR_SWIFT_DIAGNOSTIC_DIR" , " extractor-out/diagnostics" );
132
137
diagFile /= programName;
133
- diagFile /= now ;
138
+ diagFile /= logBaseName ;
134
139
diagFile.replace_extension (" .jsonl" );
135
140
std::error_code ec;
136
141
std::filesystem::create_directories (diagFile.parent_path (), ec);
@@ -149,8 +154,8 @@ void Log::configure() {
149
154
for (const auto & problem : problems) {
150
155
LOG_ERROR (" {}" , problem);
151
156
}
152
- LOG_INFO (" Logging configured (binary: {}, text: {}, console: {})" , binary. level , text .level ,
153
- console.level );
157
+ LOG_INFO (" Logging configured (binary: {}, text: {}, console: {}, diagnostics: {} )" , binary.level ,
158
+ text. level , console. level , diagnostics .level );
154
159
initialized = true ;
155
160
flushImpl ();
156
161
}
@@ -163,6 +168,9 @@ void Log::flushImpl() {
163
168
if (binary) {
164
169
binary.output .flush ();
165
170
}
171
+ if (diagnostics) {
172
+ diagnostics.output .flush ();
173
+ }
166
174
}
167
175
168
176
Log::LoggerConfiguration Log::getLoggerConfigurationImpl (std::string_view name) {
0 commit comments