Skip to content
Permalink
Browse files

use the jitsi-utils logger (#186)

* use new logger in agent

* use new logger in component, componentsocket, icemediastream, mergingdatagramsocket

* use new logger in localcandidate

* use new logger in checklist

* use new logger in defaultnominator

* use new logger in connectivitycheckclient, connectivitycheckserver

* fix typo, allow taking in a parent logger

* use jitsi-utils

* clean up uses of old logger and remove it
  • Loading branch information...
bbaldino committed Sep 19, 2019
1 parent 43fa07d commit e854e4efaf5dbb82e45028fceafe9d76ca93cb2a
21 pom.xml
@@ -35,6 +35,12 @@
<artifactId>weupnp</artifactId>
<version>0.1.4</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-utils</artifactId>
<version>1.0-12-gcdf6537</version>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
@@ -249,4 +255,19 @@
</build>
</profile>
</profiles>

<repositories>
<repository>
<id>jitsi-maven-repository-releases</id>
<layout>default</layout>
<name>Jitsi Maven Repository (Releases)</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://github.com/jitsi/jitsi-maven-repository/raw/master/releases/</url>
</repository>
</repositories>
</project>
@@ -31,7 +31,9 @@
import org.ice4j.ice.harvest.*;
import org.ice4j.stack.*;
import org.ice4j.util.*;
import org.ice4j.util.Logger; // Disambiguation.
import org.jitsi.utils.collections.*;
import org.jitsi.utils.logging2.*;
import org.jitsi.utils.logging2.Logger;

/**
* An <tt>Agent</tt> could be described as the main class (i.e. the chef
@@ -343,41 +345,37 @@ public void run()
*/
public Agent()
{
this(Level.INFO, null);
this(null, null);
}

/**
* Creates an empty <tt>Agent</tt> with no streams, and no address.
* @param ufragPrefix an optional prefix to the generated local ICE username
* fragment.
*/
public Agent(String ufragPrefix)
{
this(Level.INFO, ufragPrefix);
}

/**
* Creates an empty <tt>Agent</tt> with no streams, and no address.
* @param loggingLevel the logging level to be used by the agent and all of
* its components.
*/
public Agent(Level loggingLevel)
public Agent(Logger parentLogger)
{
this(loggingLevel, null);
this(null, parentLogger);
}

/**
* Creates an empty <tt>Agent</tt> with no streams, and no address.
* @param loggingLevel the logging level to be used by the agent and all of
* its components.
* @param ufragPrefix an optional prefix to the generated local ICE username
* fragment.
*/
public Agent(Level loggingLevel, String ufragPrefix)
public Agent(String ufragPrefix, Logger parentLogger)
{
logger = new Logger(classLogger, loggingLevel);
SecureRandom random = new SecureRandom();

String ufrag = ufragPrefix == null ? "" : ufragPrefix;
ufrag += new BigInteger(24, random).toString(32);
ufrag += BigInteger.valueOf(System.currentTimeMillis()).toString(32);
ufrag = ensureIceAttributeLength(ufrag, /* min */ 4, /* max */ 256);
this.ufrag = ufrag;
if (parentLogger != null)
{
logger = parentLogger.createChildLogger(this.getClass().getName(), JMap.of("ufrag", this.ufrag));
}
else
{
logger = new LoggerImpl(Agent.class.getName(), new LogContext(JMap.of("ufrag", this.ufrag)));
}

connCheckServer = new ConnectivityCheckServer(this);
connCheckClient = new ConnectivityCheckClient(
this, agentTasksScheduler, agentTasksExecutor);
@@ -389,11 +387,6 @@ public Agent(Level loggingLevel, String ufragPrefix)
if (StackProperties.getString(StackProperties.SOFTWARE) == null)
System.setProperty(StackProperties.SOFTWARE, "ice4j.org");

String ufrag = ufragPrefix == null ? "" : ufragPrefix;
ufrag += new BigInteger(24, random).toString(32);
ufrag += BigInteger.valueOf(System.currentTimeMillis()).toString(32);
ufrag = ensureIceAttributeLength(ufrag, /* min */ 4, /* max */ 256);
this.ufrag = ufrag;

password
= ensureIceAttributeLength(
@@ -409,10 +402,7 @@ public Agent(Level loggingLevel, String ufragPrefix)
addCandidateHarvester(harvester);
}

if (logger.isLoggable(Level.FINE))
{
logger.fine("Created a new Agent, ufrag=" + ufrag);
}
logger.debug(() -> "Created a new Agent");
}

/**
@@ -434,7 +424,7 @@ public void setTieBreaker(long tieBreakerInput)
*/
public IceMediaStream createMediaStream(String mediaStreamName)
{
logger.debug("Create media stream for " + mediaStreamName);
logger.debug(() -> "Create media stream for " + mediaStreamName);

IceMediaStream mediaStream
= new IceMediaStream(Agent.this, mediaStreamName);
@@ -679,7 +669,7 @@ private void gatherCandidates( Component component,
else
{
if (hostHarvesters.isEmpty())
logger.warning("No host harvesters available!");
logger.warn("No host harvesters available!");
}

for (CandidateHarvester harvester : hostHarvesters)
@@ -688,7 +678,7 @@ private void gatherCandidates( Component component,
}

if (component.getLocalCandidateCount() == 0)
logger.warning("Failed to gather any host candidates!");
logger.warn("Failed to gather any host candidates!");

//in case we are not trickling, apply other harvesters here
if (!isTrickling())
@@ -697,7 +687,7 @@ private void gatherCandidates( Component component,
harvesters.harvest(component);
}

logger.fine("Candidate count in first harvest: " +
logger.debug(() -> "Candidate count in first harvest: " +
component.getLocalCandidateCount());

// Emil: Because of trickle, we now assign foundations, compute
@@ -733,7 +723,7 @@ public void startCandidateTrickle(TrickleCallback trickleCallback)

if (harvestingStarted)
{
logger.warning(
logger.warn(
"Hmmm ... why are you harvesting twice? You shouldn't be!");
}

@@ -1102,7 +1092,7 @@ public String generateLocalUserName(String media)
if (stream == null)
{
ret = null;
logger.warning(
logger.warn(
"Agent contains no IceMediaStream with name " + media
+ "!");
}
@@ -1113,7 +1103,7 @@ public String generateLocalUserName(String media)
if (remoteUfrag == null)
{
ret = null;
logger.warning(
logger.warn(
"Remote ufrag of IceMediaStream with name " + media
+ " is null!");
}
@@ -1660,7 +1650,7 @@ protected void incomingCheckReceived(TransportAddress remoteAddress,
CandidatePair triggeredPair
= createCandidatePair(localCandidate, remoteCandidate);

logger.fine("set use-candidate " + useCandidate + " for pair " +
logger.debug(() -> "set use-candidate " + useCandidate + " for pair " +
triggeredPair.toShortString());
if (useCandidate)
{
@@ -1671,7 +1661,7 @@ protected void incomingCheckReceived(TransportAddress remoteAddress,
{
if (state == IceProcessingState.WAITING)
{
logger.fine("Receive STUN checks before our ICE has started");
logger.debug(() -> "Receive STUN checks before our ICE has started");
//we are not started yet so we'd better wait until we get the
//remote candidates in case we are holding to a new PR one.
this.preDiscoveredPairsQueue.add(triggeredPair);
@@ -1682,12 +1672,8 @@ else if (state == IceProcessingState.FAILED)
}
else //Running, Connected or Terminated.
{
if (logger.isLoggable(Level.FINE))
{
logger.debug("Received check from "
+ triggeredPair.toShortString() + " triggered a check. "
+ "Local ufrag " + getLocalUfrag());
}
logger.debug(() -> "Received check from "
+ triggeredPair.toShortString() + " triggered a check.");

// We have been started, and have not failed (yet). If this is
// a new pair, handle it (even if we have already completed).
@@ -1735,7 +1721,7 @@ private void triggerCheck(CandidatePair triggerPair)
//7.2.1.5. Updating the Nominated Flag
if (!isControlling() && useCand)
{
logger.fine("update nominated flag");
logger.debug(() -> "update nominated flag");
// If the Binding request received by the agent had the
// USE-CANDIDATE attribute set, and the agent is in the
// controlled role, the agent looks at the state of the
@@ -1943,7 +1929,7 @@ else if (checkListState == CheckListState.COMPLETED)
if (!atLeastOneListSucceeded)
{
//all lists ended but none succeeded. No love today ;(
if (logger.isLoggable(Level.INFO))
if (logger.isInfoEnabled())
{
if (connCheckClient.isAlive()
|| connCheckServer.isAlive())
@@ -2344,7 +2330,7 @@ protected void finalize()
*/
public void free()
{
logger.fine("Free ICE agent");
logger.debug(() -> "Free ICE agent");

shutdown = true;

@@ -2380,17 +2366,17 @@ public void free()
// Free its IceMediaStreams, Components and Candidates.
boolean interrupted = false;

logger.fine("remove streams");
logger.debug(() -> "remove streams");
for (IceMediaStream stream : getStreams())
{
try
{
removeStream(stream);
logger.fine("remove stream " + stream.getName());
logger.debug("remove stream " + stream.getName());
}
catch (Throwable t)
{
logger.fine(
logger.debug(() ->
"remove stream " + stream.getName() + " failed: " + t);
if (t instanceof InterruptedException)
interrupted = true;
@@ -2403,7 +2389,7 @@ else if (t instanceof ThreadDeath)

getStunStack().shutDown();

logger.fine("ICE agent freed");
logger.debug(() -> "ICE agent freed");
}

/**
@@ -2738,7 +2724,7 @@ protected void run()
}
catch (Exception e)
{
logger.log(Level.WARNING, "Error while sending keep alive", e);
logger.warn("Error while sending keep alive", e);
}
}

@@ -17,11 +17,11 @@
*/
package org.ice4j.ice;

import org.jitsi.utils.logging2.*;

import java.beans.*;
import java.util.*;

import org.ice4j.util.Logger;

/**
* A check list is a list of <tt>CandidatePair</tt>s with a state (i.e. a
* <tt>CheckListState</tt>). The pairs in a check list are those that an ICE
@@ -35,15 +35,6 @@
public class CheckList
extends Vector<CandidatePair>
{
/**
* The class logger.
* Note that this shouldn't be used directly by instances of
* {@link CheckList}, because it doesn't take into account the per-instance
* log level. Instances should use {@link #logger} instead.
*/
private static final java.util.logging.Logger classLogger
= java.util.logging.Logger.getLogger(CheckList.class.getName());

/**
* A dummy serialization id.
*/
@@ -107,8 +98,7 @@
protected CheckList(IceMediaStream parentStream)
{
this.parentStream = parentStream;
logger
= new Logger(classLogger, parentStream.getParentAgent().getLogger());
logger = parentStream.getLogger().createChildLogger(this.getClass().getName());
}

/**

0 comments on commit e854e4e

Please sign in to comment.
You can’t perform that action at this time.