Skip to content

Commit f7d9f13

Browse files
committed
Switched Logging to SLF4J solving GH #9.
Allowing every application to be free which logging is used for javapos-config-loader library.
1 parent 24aea5a commit f7d9f13

19 files changed

Lines changed: 184 additions & 1334 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 4.0.0
44

5+
- replaced legacy logging implementation by the logging facade SLF4J, see https://www.slf4j.org/ for details on how to integrate
56
- jpos.config.DefaultCompositeRegPopulator.load() is throwing more specific IllegalArgument exception instead of RuntimeException
67
- added Javax XML parser based XML registry populator implementation (contributed by @mjpcger)
78
- removed Xerces based XML registry populator implementations, mainly

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ def testResourceDir = file("${System.properties['java.io.tmpdir']}/javapos-confi
6565

6666
dependencies {
6767
api 'org.javapos:javapos-contracts:1.6.0'
68+
implementation 'org.slf4j:slf4j-api:2.0.13'
6869

6970
testImplementation("junit:junit:4.13.2")
7071

72+
testRuntimeOnly 'org.slf4j:slf4j-simple:2.0.13'
7173
testRuntimeOnly files(testResourceDir)
7274
}
7375

src/main/java/jpos/config/DefaultCompositeRegPopulator.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import jpos.loader.*;
2626
import jpos.util.*;
27-
import jpos.util.tracing.Tracer;
28-
import jpos.util.tracing.TracerFactory;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2929

3030
/**
3131
* Default implementation of the CompositeRegPopulator interface
@@ -34,6 +34,8 @@
3434
*/
3535
public class DefaultCompositeRegPopulator implements CompositeRegPopulator
3636
{
37+
private static final Logger log = LoggerFactory.getLogger(DefaultCompositeRegPopulator.class);
38+
3739
//-------------------------------------------------------------------------
3840
// Ctor(s)
3941
//
@@ -91,27 +93,23 @@ private JposRegPopulator createPopulator( String popName, String className )
9193
}
9294
catch( ClassNotFoundException cnfe )
9395
{
94-
tracer.println( "Could not find populator class with name: " +
95-
className + " exception message = " +
96-
cnfe.getMessage() );
96+
log.error( "Could not find populator class with name: {} exception message = {}",
97+
className, cnfe.getMessage() );
9798
}
9899
catch( NoSuchMethodException nsme )
99100
{
100-
tracer.println( "Populator by class name: " +
101-
className +
102-
" must define a no-arg ctor or a 1-arg ctor with String param as the unique ID" );
101+
log.error( "Populator by class name: {} must define a no-arg ctor or a 1-arg ctor with String param as the unique ID",
102+
className );
103103
}
104104
catch( InstantiationException ie )
105105
{
106-
tracer.println( "Could not instantiate populator class with name: " +
107-
className + " exception message = " +
108-
ie.getMessage() );
106+
log.error( "Could not instantiate populator class with name: {} exception message = {}",
107+
className, ie.getMessage() );
109108
}
110109
catch( Exception e )
111110
{
112-
tracer.println( "Could not instantiate populator class with name: " +
113-
className + " exception message = " +
114-
e.getMessage() );
111+
log.error( "Could not instantiate populator class with name: {} exception message = {}",
112+
className, e.getMessage() );
115113
}
116114

117115
return populator;
@@ -187,9 +185,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc
187185
List<JposEntry> entryList = popEntriesMap.get( populator.getUniqueId() );
188186

189187
if( entryList == null )
190-
tracer.println( "Trying to save entry with logicalName = " +
191-
entry.getLogicalName() +
192-
" and populator with" );
188+
log.debug( "Trying to save entry with logicalName = {} and populator with entry list null", entry.getLogicalName() );
193189
else
194190
entryList.add( entry );
195191
}
@@ -214,8 +210,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc
214210
catch( Exception e )
215211
{
216212
exception = e;
217-
tracer.println( "Error while saving to populator with unique ID:" +
218-
populator.getUniqueId() );
213+
log.error( "Error while saving to populator with unique ID: {}", populator.getUniqueId() );
219214
}
220215
}
221216

@@ -254,7 +249,7 @@ public void load()
254249

255250
if( populatorClassMultiProp == null || populatorClassMultiProp.getNumberOfProperties() == 0 )
256251
{
257-
tracer.println( "CompositeRegPopulator.load() w/o any defined multi-property" );
252+
log.error( "CompositeRegPopulator.load() w/o any defined multi-property" );
258253
throw new IllegalArgumentException( "CompositeRegPopulator.load() w/o any defined multi-property" );
259254
}
260255

@@ -281,8 +276,7 @@ public void load()
281276
}
282277
else
283278
{
284-
tracer.println( "Created default populator with name = " + defaultPopName +
285-
" OK but populator file is null" );
279+
log.debug( "Created default populator with name = {} OK but populator file is null", defaultPopName );
286280
defaultPopulator.load();
287281
lastLoadException = defaultPopulator.getLastLoadException();
288282
}
@@ -296,8 +290,7 @@ public void load()
296290
setDefaultPopulator( defaultPopulator );
297291
}
298292
else
299-
tracer.println( "Did not add default populator by <name, className>: " +
300-
"<" + defaultPopName + ", " + defaultPopClass + ">" );
293+
log.debug( "Did not add default populator by <name, className>: <{}, {}>", defaultPopName, defaultPopClass);
301294
while( popClasses.hasNext() )
302295
{
303296
String popName = popClasses.next();
@@ -316,17 +309,15 @@ public void load()
316309
}
317310
else
318311
{
319-
tracer.println( "Created populator with name = " + popName +
320-
" OK but populator file is null" );
312+
log.debug( "Created populator with name = {} OK but populator file is null", popName );
321313
populator.load();
322314
lastLoadException = populator.getLastLoadException();
323315
}
324316

325317
add( populator );
326318
}
327319
else
328-
tracer.println( "Did not add populator by <name, className>: " +
329-
"<" + popName + ", " + popClass + ">" );
320+
log.debug( "Did not add populator by <name, className>: <{}, {}>", popName, popClass );
330321
}
331322
}
332323

@@ -432,7 +423,4 @@ public JposRegPopulator getPopulator( String uniqueId )
432423
private HashMap<String, String> popFileMap = new HashMap<>();
433424
private JposRegPopulator defaultPop = null;
434425
private Exception lastLoadException = null;
435-
436-
private Tracer tracer = TracerFactory.getInstance().
437-
createTracer( "DefaultCompositeRegPopulator" );
438426
}

src/main/java/jpos/config/simple/AbstractRegPopulator.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import jpos.loader.JposServiceLoader;
2828
import jpos.util.JposProperties;
2929
import jpos.util.JposPropertiesConst;
30-
import jpos.util.tracing.Tracer;
31-
import jpos.util.tracing.TracerFactory;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3232

3333
/**
3434
* Common abstract superclass to help in the implementation of the
@@ -39,6 +39,8 @@
3939
*/
4040
public abstract class AbstractRegPopulator implements JposRegPopulator
4141
{
42+
private static final Logger log = LoggerFactory.getLogger(AbstractRegPopulator.class);
43+
4244
//-------------------------------------------------------------------------
4345
// Ctor(s)
4446
//
@@ -115,8 +117,7 @@ protected URL createURLFromFile( File file )
115117
{ url = new URL( "file", "", file.getAbsolutePath() ); }
116118
catch( Exception e )
117119
{
118-
tracer.println( "Error creating URL: Exception.message=" +
119-
e.getMessage() );
120+
log.error( "Error creating URL: Exception.message={}", e.getMessage() );
120121
}
121122

122123
return url;
@@ -138,8 +139,7 @@ protected URL createURLFromFile( ZipFile zipFile )
138139
}
139140
catch( Exception e )
140141
{
141-
tracer.println( "Error creating URL: Exception.message=" +
142-
e.getMessage() );
142+
log.error( "Error creating URL: Exception.message={}", e.getMessage() );
143143
}
144144

