Migrate to SLF4J.

This commit is contained in:
Christian P. MOMON 2013-06-26 16:40:18 +02:00
parent f4307c754c
commit cb0d17104f
28 changed files with 98 additions and 85 deletions

View file

@ -8,5 +8,7 @@
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/> <classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/junit-4.11.jar"/> <classpathentry kind="lib" path="lib/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/> <classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -2,3 +2,5 @@ Description of used libraries:
- hamcrest-core: required by junit - hamcrest-core: required by junit
- junit: unit tests API - junit: unit tests API
- log4j: log API - log4j: log API
- slf4j-api: facade log API
- slf4j-log4j12: adaptation layer between slf4j and log4j

Binary file not shown.

BIN
lib/slf4j-api-1.7.5.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/slf4j-log4j12-1.7.5.jar Normal file

Binary file not shown.

View file

@ -17,8 +17,8 @@ import java.util.regex.Pattern;
*/ */
public class DateHelper public class DateHelper
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (DateHelper.class); // LoggerFactory.getLogger(DateHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d"; static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d"; static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d";

View file

@ -7,13 +7,13 @@ package fr.devinsy.util;
import java.util.Calendar; import java.util.Calendar;
/** /**
* This class groups function to help in Calendar manipulation. * This class groups function to help in Calendar manipulation.
*/ */
public class DateTimeHelper public class DateTimeHelper
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (DateTimeHelper.class); // static private final Logger logger =
// LoggerFactory.getLogger(DateTimeHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d"; static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d %02d:%02d:%02d";
static final String RAW_DATE_FORMAT = "%04d%02d%02d %02d:%02d:%02d"; static final String RAW_DATE_FORMAT = "%04d%02d%02d %02d:%02d:%02d";
@ -25,11 +25,10 @@ public class DateTimeHelper
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$"; static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$"; static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/** /**
* *
*/ */
static public String europeanFormat (Calendar time) static public String americanFormat(final Calendar time)
{ {
String result; String result;
@ -39,11 +38,49 @@ public class DateTimeHelper
} }
else else
{ {
result = String.format (EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MONTH) + 1, time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
time.get(Calendar.YEAR), }
time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), //
return (result);
}
/**
*
*/
static public String europeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR), time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE), time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.SECOND)); time.get(Calendar.SECOND));
} }
@ -51,11 +88,10 @@ public class DateTimeHelper
return (result); return (result);
} }
/** /**
* *
*/ */
static public String ISOFormat (Calendar time) static public String rawFormat(final Calendar time)
{ {
String result; String result;
@ -65,63 +101,7 @@ public class DateTimeHelper
} }
else else
{ {
result = String.format (ISO_DATE_FORMAT, time.get(Calendar.YEAR), result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE),
time.get(Calendar.MONTH) + 1,
time.get(Calendar.DAY_OF_MONTH),
time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String americanFormat (Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1,
time.get(Calendar.DAY_OF_MONTH),
time.get(Calendar.YEAR),
time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE),
time.get(Calendar.SECOND));
}
//
return (result);
}
/**
*
*/
static public String rawFormat (Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (RAW_DATE_FORMAT, time.get(Calendar.YEAR),
time.get(Calendar.MONTH) + 1,
time.get(Calendar.DAY_OF_MONTH),
time.get(Calendar.HOUR_OF_DAY),
time.get(Calendar.MINUTE),
time.get(Calendar.SECOND)); time.get(Calendar.SECOND));
} }

View file

@ -1,5 +1,8 @@
package fr.devinsy.util.cmdexec; package fr.devinsy.util.cmdexec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.StringConcatenator; import fr.devinsy.util.StringConcatenator;
/** /**
@ -8,7 +11,7 @@ import fr.devinsy.util.StringConcatenator;
*/ */
public class CmdExec public class CmdExec
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CmdExec.class); static private final Logger logger = LoggerFactory.getLogger(CmdExec.class);
protected int exitValue; protected int exitValue;
protected String out; protected String out;

View file

@ -5,12 +5,15 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class StreamGobbler extends Thread public class StreamGobbler extends Thread
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CmdExec.class); static private final Logger logger = LoggerFactory.getLogger(CmdExec.class);
static final public int NONE = 0; static final public int NONE = 0;
static final public int PRINT = 1; static final public int PRINT = 1;

