Compare commits
No commits in common. "316d22aecd52e17e352b97b1c48854966ec7c3e3" and "9cd09831ff67bd661b71727aad8a79faab64b23d" have entirely different histories.
316d22aecd
...
9cd09831ff
4 changed files with 29 additions and 157 deletions
|
@ -395,7 +395,7 @@ public final class Logar
|
||||||
}
|
}
|
||||||
else if (!file.isFile())
|
else if (!file.isFile())
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Parameter is not a file [" + file + "]");
|
throw new IllegalArgumentException("Parameter is not a file.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -458,31 +458,13 @@ public final class Logar
|
||||||
}
|
}
|
||||||
else if (!source.exists())
|
else if (!source.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Missing source to check [" + source + "]");
|
System.out.println("Missing source to check.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkLogFiles(new Files(source));
|
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for (File file : files)
|
||||||
* Check log files.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the source
|
|
||||||
* @throws IOException
|
|
||||||
* Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
public static void checkLogFiles(final Files source) throws IOException
|
|
||||||
{
|
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
System.out.println("Undefined source.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (File file : source)
|
|
||||||
{
|
{
|
||||||
checkLogFile(file);
|
checkLogFile(file);
|
||||||
}
|
}
|
||||||
|
@ -505,7 +487,7 @@ public final class Logar
|
||||||
}
|
}
|
||||||
else if (!source.exists())
|
else if (!source.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Missing source to check [" + source + "]");
|
System.out.println("Missing source to check.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -518,29 +500,6 @@ public final class Logar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check sort.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the source
|
|
||||||
* @throws IOException
|
|
||||||
* Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
public static void checkSort(final Files source) throws IOException
|
|
||||||
{
|
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
System.out.println("Undefined source.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (File file : source)
|
|
||||||
{
|
|
||||||
checkSortFile(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check sort file.
|
* Check sort file.
|
||||||
*
|
*
|
||||||
|
@ -692,31 +651,12 @@ public final class Logar
|
||||||
}
|
}
|
||||||
else if (!source.exists())
|
else if (!source.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Missing source to sort [" + source + "]");
|
System.out.println("Missing source to sort.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
identify(new Files(source));
|
Files files = FilesUtils.search(source, LOGFILE_PATTERN).removeHidden().sortByName();
|
||||||
}
|
for (File file : files)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Identify.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the source
|
|
||||||
* @throws IOException
|
|
||||||
* Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
public static void identify(final Files source) throws IOException
|
|
||||||
{
|
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
System.out.println("Undefined source.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (File file : source)
|
|
||||||
{
|
{
|
||||||
String type = LogFile.getType(file);
|
String type = LogFile.getType(file);
|
||||||
|
|
||||||
|
@ -741,31 +681,13 @@ public final class Logar
|
||||||
}
|
}
|
||||||
else if (!source.exists())
|
else if (!source.exists())
|
||||||
{
|
{
|
||||||
System.out.println("Missing source to sort [" + source + "]");
|
System.out.println("Missing source to sort.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sort(new Files(source));
|
Files files = FilesUtils.search(source, LOGFILE_PATTERN).removeHidden().sortByName();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for (File file : files)
|
||||||
* Sort.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the source
|
|
||||||
* @throws IOException
|
|
||||||
* Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
public static void sort(final Files source) throws IOException
|
|
||||||
{
|
|
||||||
if (source == null)
|
|
||||||
{
|
|
||||||
System.out.println("Undefined source.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (File file : source)
|
|
||||||
{
|
{
|
||||||
System.out.println("== Sort for [" + file.getName() + "]");
|
System.out.println("== Sort for [" + file.getName() + "]");
|
||||||
LogFile.sortLogFile(file);
|
LogFile.sortLogFile(file);
|
||||||
|
@ -781,18 +703,9 @@ public final class Logar
|
||||||
*/
|
*/
|
||||||
public static void statUserAgents(final File source)
|
public static void statUserAgents(final File source)
|
||||||
{
|
{
|
||||||
statUserAgents(new Files(source));
|
Files files = FilesUtils.searchEndingWith(source, ".log", ".log.gz").keepFileType().sortByName();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for (File file : files)
|
||||||
* Stat user agents.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the source
|
|
||||||
*/
|
|
||||||
public static void statUserAgents(final Files source)
|
|
||||||
{
|
|
||||||
for (File file : source)
|
|
||||||
{
|
{
|
||||||
statUserAgentsForFile(file);
|
statUserAgentsForFile(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.io.PrintWriter;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -239,7 +238,7 @@ public final class LogFile
|
||||||
PrintWriter out = null;
|
PrintWriter out = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (StringUtils.endsWithAny(target.getName(), ".gz", ".gz.tmp"))
|
if (target.getName().endsWith(".gz"))
|
||||||
{
|
{
|
||||||
out = new PrintWriter(new GZIPOutputStream(new FileOutputStream(target)));
|
out = new PrintWriter(new GZIPOutputStream(new FileOutputStream(target)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,26 +167,16 @@ public final class LogarCLI
|
||||||
|
|
||||||
Logar.archive(source, target, OnOffOption.ON);
|
Logar.archive(source, target, OnOffOption.ON);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "check", ".+"))
|
else if (CLIUtils.isMatching(args, "check", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File source = new File(args[1]);
|
||||||
for (int index = 1; index < args.length; index++)
|
|
||||||
{
|
|
||||||
File file = new File(args[index]);
|
|
||||||
Files filteredFiles = FilesUtils.search(file, Logar.LOGFILE_PATTERN).keepFileType().sortByName();
|
|
||||||
source.addAll(filteredFiles);
|
|
||||||
}
|
|
||||||
Logar.checkLogFiles(source);
|
Logar.checkLogFiles(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "checksort", ".+"))
|
else if (CLIUtils.isMatching(args, "checksort", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File source = new File(args[1]);
|
||||||
for (int index = 1; index < args.length; index++)
|
|
||||||
{
|
|
||||||
File file = new File(args[index]);
|
|
||||||
Files filteredFiles = FilesUtils.search(file, Logar.LOGFILE_PATTERN).keepFileType().sortByName();
|
|
||||||
source.addAll(filteredFiles);
|
|
||||||
}
|
|
||||||
Logar.checkSort(source);
|
Logar.checkSort(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "extract", "\\s*((ip)?(,)?(remoteuser)?(,)?(datetime)?(,)?(useragent)?)\\s*", "\\s*\\S+\\s*"))
|
else if (CLIUtils.isMatching(args, "extract", "\\s*((ip)?(,)?(remoteuser)?(,)?(datetime)?(,)?(useragent)?)\\s*", "\\s*\\S+\\s*"))
|
||||||
|
@ -196,37 +186,22 @@ public final class LogarCLI
|
||||||
|
|
||||||
Logar.extract(source, options);
|
Logar.extract(source, options);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "identify", ".+"))
|
else if (CLIUtils.isMatching(args, "identify", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File source = new File(args[1]);
|
||||||
for (int index = 1; index < args.length; index++)
|
|
||||||
{
|
|
||||||
File file = new File(args[index]);
|
|
||||||
Files filteredFiles = FilesUtils.search(file, Logar.LOGFILE_PATTERN).keepFileType().sortByName();
|
|
||||||
source.addAll(filteredFiles);
|
|
||||||
}
|
|
||||||
Logar.identify(source);
|
Logar.identify(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "sort", ".+"))
|
else if (CLIUtils.isMatching(args, "sort", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File source = new File(args[1]);
|
||||||
for (int index = 1; index < args.length; index++)
|
|
||||||
{
|
|
||||||
File file = new File(args[index]);
|
|
||||||
Files filteredFiles = FilesUtils.search(file, Logar.LOGFILE_PATTERN).keepFileType().sortByName();
|
|
||||||
source.addAll(filteredFiles);
|
|
||||||
}
|
|
||||||
Logar.sort(source);
|
Logar.sort(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatchingEllipsis(args, "statuseragent", ".+"))
|
else if (CLIUtils.isMatching(args, "statuseragent", ".+"))
|
||||||
{
|
{
|
||||||
Files source = new Files();
|
File source = new File(args[1]);
|
||||||
for (int index = 1; index < args.length; index++)
|
|
||||||
{
|
|
||||||
File file = new File(args[index]);
|
|
||||||
Files filteredFiles = FilesUtils.search(file, Logar.LOGFILE_PATTERN).keepFileType().sortByName();
|
|
||||||
source.addAll(filteredFiles);
|
|
||||||
}
|
|
||||||
Logar.statUserAgents(source);
|
Logar.statUserAgents(source);
|
||||||
}
|
}
|
||||||
else if (CLIUtils.isMatching(args, "testconcate", ".+"))
|
else if (CLIUtils.isMatching(args, "testconcate", ".+"))
|
||||||
|
|
|
@ -38,21 +38,6 @@ public class Files extends ArrayList<File>
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new files.
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* the file
|
|
||||||
*/
|
|
||||||
public Files(final File file)
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
if (file != null)
|
|
||||||
{
|
|
||||||
add(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new files.
|
* Instantiates a new files.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue