Skip to content

Commit 3a56f76

Browse files
authored
Merge pull request #901 from zfi/demo
Enable Application Logging
2 parents d528085 + a5915ce commit 3a56f76

File tree

10 files changed

+717
-135
lines changed

10 files changed

+717
-135
lines changed

pom.xml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,25 @@
238238
<artifactId>slf4j-api</artifactId>
239239
<version>1.7.21</version>
240240
</dependency>
241+
242+
<dependency>
243+
<groupId>ch.qos.logback</groupId>
244+
<artifactId>logback-classic</artifactId>
245+
<version>1.1.8</version>
246+
</dependency>
247+
<dependency>
248+
<groupId>ch.qos.logback</groupId>
249+
<artifactId>logback-core</artifactId>
250+
<version>1.1.8</version>
251+
</dependency>
252+
253+
<!--
241254
<dependency>
242255
<groupId>org.slf4j</groupId>
243256
<artifactId>slf4j-log4j12</artifactId>
244257
<version>1.7.21</version>
245258
</dependency>
259+
-->
246260
<!-- END Logging Dependencies -->
247261

248262
<!-- Dependencies for Guice -->
@@ -389,10 +403,17 @@
389403

390404
<dependency>
391405
<groupId>net.kencochrane.raven</groupId>
392-
<artifactId>raven-log4j</artifactId>
406+
<artifactId>raven-logback</artifactId>
393407
<version>6.0.0</version>
394408
</dependency>
395409

410+
<!--
411+
<dependency>
412+
<groupId>net.kencochrane.raven</groupId>
413+
<artifactId>raven-log4j</artifactId>
414+
<version>6.0.0</version>
415+
</dependency>
416+
-->
396417
<!-- Lucene search engine -->
397418
<dependency>
398419
<groupId>org.apache.lucene</groupId>
@@ -439,12 +460,19 @@
439460
<version>${metrics-version}</version>
440461
</dependency>
441462

463+
<dependency>
464+
<groupId>io.dropwizard.metrics</groupId>
465+
<artifactId>metrics-logback</artifactId>
466+
<version>3.1.2</version>
467+
</dependency>
468+
469+
<!--
442470
<dependency>
443471
<groupId>io.dropwizard.metrics</groupId>
444472
<artifactId>metrics-log4j</artifactId>
445473
<version>${metrics-version}</version>
446474
</dependency>
447-
475+
-->
448476
<dependency>
449477
<groupId>io.dropwizard.metrics</groupId>
450478
<artifactId>metrics-servlet</artifactId>

src/main/java/com/parallax/server/blocklyprop/config/DaoModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,26 @@
1515
import com.parallax.server.blocklyprop.db.dao.impl.SessionDaoImpl;
1616
import com.parallax.server.blocklyprop.db.dao.impl.UserDaoImpl;
1717

18+
1819
/**
1920
*
2021
* @author Michel
22+
*
23+
* AbstractModule:
24+
* A support class for Modules which reduces repetition and results in a more
25+
* readable configuration. Simply extend this class, implement configure(),
26+
* and call the inherited methods which mirror those found in Binder.
27+
* For example:
28+
*
29+
* public class MyModule extends AbstractModule {
30+
* protected void configure() {
31+
* bind(Service.class).to(ServiceImpl.class).in(Singleton.class);
32+
* bind(CreditCardPaymentService.class);
33+
* bind(PaymentService.class).to(CreditCardPaymentService.class);
34+
* bindConstant().annotatedWith(Names.named("port")).to(8080);
35+
* }
36+
* }
37+
*
2138
*/
2239
public class DaoModule extends AbstractModule {
2340

src/main/java/com/parallax/server/blocklyprop/config/PersistenceModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import com.google.inject.Provides;
1111
import com.parallax.server.blocklyprop.db.utils.DataSourceSetup;
1212
import java.sql.SQLException;
13-
import java.util.logging.Level;
14-
import java.util.logging.Logger;
1513
import javax.sql.DataSource;
1614
import org.apache.commons.configuration.Configuration;
1715
import org.apache.commons.dbcp2.PoolingDataSource;
1816
import org.jooq.SQLDialect;
17+
import java.util.logging.Level;
18+
import java.util.logging.Logger;
19+
1920

2021
/**
2122
*
@@ -37,6 +38,7 @@ protected void configure() {
3738

3839
@Provides
3940
PoolingDataSource dataSource() throws ClassNotFoundException {
41+
4042
PoolingDataSource ds = DataSourceSetup.connect(configuration);
4143
try {
4244
ds.getConnection();

src/main/java/com/parallax/server/blocklyprop/config/SetupConfig.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import org.apache.commons.configuration.Configuration;
2222
import org.apache.commons.configuration.ConfigurationException;
2323
import org.apache.commons.configuration.DefaultConfigurationBuilder;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
import ch.qos.logback.classic.LoggerContext;
27+
2428

2529
/**
2630
*
@@ -29,6 +33,7 @@
2933
public class SetupConfig extends GuiceServletContextListener {
3034

3135
private Configuration configuration;
36+
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
3237

3338
@Override
3439
protected Injector getInjector() {
@@ -62,10 +67,11 @@ protected void configure() {
6267

6368
private void readConfiguration() {
6469
try {
65-
System.out.println("Looking for blocklyprop.properties in: " + System.getProperty("user.home"));
70+
LOG.info("Looking for blocklyprop.properties in: {}", System.getProperty("user.home"));
6671
DefaultConfigurationBuilder configurationBuilder = new DefaultConfigurationBuilder(getClass().getResource("/config.xml"));
6772
configuration = configurationBuilder.getConfiguration();
6873
} catch (ConfigurationException ce) {
74+
LOG.error("{}", ce.getMessage());
6975
ce.printStackTrace();
7076
} catch (Throwable t) {
7177
t.printStackTrace();
@@ -81,12 +87,20 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) {
8187
Driver driver = drivers.nextElement();
8288
try {
8389
DriverManager.deregisterDriver(driver);
84-
// LOG.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver));
90+
LOG.info("deregistering jdbc driver: {}",driver);
8591
} catch (SQLException sqlE) {
8692
// LOG.log(Level.SEVERE, String.format("Error deregistering driver %s", driver), e);
8793
}
8894

8995
}
96+
97+
// Shut down the loggers. Assume SLF4J is bound to logback-classic
98+
// in the current environment
99+
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
100+
if (loggerContext != null) {
101+
loggerContext.stop();
102+
}
103+
90104
}
91105

92106
}

0 commit comments

Comments
 (0)