View file

@ -5,13 +5,16 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class Wrapper public class Wrapper
{ {
static private final Wrapper instance = new Wrapper(); static private final Wrapper instance = new Wrapper();
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Wrapper.class); static private final Logger logger = LoggerFactory.getLogger(Wrapper.class);
/** /**
* return instance of the controller * return instance of the controller

View file

@ -2,6 +2,9 @@ package fr.devinsy.util.unix;
import java.io.File; import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
@ -12,7 +15,7 @@ public class CachedFile
NOT_LOAD, EXPIRED, UPDATED NOT_LOAD, EXPIRED, UPDATED
} }
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CachedFile.class); static private final Logger logger = LoggerFactory.getLogger(CachedFile.class);
protected String sourceName; protected String sourceName;
protected long sourceTime; protected long sourceTime;

View file

@ -7,8 +7,8 @@ import java.util.Vector;
*/ */
public class EtcGroupFile extends CachedFile public class EtcGroupFile extends CachedFile
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (EtcGroupFile.class); // LoggerFactory.getLogger(EtcGroupFile.class);
static EtcGroupFile instance = null; static EtcGroupFile instance = null;
protected Groups groups; protected Groups groups;

View file

@ -4,12 +4,15 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class EtcGroupFileReader public class EtcGroupFileReader
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcGroupFileReader.class); static private final Logger logger = LoggerFactory.getLogger(EtcGroupFileReader.class);
/** /**
* *

View file

@ -1,11 +1,14 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class EtcPasswdFile extends CachedFile public class EtcPasswdFile extends CachedFile
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcPasswdFile.class); static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class);
static EtcPasswdFile instance = null; static EtcPasswdFile instance = null;
protected Users users; protected Users users;

View file

@ -4,12 +4,15 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class EtcPasswdFileReader public class EtcPasswdFileReader
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcPasswdFileReader.class); static private final Logger logger = LoggerFactory.getLogger(EtcPasswdFileReader.class);
/** /**
* *

View file

@ -7,8 +7,8 @@ import java.util.Vector;
*/ */
public class Group public class Group
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (Group.class); // LoggerFactory.getLogger(Group.class);
/* /*
* /usr/include/grp.h * /usr/include/grp.h

View file

@ -11,8 +11,8 @@ public class Groups extends Vector<Group>
private static final long serialVersionUID = 5802487312198869603L; private static final long serialVersionUID = 5802487312198869603L;
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (Groups.class); // LoggerFactory.getLogger(Groups.class);
/** /**
* *

View file

@ -3,6 +3,9 @@ package fr.devinsy.util.unix;
import java.io.File; import java.io.File;
import java.util.Vector; import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.StringConcatenator; import fr.devinsy.util.StringConcatenator;
import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.unix.acl.Acl; import fr.devinsy.util.unix.acl.Acl;
@ -13,7 +16,7 @@ import fr.devinsy.util.unix.acl.AclManager;
*/ */
public class Unix public class Unix
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Unix.class); static private final Logger logger = LoggerFactory.getLogger(Unix.class);
static public final String SUDO = "/usr/bin/sudo"; static public final String SUDO = "/usr/bin/sudo";
/** /**

View file

@ -1,12 +1,12 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
/** /**
* *
*/ */
public class User public class User
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger = LoggerFactory.getLogger(User.class);
// org.apache.log4j.Logger.getLogger (User.class);
/* /*
* /usr/include/pwd.h * /usr/include/pwd.h

View file

@ -10,8 +10,8 @@ public class Users extends Vector<User>
{ {
private static final long serialVersionUID = -7178304512851592399L; private static final long serialVersionUID = -7178304512851592399L;
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (Users.class); // LoggerFactory.getLogger(Users.class);
/** /**
* *

View file

@ -5,8 +5,7 @@ package fr.devinsy.util.unix.acl;
*/ */
public class Acl public class Acl
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger = LoggerFactory.getLogger(Acl.class);
// org.apache.log4j.Logger.getLogger (Acl.class);
/* /*
# file: goo39 # file: goo39

View file

@ -10,8 +10,8 @@ public class AclEntries extends Vector<AclEntry>
{ {
private static final long serialVersionUID = 5802487312198869603L; private static final long serialVersionUID = 5802487312198869603L;
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (AclEntries.class); // LoggerFactory.getLogger(AclEntries.class);
/** /**
* *

View file

@ -1,12 +1,13 @@
package fr.devinsy.util.unix.acl; package fr.devinsy.util.unix.acl;
/** /**
* *
*/ */
public class AclEntry public class AclEntry
{ {
// static private org.apache.log4j.Logger logger = // static private final Logger logger =
// org.apache.log4j.Logger.getLogger (AclEntry.class); // LoggerFactory.getLogger(AclEntry.class);
/* /*
user::rwx user::rwx

View file

@ -4,6 +4,9 @@ import java.io.File;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.StringConcatenator; import fr.devinsy.util.StringConcatenator;
import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.unix.Unix; import fr.devinsy.util.unix.Unix;
@ -13,7 +16,7 @@ import fr.devinsy.util.unix.Unix;
*/ */
public class AclManager public class AclManager
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AclManager.class); static private final Logger logger = LoggerFactory.getLogger(AclManager.class);
static public final String SUDO = "/usr/bin/sudo"; static public final String SUDO = "/usr/bin/sudo";
static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$"); static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");

