Skip to content

Commit 3fc4881

Browse files
committed
Swift: add logging to main
1 parent ed48065 commit 3fc4881

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

swift/extractor/main.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/extractor/invocation/SwiftInvocationExtractor.h"
1717
#include "swift/extractor/trap/TrapDomain.h"
1818
#include "swift/extractor/infra/file/Path.h"
19+
#include "swift/extractor/infra/log/SwiftLogging.h"
1920

2021
using namespace std::string_literals;
2122

@@ -179,7 +180,27 @@ codeql::SwiftExtractorConfiguration configure(int argc, char** argv) {
179180
return configuration;
180181
}
181182

182-
int main(int argc, char** argv) {
183+
static auto argDump(int argc, char** argv) {
184+
std::string ret;
185+
for (auto arg = argv + 1; arg < argv + argc; ++arg) {
186+
ret += *arg;
187+
ret += ' ';
188+
}
189+
ret.pop_back();
190+
return ret;
191+
}
192+
193+
static auto envDump(char** envp) {
194+
std::string ret;
195+
for (auto env = envp; *env; ++env) {
196+
ret += *env;
197+
ret += '\n';
198+
}
199+
ret.pop_back();
200+
return ret;
201+
}
202+
203+
int main(int argc, char** argv, char** envp) {
183204
checkWhetherToRunUnderTool(argc, argv);
184205

185206
if (argc == 1) {
@@ -193,6 +214,10 @@ int main(int argc, char** argv) {
193214
initializeSwiftModules();
194215

195216
const auto configuration = configure(argc, argv);
217+
codeql::Log::configure("extractor");
218+
auto& logger = codeql::logger();
219+
LOG_INFO("calling extractor with arguments \"{}\"", argDump(argc, argv));
220+
LOG_DEBUG("environment:\n{}\n", envDump(envp));
196221

197222
auto openInterception = codeql::setupFileInterception(configuration);
198223

@@ -204,5 +229,7 @@ int main(int argc, char** argv) {
204229
observer.markSuccessfullyExtractedFiles();
205230
}
206231

232+
codeql::Log::flush();
233+
207234
return frontend_rc;
208235
}

0 commit comments

Comments
 (0)