145145
return url;
@@ -213,8 +213,7 @@ protected InputStream getPopulatorFileIS() throws Exception
213213
jposProperties.getPropertyString(
214214
JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME );
215215

216-
tracer.println( "getPopulatorFileIS(): populatorFileName=" +
217-
populatorFileName );
216+
log.debug( "getPopulatorFileIS(): populatorFileName={}", populatorFileName );
218217

219218
populatorIS = new FileInputStream( populatorFileName );
220219
}
@@ -229,15 +228,14 @@ protected InputStream getPopulatorFileIS() throws Exception
229228

230229
populatorIS = url.openStream();
231230

232-
tracer.println( "getPopulatorFileIS(): populatorFileURL=" +
233-
populatorFileURL );
231+
log.debug( "getPopulatorFileIS(): populatorFileURL={}", populatorFileURL );
234232
}
235233
else
236234
{
237235
String msg = "jpos.config.populatorFile OR " +
238236
" jpos.config.populatorFileURL properties not defined";
239237

240-
tracer.println( msg );
238+
log.error( msg );
241239

242240
throw new Exception( msg );
243241
}
@@ -284,7 +282,7 @@ protected OutputStream getPopulatorFileOS() throws Exception
284282
String msg = "jpos.config.populatorFile OR " +
285283
"jpos.config.populatorFileURL properties not defined";
286284

287-
tracer.println( msg );
285+
log.error( msg );
288286

289287
throw new Exception( msg );
290288
}
@@ -338,8 +336,7 @@ protected InputStream findFileInClasspath( String fileName )
338336
{
339337
is = null;
340338

341-
tracer.println( "findFileInClasspath: IOException.msg=" +
342-
ioe.getMessage() );
339+
log.error( "findFileInClasspath: IOException.msg={}", ioe.getMessage() );
343340
}
344341

345342
return is;
@@ -431,8 +428,7 @@ private InputStream findFileInJarZipFiles( String fileName, List<String> jarZipF
431428
}
432429
catch( Exception e )
433430
{
434-
tracer.println( "findInJarZipFiles: Exception.message=" +
435-
e.getMessage() );
431+
log.error( "findInJarZipFiles: Exception.message={}", e.getMessage() );
436432
}
437433

438434
if( is != null ) break;
@@ -453,7 +449,4 @@ private InputStream findFileInJarZipFiles( String fileName, List<String> jarZipF
453449
private String uniqueId = "";
454450

455451
protected Exception lastLoadException = null;
456-
457-
private Tracer tracer = TracerFactory.getInstance().
458-
createTracer( "AbstractRegPopulator" );
459452
}

src/main/java/jpos/config/simple/SimpleEntryRegistry.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
import jpos.config.*;
2525

26-
import jpos.util.tracing.Tracer;
27-
import jpos.util.tracing.TracerFactory;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2828