View file

@ -1,3 +1,8 @@
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.PatternLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.cmdexec.StreamGobbler; import fr.devinsy.util.cmdexec.StreamGobbler;
@ -6,30 +11,26 @@ import fr.devinsy.util.cmdexec.StreamGobbler;
*/ */
class CmdExecPlayer class CmdExecPlayer
{ {
static private org.apache.log4j.Logger logger; static private final Logger logger;
static static
{ {
// Initialize logger. // Initialize logger.
org.apache.log4j.Logger logger = null;
org.apache.log4j.BasicConfigurator.configure(); org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
logger = org.apache.log4j.Logger.getRootLogger(); logger = LoggerFactory.getLogger(CmdExecPlayer.class);
// logger.setLevel (org.apache.log4j.Level.INFO);
logger.setLevel(org.apache.log4j.Level.INFO);
logger.info("Enter"); logger.info("Enter");
// //
logger.info("Set the log file format..."); logger.info("Set the log file format...");
org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.removeAllAppenders();
defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
// log =
// org.apache.log4j.Category.getInstance(Application.class.getName());
logger.info("... done."); logger.info("... done.");
logger.debug("Exit"); logger.debug("Exit");
logger = org.apache.log4j.Logger.getLogger(CmdExecPlayer.class);
} }
/** /**

View file

@ -1,9 +1,9 @@
import java.io.File; import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender; import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout; import org.apache.log4j.PatternLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.FileIterator; import fr.devinsy.util.FileIterator;
@ -12,22 +12,23 @@ import fr.devinsy.util.FileIterator;
*/ */
public class FileIteratorPlayer public class FileIteratorPlayer
{ {
static private org.apache.log4j.Logger logger; static private final Logger logger;
static static
{ {
// Initialize logger. // Initialize logger.
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);
BasicConfigurator.configure(); logger = LoggerFactory.getLogger(CmdExecPlayer.class);
Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.setLevel(org.apache.log4j.Level.DEBUG);
//
org.apache.log4j.Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.removeAllAppenders(); defaultLogger.removeAllAppenders();
defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - FIT [%-5p] %34.34c.%-25M - %m%n"))); defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - dutils [%-5p] %34.34c.%-25M - %m%n")));
defaultLogger.debug("Log initialized."); //
logger.debug("Log initialized.");
logger = org.apache.log4j.Logger.getLogger(FileIteratorPlayer.class.getName());
} }
/** /**

View file

@ -4,7 +4,7 @@ import org.junit.Test;
public class Foo2Test public class Foo2Test
{ {
// private Logger logger = // static private final Logger logger =
// LoggerFactory.getLogger(PdfGenerationAmqpServiceInjectedTest.class); // LoggerFactory.getLogger(PdfGenerationAmqpServiceInjectedTest.class);
/** /**