Skip to content

Commit

Permalink
[#60feature/#60-restlib] sonar issues fixed
Browse files Browse the repository at this point in the history
Signed-off-by: huluvu424242 <huluvu424242@gmail.com>
  • Loading branch information
Huluvu424242 committed Jan 23, 2023
1 parent f850f23 commit 76abdae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.github.funthomas424242.jenkinsmonitor.logstash.LogStashConfigManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -173,17 +174,7 @@ public long getPollPeriodInSecond() {
final String propValue = this.configurationProperties.getProperty(JENKINSMONITOR_POLLPERIOD, DEFAULT_POLLPERIOD);
return Long.parseLong(propValue);
}

//TODO auslagern
private void reloadDefaultLoggerConfiguration() throws JoranException {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(loggerContext);
loggerContext.reset();
ci.autoConfig();
}

public Loaded resetLoggerConfiguration() {
// reload();
final String[] LOG_LEVEL = {"debug", "info", "error", "log"};
final String[] LOG_APPENDER = {"CONSOLE", "FILE"};

Expand Down Expand Up @@ -212,20 +203,19 @@ public Loaded resetLoggerConfiguration() {
}
try {
// Logger Konfiguratin neu laden mit gesetzten Systemproperties
reloadDefaultLoggerConfiguration();
LogStashConfigManager.reloadDefaultLoggerConfiguration();
} catch (JoranException e) {
throw new RuntimeException(e);
}
return this;
}

public JobBeschreibungen getJobBeschreibungen() {
// loadPropertiesFromFile(configurationFile);
final Map<String, JobBeschreibung> jobBeschreibungMap = configurationProperties
.stringPropertyNames()
.stream()
.sorted()
.filter((key) -> key.startsWith(JOBKEY_PREFIX))
.filter(key -> key.startsWith(JOBKEY_PREFIX))
.map(key -> {
final Pattern pattern = Pattern.compile("joburl-(.+)");
final Matcher matcher = pattern.matcher(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.funthomas424242.jenkinsmonitor.logstash;

/*-
* #%L
* Jenkins Monitor
* %%
* Copyright (C) 2019 - 2023 PIUG
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import org.slf4j.LoggerFactory;

public class LogStashConfigManager {

public static void reloadDefaultLoggerConfiguration() throws JoranException {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(loggerContext);
loggerContext.reset();
ci.autoConfig();
}
}

0 comments on commit 76abdae

Please sign in to comment.