Browse Source

inkl Ohmlogger txt datei

JensV2
ahren 1 year ago
parent
commit
03251b36f5
4 changed files with 36 additions and 5 deletions
  1. 15
    0
      ohmLog2
  2. 2
    1
      src/bandit/Model/Wuerfel.java
  3. 15
    4
      src/bandit/util/OhmLogger.java
  4. 4
    0
      src/config.properties

+ 15
- 0
ohmLog2 View File

| 2023-11-28T11:37:42.390252 | INFO | bandit.Schnittstelle.StartStopController | Start gedruekt |
| 2023-11-28T11:37:42.393278400 | INFO | bandit.Model.Zahlengenerator | Generator gestartet |
| 2023-11-28T11:37:43.136932500 | INFO | bandit.Schnittstelle.StartStopController | Stop gedrueckt |
| 2023-11-28T11:37:43.137930 | INFO | bandit.Model.Zahlengenerator | Generator gestopt |
| 2023-11-28T11:37:43.143407 | WARNING | bandit.Model.Zahlengenerator | unlucky -> 522 |
| 2023-11-28T11:38:59.188169300 | INFO | bandit.Schnittstelle.StartStopController | Start gedruekt |
| 2023-11-28T11:38:59.189224300 | INFO | bandit.Model.Zahlengenerator | Generator gestartet |
| 2023-11-28T11:39:00.790984600 | INFO | bandit.Schnittstelle.StartStopController | Stop gedrueckt |
| 2023-11-28T11:39:00.791922600 | INFO | bandit.Model.Zahlengenerator | Generator gestopt |
| 2023-11-28T11:39:00.800778 | WARNING | bandit.Model.Zahlengenerator | unlucky -> 463 |
| 2023-11-28T11:39:02.989252600 | INFO | bandit.Schnittstelle.StartStopController | Start gedruekt |
| 2023-11-28T11:39:02.990717700 | INFO | bandit.Model.Zahlengenerator | Generator gestartet |
| 2023-11-28T11:39:04.198394300 | INFO | bandit.Schnittstelle.StartStopController | Stop gedrueckt |
| 2023-11-28T11:39:04.214775 | INFO | bandit.Model.Zahlengenerator | Generator gestopt |
| 2023-11-28T11:39:04.215990800 | WARNING | bandit.Model.Zahlengenerator | unlucky -> 544 |

+ 2
- 1
src/bandit/Model/Wuerfel.java View File

@Override @Override
public void run() public void run()
{ {
lg.fine("Run "+ data.getId());
lg.fine("Run "+ data.getId());
while (true) while (true)
{ {
while (!laufend) while (!laufend)
{ {
synchronized (LOCK) synchronized (LOCK)

+ 15
- 4
src/bandit/util/OhmLogger.java View File

{ {
try (InputStream configFile = OhmLogger.class.getClassLoader().getResourceAsStream("config.properties")) { try (InputStream configFile = OhmLogger.class.getClassLoader().getResourceAsStream("config.properties")) {
if (configFile != null) { if (configFile != null) {
Properties properties = new Properties();
properties.load(configFile);
java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty("log.level"));
ConsoleHandler ch = new ConsoleHandler(); ConsoleHandler ch = new ConsoleHandler();
ch.setFormatter(new OhmFormatter()); ch.setFormatter(new OhmFormatter());
lg.setUseParentHandlers(false); lg.setUseParentHandlers(false);
lg.getHandlers(); lg.getHandlers();
lg.addHandler(ch); lg.addHandler(ch);


lg.setLevel(classLogLevel);
Properties properties = new Properties();
properties.load(configFile);
java.util.logging.Level classLogLevel = java.util.logging.Level.parse(properties.getProperty("log.level"));
lg.setLevel(classLogLevel);
String logDirectory = properties.getProperty("log.directory");
String logFileName = properties.getProperty("log.filename");

FileHandler fileHandler = new FileHandler(logDirectory + "/" + logFileName, true);
fileHandler.setFormatter(new OhmFormatter());
lg.addHandler(fileHandler);
} else { } else {
System.err.println("Unable to find config.properties file. OhmLogger will use default settings."); System.err.println("Unable to find config.properties file. OhmLogger will use default settings.");

+ 4
- 0
src/config.properties View File

log.level=INFO log.level=INFO

log.directory=../Aufgabe7_bandit
log.filename=ohmLog

# Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete # Beispiel f\u00fcr verschiedene Level f\u00fcr unterschiedliche Pakete
# log.level.bandit.Zahlengenerator=FINE # log.level.bandit.Zahlengenerator=FINE
# log.level.bandit.Model.Wuerfel=WARNING # log.level.bandit.Model.Wuerfel=WARNING

Loading…
Cancel
Save