diff --git a/src/fr/devinsy/logar/app/ExtractOption.java b/src/fr/devinsy/logar/app/ExtractOption.java new file mode 100644 index 0000000..31b5ed0 --- /dev/null +++ b/src/fr/devinsy/logar/app/ExtractOption.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of Logar, simple tool to manage http log files. + * + * Logar is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Logar 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Logar. If not, see . + */ +package fr.devinsy.logar.app; + +import org.apache.commons.lang3.StringUtils; + +/** + * The Enum DryOption. + */ +public enum ExtractOption +{ + IP, + DATETIME, + USERAGENT; + + public static ExtractOption of(final String source) + { + ExtractOption result; + + if (source == null) + { + result = null; + } + else + { + String token = source.toLowerCase().trim(); + if (StringUtils.equals(token, "ip")) + { + result = IP; + } + else if (StringUtils.equals(token, "dateime")) + { + result = DATETIME; + } + else if (StringUtils.equals(token, "useragent")) + { + result = USERAGENT; + } + else + { + result = null; + } + } + + // + return result; + } +} diff --git a/src/fr/devinsy/logar/app/Logar.java b/src/fr/devinsy/logar/app/Logar.java index 8d2d6de..7338741 100644 --- a/src/fr/devinsy/logar/app/Logar.java +++ b/src/fr/devinsy/logar/app/Logar.java @@ -520,18 +520,18 @@ public final class Logar else { Files files = FilesUtils.search(source, LOGFILE_PATTERN).removeHidden().keep(".*access.*").sortByName(); - System.out.println(files.size()); + // System.out.println(files.size()); + System.err.println(files.size()); for (File file : files) { - // System.out.println("== Extract userAgent for [" + - // file.getName() + "]"); + System.err.println("== Extract userAgent for [" + file.getName() + "]"); try { LineIterator iterator = new LineIterator(file); while (iterator.hasNext()) { String line = iterator.next(); - + // System.out.println(line); try { Log log = LogParser.parseAccessLog(line); @@ -554,7 +554,7 @@ public final class Logar extract = null; } - System.out.println(log.getUserAgent()); + System.out.println(extract); } catch (IllegalArgumentException exception) { @@ -572,8 +572,6 @@ public final class Logar System.err.println("Error with file [" + file.getAbsolutePath() + "]"); exception.printStackTrace(); } - - LogFile.sortLogFile(file); } } } diff --git a/src/fr/devinsy/logar/app/log/LogParser.java b/src/fr/devinsy/logar/app/log/LogParser.java index 3ab9c70..cfe8ef3 100644 --- a/src/fr/devinsy/logar/app/log/LogParser.java +++ b/src/fr/devinsy/logar/app/log/LogParser.java @@ -88,7 +88,7 @@ public final class LogParser } catch (DateTimeParseException exception) { - throw new IllegalArgumentException("Bad line format (date): " + line); + throw new IllegalArgumentException("Bad line format (date): " + line, exception); } // @@ -144,7 +144,7 @@ public final class LogParser } catch (DateTimeParseException exception) { - throw new IllegalArgumentException("Bad line format (date): " + line); + throw new IllegalArgumentException("Bad line format (date): " + line, exception); } //