2929
/**
3030
* This is a simple implementation for the JposEntryRegistry using a Hashtable
@@ -35,6 +35,8 @@
3535
*/
3636
public class SimpleEntryRegistry implements JposEntryRegistry
3737
{
38+
private static final Logger log = LoggerFactory.getLogger(SimpleEntryRegistry.class);
39+
3840
/**
3941
* One-argument constructor
4042
* @param populator the JposRegPopulator used by the registry
@@ -89,7 +91,7 @@ public void modifyJposEntry( String logicalName, JposEntry newEntry )
8991
{
9092
jposEntries.put( logicalName, newEntry );
9193

92-
tracer.println( "Modified entry.logicalName = " + logicalName );
94+
log.debug( "Modified entry.logicalName = {}", logicalName );
9395

9496
fireJposEntryRegistryEventModified( new JposEntryRegistryEvent(
9597
this, newEntry ) );
@@ -104,7 +106,7 @@ public void addJposEntry( String logicalName, JposEntry entry )
104106
{
105107
jposEntries.put( logicalName, entry );
106108

107-
tracer.println( "Added entry.logicalName = " + logicalName );
109+
log.debug( "Added entry.logicalName = {}", logicalName );
108110

109111
fireJposEntryRegistryEventAdded( new JposEntryRegistryEvent(
110112
this, entry ) );
@@ -141,8 +143,7 @@ public void removeJposEntry( JposEntry entry )
141143
jposEntries.remove( entry.getPropertyValue( JposEntry.
142144
LOGICAL_NAME_PROP_NAME ) );
143145

144-
tracer.println( "Removed entry.logicalName = " +
145-
entry.getLogicalName() );
146+
log.debug( "Removed entry.logicalName = {}", entry.getLogicalName() );
146147

147148
fireJposEntryRegistryEventRemoved( new JposEntryRegistryEvent(
148149
this, removedEntry ) );
@@ -151,8 +152,7 @@ public void removeJposEntry( JposEntry entry )
151152
}
152153
}
153154

154-
tracer.println( "Could not find entry to remove entry.logicalName = " +
155-
entry.getLogicalName() );
155+
log.debug( "Could not find entry to remove entry.logicalName = {}", entry.getLogicalName() );
156156
}
157157

158158
/**
@@ -236,7 +236,9 @@ public void load()
236236

237237
jposEntries.put( jposEntry.getLogicalName(), jposEntry );
238238
}
239-
catch( Exception e ) { tracer.print( e ); }
239+
catch( Exception e ) {
240+
log.error( e.getMessage() );
241+
}
240242
}
241243

242244
loaded = true;
@@ -305,9 +307,8 @@ public String toString()
305307
*/
306308
protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e )
307309
{
308-
tracer.println( "fireJposEntryRegistryEventAdded: " +
309-
"e.getJposEntry().logicalName = " +
310-
e.getJposEntry().getLogicalName() );
310+
log.debug( "fireJposEntryRegistryEventAdded: e.getJposEntry().logicalName = {}",
311+
e.getJposEntry().getLogicalName() );
311312

312313
@SuppressWarnings("unchecked")
313314
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
@@ -327,9 +328,8 @@ protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e )
327328
*/
328329
protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e )
329330
{
330-
tracer.println( "fireJposEntryRegistryEventRemoved: " +
331-
"e.getJposEntry().logicalName = " +
332-
e.getJposEntry().getLogicalName() );
331+
log.debug( "fireJposEntryRegistryEventRemoved: e.getJposEntry().logicalName = {}",
332+
e.getJposEntry().getLogicalName() );
333333

334334
@SuppressWarnings("unchecked")
335335
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
@@ -348,9 +348,8 @@ protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e )
348348
*/
349349
protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e )
350350
{
351-
tracer.println( "fireJposEntryRegistryEventModified: " +
352-
"e.getJposEntry().logicalName = " +
353-
e.getJposEntry().getLogicalName() );
351+
log.debug( "fireJposEntryRegistryEventModified: e.getJposEntry().logicalName = {}",
352+
e.getJposEntry().getLogicalName() );
354353

355354
@SuppressWarnings("unchecked")
356355
Vector<JposEntryRegistryListener> listenersClone = (Vector<JposEntryRegistryListener>) listeners.clone();
@@ -370,7 +369,4 @@ protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e )
370369
private final Vector<JposEntryRegistryListener> listeners = new Vector<>();
371370
private JposRegPopulator regPopulator = null;
372371
private boolean loaded = false;
373-
374-
private Tracer tracer = TracerFactory.getInstance().
375-
createTracer( "SimpleEntryRegistry" );
376372
}

0 commit comments

Comments
 (0)