Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the jitsi-utils logger #186

Merged
merged 9 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
96 changes: 41 additions & 55 deletions src/main/java/org/ice4j/ice/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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");
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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!");
}

Expand Down Expand Up @@ -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
+ "!");
}
Expand All @@ -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!");
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -2344,7 +2330,7 @@ protected void finalize()
*/
public void free()
{
logger.fine("Free ICE agent");
logger.debug(() -> "Free ICE agent");

shutdown = true;

Expand Down Expand Up @@ -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;
Expand All @@ -2403,7 +2389,7 @@ else if (t instanceof ThreadDeath)

getStunStack().shutDown();

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

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/main/java/org/ice4j/ice/CheckList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -107,8 +98,7 @@ public class CheckList
protected CheckList(IceMediaStream parentStream)
{
this.parentStream = parentStream;
logger
= new Logger(classLogger, parentStream.getParentAgent().getLogger());
logger = parentStream.getLogger().createChildLogger(this.getClass().getName());
}

/**
Expand Down
Loading