aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/MainModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/MainModule.java')
-rw-r--r--src/main/java/org/traccar/MainModule.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 439dcd1d9..7dcc91f32 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -22,6 +22,8 @@ import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.apache.velocity.app.VelocityEngine;
@@ -59,6 +61,7 @@ import org.traccar.geolocation.UnwiredGeolocationProvider;
import org.traccar.handler.GeocoderHandler;
import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.SpeedLimitHandler;
+import org.traccar.helper.Log;
import org.traccar.helper.SanitizerModule;
import org.traccar.notification.EventForwarder;
import org.traccar.session.cache.CacheManager;
@@ -83,8 +86,15 @@ import java.util.Properties;
public class MainModule extends AbstractModule {
+ private final String configFile;
+
+ public MainModule(String configFile) {
+ this.configFile = configFile;
+ }
+
@Override
protected void configure() {
+ bindConstant().annotatedWith(Names.named("configFile")).to(configFile);
bind(Storage.class).to(DatabaseStorage.class);
bind(Timer.class).to(HashedWheelTimer.class).in(Scopes.SINGLETON);
}
@@ -101,9 +111,17 @@ public class MainModule extends AbstractModule {
return objectMapper;
}
+ @Singleton
@Provides
- public static Config provideConfig() {
- return Context.getConfig();
+ public static Config provideConfig(@Named("configFile") String configFile) throws Exception {
+ try {
+ Config config = new Config(configFile);
+ Log.setupLogger(config);
+ return config;
+ } catch (Exception e) {
+ Log.setupDefaultLogger();
+ throw e;
+ }
}
@Provides