View Javadoc

1   package cz.cuni.amis.pogamut.base.utils.logging;
2   
3   import java.util.logging.LogRecord;
4   
5   import cz.cuni.amis.pogamut.base.agent.IAgentId;
6   
7   /**
8    * Publisher that is used by {@link AbstractAgentLogger} that passes all the logs into {@link NetworkLogManager}.
9    * 
10   * @author Pyroh
11   * @author Jimmy
12   */
13  public class NetworkLogPublisher extends LogPublisher {
14      
15      /**
16       * Who we are logging for, passed as a parameter along with log message to the {@link NetworkLogPublisher#manager} via
17       * {@link NetworkLogManager#processLog(NetworkLogEnvelope, IAgentId)}.
18       */
19      private IAgentId agent;
20  
21      /**
22       * Instantiates a log publisher that delivers the log into the {@link NetworkLogManager}.
23       * <p><p>
24       * The class is not meant to be instantiated outside {@link AgentLogger}.
25       * 
26       * @param name ID of the agent who wants to publish.
27       * @param man  The reference to NetworkLogManager which sends logs to further client sockets.
28       */
29      NetworkLogPublisher(IAgentId name) {
30      	super(name);
31          agent = name;
32          NetworkLogManager.getNetworkLogManager().addAgent(name);
33      }
34  
35      @Override
36      public void publish(LogRecord record) {
37      	NetworkLogManager.getNetworkLogManager().processLog(new NetworkLogEnvelope(record.getLoggerName(), record.getLevel(),record.getMillis(),record.getMessage()), agent);
38      }
39  
40      @Override
41      public void publish(LogRecord record, String formattedMsg) {
42      	NetworkLogManager.getNetworkLogManager().processLog(new NetworkLogEnvelope(record.getLoggerName(), record.getLevel(),record.getMillis(),record.getMessage()), agent);
43      }
44  
45      @Override
46      public void flush() {
47      }
48  
49      @Override
50      public void close() throws SecurityException {        
51      }
52  
53  }