Improved parameter management.
This commit is contained in:
parent
9cd09831ff
commit
c2520f05b7
3 changed files with 155 additions and 28 deletions
|
@ -395,7 +395,7 @@ public final class Logar
|
|||
}
|
||||
else if (!file.isFile())
|
||||
{
|
||||
throw new IllegalArgumentException("Parameter is not a file.");
|
||||
throw new IllegalArgumentException("Parameter is not a file [" + file + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -458,13 +458,31 @@ public final class Logar
|
|||
}
|
||||
else if (!source.exists())
|
||||
{
|
||||
System.out.println("Missing source to check.");
|
||||
System.out.println("Missing source to check [" + source + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
|
||||
checkLogFiles(new Files(source));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -487,7 +505,7 @@ public final class Logar
|
|||
}
|
||||
else if (!source.exists())
|
||||
{
|
||||
System.out.println("Missing source to check.");
|
||||
System.out.println("Missing source to check [" + source + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -500,6 +518,29 @@ 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.
|
||||
*
|
||||
|
@ -651,12 +692,31 @@ public final class Logar
|
|||
}
|
||||
else if (!source.exists())
|
||||
{
|
||||
System.out.println("Missing source to sort.");
|
||||
System.out.println("Missing source to sort [" + source + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
Files files = FilesUtils.search(source, LOGFILE_PATTERN).removeHidden().sortByName();
|
||||
for (File file : files)
|
||||
identify(new Files(source));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
|
@ -681,13 +741,31 @@ public final class Logar
|
|||
}
|
||||
else if (!source.exists())
|
||||
{
|
||||
System.out.println("Missing source to sort.");
|
||||
System.out.println("Missing source to sort [" + source + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
Files files = FilesUtils.search(source, LOGFILE_PATTERN).removeHidden().sortByName();
|
||||
sort(new Files(source));
|
||||
}
|
||||
}
|
||||
|
||||
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() + "]");
|
||||
LogFile.sortLogFile(file);
|
||||
|
@ -703,9 +781,18 @@ public final class Logar
|
|||
*/
|
||||
public static void statUserAgents(final File source)
|
||||
{
|
||||
Files files = FilesUtils.searchEndingWith(source, ".log", ".log.gz").keepFileType().sortByName();
|
||||
statUserAgents(new Files(source));
|
||||
}
|
||||
|
||||
for (File file : files)
|
||||
/**
|
||||
* Stat user agents.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
*/
|
||||
public static void statUserAgents(final Files source)
|
||||
{
|
||||
for (File file : source)
|
||||
{
|
||||
statUserAgentsForFile(file);
|
||||
}
|
||||
|
|
|
@ -167,16 +167,26 @@ public final class LogarCLI
|
|||
|
||||
Logar.archive(source, target, OnOffOption.ON);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "check", ".+"))
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "check", ".+"))
|
||||
{
|
||||
File source = new File(args[1]);
|
||||
|
||||
Files source = new Files();
|
||||
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);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "checksort", ".+"))
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "checksort", ".+"))
|
||||
{
|
||||
File source = new File(args[1]);
|
||||
|
||||
Files source = new Files();
|
||||
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);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "extract", "\\s*((ip)?(,)?(remoteuser)?(,)?(datetime)?(,)?(useragent)?)\\s*", "\\s*\\S+\\s*"))
|
||||
|
@ -186,22 +196,37 @@ public final class LogarCLI
|
|||
|
||||
Logar.extract(source, options);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "identify", ".+"))
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "identify", ".+"))
|
||||
{
|
||||
File source = new File(args[1]);
|
||||
|
||||
Files source = new Files();
|
||||
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);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "sort", ".+"))
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "sort", ".+"))
|
||||
{
|
||||
File source = new File(args[1]);
|
||||
|
||||
Files source = new Files();
|
||||
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);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "statuseragent", ".+"))
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "statuseragent", ".+"))
|
||||
{
|
||||
File source = new File(args[1]);
|
||||
|
||||
Files source = new Files();
|
||||
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);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "testconcate", ".+"))
|
||||
|
|
|
@ -38,6 +38,21 @@ public class Files extends ArrayList<File>
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new files.
|
||||
*
|
||||
* @param file
|
||||
* the file
|
||||
*/
|
||||
public Files(final File file)
|
||||
{
|
||||
super();
|
||||
if (file != null)
|
||||
{
|
||||
add(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new files.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue