1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.wayf;
18
19 import java.util.Timer;
20
21 import org.opensaml.util.resource.FilesystemResource;
22 import org.opensaml.util.resource.Resource;
23 import org.opensaml.util.resource.ResourceChangeWatcher;
24 import org.opensaml.util.resource.ResourceException;
25 import org.slf4j.LoggerFactory;
26
27 import ch.qos.logback.classic.LoggerContext;
28 import ch.qos.logback.core.status.ErrorStatus;
29 import ch.qos.logback.core.status.StatusManager;
30
31
32
33
34 public class LogbackLoggingService {
35
36
37 private Timer taskTimer;
38
39
40
41
42
43
44
45 public LogbackLoggingService(String loggingConfigurationFile, long pollingFrequency) {
46 LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
47 StatusManager statusManager = loggerContext.getStatusManager();
48
49 try{
50 Resource configResource = new FilesystemResource(loggingConfigurationFile);
51 LogbackConfigurationChangeListener configChangeListener = new LogbackConfigurationChangeListener();
52 configChangeListener.onResourceCreate(configResource);
53
54 ResourceChangeWatcher resourceWatcher = new ResourceChangeWatcher(configResource, pollingFrequency, 5);
55 resourceWatcher.getResourceListeners().add(configChangeListener);
56
57 taskTimer = new Timer(true);
58 taskTimer.schedule(resourceWatcher, 0, pollingFrequency);
59 }catch(ResourceException e){
60 statusManager.add(new ErrorStatus("Error loading logging configuration file: "
61 + loggingConfigurationFile, this, e));
62 }
63 }
64 }