@@ -23,11 +23,11 @@ Log::Level getLevelFor(std::string_view name, const LevelRules& rules, Log::Leve
2323 return dflt;
2424}
2525
26- const char * getEnvOr (const char * var, const char * deflt ) {
26+ const char * getEnvOr (const char * var, const char * dflt ) {
2727 if (const char * ret = getenv (var)) {
2828 return ret;
2929 }
30- return deflt ;
30+ return dflt ;
3131}
3232
3333std::string_view matchToView (std::csub_match m) {
@@ -48,16 +48,11 @@ Log::Level matchToLevel(std::csub_match m) {
4848 return stringToLevel (matchToView (m));
4949}
5050
51- struct LevelConfiguration {
52- LevelRules& sourceRules;
53- Log::Level& binSeverity;
54- Log::Level& textSeverity;
55- Log::Level& consoleSeverity;
56- std::vector<std::string>& problems;
57- };
51+ } // namespace
5852
59- void collectSeverityRules (const char * var, LevelConfiguration&& configuration) {
60- if (auto levels = getEnvOr (var, nullptr )) {
53+ std::vector<std::string> Log::collectSeverityRulesAndReturnProblems (const char * envVar) {
54+ std::vector<std::string> problems;
55+ if (auto levels = getEnvOr (envVar, nullptr )) {
6156 // expect comma-separated <glob pattern>:<log severity>
6257 std::regex comma{" ," };
6358 std::regex levelAssignment{R"( (?:([*./\w]+)|(?:out:(bin|text|console))):()" LEVEL_REGEX_PATTERN
@@ -76,31 +71,28 @@ void collectSeverityRules(const char* var, LevelConfiguration&& configuration) {
7671 pattern.insert (pos, (pattern[pos] == ' *' ) ? " ." : " \\ " );
7772 pos += 2 ;
7873 }
79- configuration. sourceRules .emplace_back (pattern, level);
74+ sourceRules.emplace_back (pattern, level);
8075 } else {
8176 auto out = matchToView (match[2 ]);
8277 if (out == " bin" ) {
83- configuration. binSeverity = level;
78+ binary. level = level;
8479 } else if (out == " text" ) {
85- configuration. textSeverity = level;
80+ text. level = level;
8681 } else if (out == " console" ) {
87- configuration. consoleSeverity = level;
82+ console. level = level;
8883 }
8984 }
9085 } else {
91- configuration. problems .emplace_back (" Malformed log level rule: " + it->str ());
86+ problems.emplace_back (" Malformed log level rule: " + it->str ());
9287 }
9388 }
9489 }
90+ return problems;
9591}
9692
97- } // namespace
98-
9993void Log::configure () {
10094 // as we are configuring logging right now, we collect problems and log them at the end
101- std::vector<std::string> problems;
102- collectSeverityRules (" CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS" ,
103- {sourceRules, binary.level , text.level , console.level , problems});
95+ auto problems = collectSeverityRulesAndReturnProblems (" CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS" );
10496 if (text || binary) {
10597 std::filesystem::path logFile = getEnvOr (" CODEQL_EXTRACTOR_SWIFT_LOG_DIR" , " ." );
10698 logFile /= logRootName;
@@ -144,7 +136,7 @@ void Log::flushImpl() {
144136}
145137
146138Log::LoggerConfiguration Log::getLoggerConfigurationImpl (std::string_view name) {
147- LoggerConfiguration ret{session, logRootName};
139+ LoggerConfiguration ret{session, std::string{ logRootName} };
148140 ret.fullyQualifiedName += ' /' ;
149141 ret.fullyQualifiedName += name;
150142 ret.level = std::min ({binary.level , text.level , console.level });
0 commit comments