mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: multiple loggers allowed
parent
13efc0594a
commit
9bcce47e9c
|
@ -20,6 +20,7 @@ package io.openvidu.server;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -137,7 +138,7 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public CallDetailRecord cdr() {
|
public CallDetailRecord cdr() {
|
||||||
return new CallDetailRecord(new CDRLoggerFile());
|
return new CallDetailRecord(Arrays.asList(new CDRLoggerFile()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -18,7 +18,9 @@
|
||||||
package io.openvidu.server.cdr;
|
package io.openvidu.server.cdr;
|
||||||
|
|
||||||
public interface CDRLogger {
|
public interface CDRLogger {
|
||||||
|
|
||||||
public void log(CDREvent event);
|
public void log(CDREvent event);
|
||||||
|
|
||||||
|
public boolean canBeDisabled();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,9 @@ public class CDRLoggerFile implements CDRLogger {
|
||||||
log.info("{}", event);
|
log.info("{}", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeDisabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package io.openvidu.server.cdr;
|
package io.openvidu.server.cdr;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -84,7 +85,7 @@ public class CallDetailRecord {
|
||||||
@Autowired
|
@Autowired
|
||||||
protected OpenviduConfig openviduConfig;
|
protected OpenviduConfig openviduConfig;
|
||||||
|
|
||||||
private CDRLogger logger;
|
private Collection<CDRLogger> loggers;
|
||||||
|
|
||||||
private Map<String, CDREventSession> sessions = new ConcurrentHashMap<>();
|
private Map<String, CDREventSession> sessions = new ConcurrentHashMap<>();
|
||||||
private Map<String, CDREventParticipant> participants = new ConcurrentHashMap<>();
|
private Map<String, CDREventParticipant> participants = new ConcurrentHashMap<>();
|
||||||
|
@ -92,34 +93,30 @@ public class CallDetailRecord {
|
||||||
private Map<String, Set<CDREventWebrtcConnection>> subscriptions = new ConcurrentHashMap<>();
|
private Map<String, Set<CDREventWebrtcConnection>> subscriptions = new ConcurrentHashMap<>();
|
||||||
private Map<String, CDREventRecording> recordings = new ConcurrentHashMap<>();
|
private Map<String, CDREventRecording> recordings = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public CallDetailRecord(CDRLogger logger) {
|
public CallDetailRecord(Collection<CDRLogger> loggers) {
|
||||||
this.logger = logger;
|
this.loggers = loggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordSessionCreated(Session session) {
|
public void recordSessionCreated(Session session) {
|
||||||
CDREventSession e = new CDREventSession(session);
|
CDREventSession e = new CDREventSession(session);
|
||||||
this.sessions.put(session.getSessionId(), e);
|
this.sessions.put(session.getSessionId(), e);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(e);
|
||||||
this.logger.log(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordSessionDestroyed(String sessionId, String reason) {
|
public void recordSessionDestroyed(String sessionId, String reason) {
|
||||||
CDREvent e = this.sessions.remove(sessionId);
|
CDREvent e = this.sessions.remove(sessionId);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(new CDREventSession(e, RecordingManager.finalReason(reason)));
|
||||||
this.logger.log(new CDREventSession(e, RecordingManager.finalReason(reason)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordParticipantJoined(Participant participant, String sessionId) {
|
public void recordParticipantJoined(Participant participant, String sessionId) {
|
||||||
CDREventParticipant e = new CDREventParticipant(sessionId, participant);
|
CDREventParticipant e = new CDREventParticipant(sessionId, participant);
|
||||||
this.participants.put(participant.getParticipantPublicId(), e);
|
this.participants.put(participant.getParticipantPublicId(), e);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(e);
|
||||||
this.logger.log(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordParticipantLeft(Participant participant, String sessionId, String reason) {
|
public void recordParticipantLeft(Participant participant, String sessionId, String reason) {
|
||||||
CDREvent e = this.participants.remove(participant.getParticipantPublicId());
|
CDREvent e = this.participants.remove(participant.getParticipantPublicId());
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(new CDREventParticipant(e, reason));
|
||||||
this.logger.log(new CDREventParticipant(e, reason));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordNewPublisher(Participant participant, String sessionId, MediaOptions mediaOptions,
|
public void recordNewPublisher(Participant participant, String sessionId, MediaOptions mediaOptions,
|
||||||
|
@ -127,16 +124,14 @@ public class CallDetailRecord {
|
||||||
CDREventWebrtcConnection publisher = new CDREventWebrtcConnection(sessionId,
|
CDREventWebrtcConnection publisher = new CDREventWebrtcConnection(sessionId,
|
||||||
participant.getParticipantPublicId(), mediaOptions, null, timestamp);
|
participant.getParticipantPublicId(), mediaOptions, null, timestamp);
|
||||||
this.publications.put(participant.getParticipantPublicId(), publisher);
|
this.publications.put(participant.getParticipantPublicId(), publisher);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(publisher);
|
||||||
this.logger.log(publisher);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stopPublisher(String participantPublicId, String reason) {
|
public boolean stopPublisher(String participantPublicId, String reason) {
|
||||||
CDREventWebrtcConnection publisher = this.publications.remove(participantPublicId);
|
CDREventWebrtcConnection publisher = this.publications.remove(participantPublicId);
|
||||||
if (publisher != null) {
|
if (publisher != null) {
|
||||||
publisher = new CDREventWebrtcConnection(publisher, reason);
|
publisher = new CDREventWebrtcConnection(publisher, reason);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(publisher);
|
||||||
this.logger.log(publisher);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -148,8 +143,7 @@ public class CallDetailRecord {
|
||||||
participant.getParticipantPublicId(), publisher.mediaOptions, senderPublicId, timestamp);
|
participant.getParticipantPublicId(), publisher.mediaOptions, senderPublicId, timestamp);
|
||||||
this.subscriptions.putIfAbsent(participant.getParticipantPublicId(), new ConcurrentSkipListSet<>());
|
this.subscriptions.putIfAbsent(participant.getParticipantPublicId(), new ConcurrentSkipListSet<>());
|
||||||
this.subscriptions.get(participant.getParticipantPublicId()).add(subscriber);
|
this.subscriptions.get(participant.getParticipantPublicId()).add(subscriber);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(subscriber);
|
||||||
this.logger.log(subscriber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stopSubscriber(String participantPublicId, String senderPublicId, String reason) {
|
public boolean stopSubscriber(String participantPublicId, String senderPublicId, String reason) {
|
||||||
|
@ -161,8 +155,7 @@ public class CallDetailRecord {
|
||||||
if (senderPublicId.equals(subscription.receivingFrom)) {
|
if (senderPublicId.equals(subscription.receivingFrom)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
subscription = new CDREventWebrtcConnection(subscription, reason);
|
subscription = new CDREventWebrtcConnection(subscription, reason);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(subscription);
|
||||||
this.logger.log(subscription);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,14 +166,20 @@ public class CallDetailRecord {
|
||||||
public void recordRecordingStarted(String sessionId, Recording recording) {
|
public void recordRecordingStarted(String sessionId, Recording recording) {
|
||||||
CDREventRecording recordingStartedEvent = new CDREventRecording(sessionId, recording);
|
CDREventRecording recordingStartedEvent = new CDREventRecording(sessionId, recording);
|
||||||
this.recordings.putIfAbsent(recording.getId(), recordingStartedEvent);
|
this.recordings.putIfAbsent(recording.getId(), recordingStartedEvent);
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(new CDREventRecording(sessionId, recording));
|
||||||
this.logger.log(new CDREventRecording(sessionId, recording));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordRecordingStopped(String sessionId, Recording recording, String reason) {
|
public void recordRecordingStopped(String sessionId, Recording recording, String reason) {
|
||||||
CDREventRecording recordingStartedEvent = this.recordings.remove(recording.getId());
|
CDREventRecording recordingStartedEvent = this.recordings.remove(recording.getId());
|
||||||
if (openviduConfig.isCdrEnabled())
|
this.log(new CDREventRecording(recordingStartedEvent, RecordingManager.finalReason(reason)));
|
||||||
this.logger.log(new CDREventRecording(recordingStartedEvent, RecordingManager.finalReason(reason)));
|
}
|
||||||
|
|
||||||
|
private void log(CDREvent event) {
|
||||||
|
this.loggers.forEach(logger -> {
|
||||||
|
if (openviduConfig.isCdrEnabled() || !logger.canBeDisabled()) {
|
||||||
|
logger.log(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue