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   import cz.cuni.amis.utils.logging.DefaultLogFormatter;
7   
8   /**
9    * Pogamut custom formatter used as default formatter for {@link LogPublisher}.
10   *
11   * @author Jimmy
12   */
13  public class LogFormatter extends DefaultLogFormatter {
14  	
15  	private IAgentId agentId;
16  
17  	public LogFormatter() {
18  		this(null, false);
19  	}
20  
21  	public LogFormatter(boolean lineEnds) {
22  		this(null, lineEnds);
23  	}
24  
25  	public LogFormatter(IAgentId agentId) {
26  		this(agentId, false);
27  	}
28  	
29  	public LogFormatter(IAgentId agentId, boolean lineEnds) {
30  		super(null, lineEnds);
31  		this.agentId = agentId;
32  		this.lineEnds = lineEnds;
33  	}
34  
35  	@Override
36  	public synchronized String format(LogRecord record) {
37  		if (agentId != null && agentId.getName() != null) {
38  			this.name = this.agentId.getName().getFlag();
39  		}
40  		return super.format(record);
41  	}
42  
43  }