1 package cz.cuni.amis.pogamut.base.utils.logging; 2 3 import java.io.File; 4 import java.util.Map; 5 import java.util.logging.Handler; 6 import java.util.logging.Level; 7 8 import cz.cuni.amis.pogamut.base.agent.IAgentId; 9 import cz.cuni.amis.pogamut.base.agent.jmx.IJMXEnabled; 10 import cz.cuni.amis.pogamut.base.component.IComponent; 11 12 /** 13 * Basic interface for agent's logs. 14 * @author ik 15 */ 16 public interface IAgentLogger extends IJMXAgentLogger, IJMXEnabled { 17 18 /** 19 * Returns agent name. 20 * @return 21 */ 22 public IAgentId getAgentId(); 23 24 /** 25 * Returns port where {@link NetworkLogManager} is listening. 26 * <p><p> 27 * Returns null if network logging is not enabled. 28 * 29 * @return 30 */ 31 public Integer getNetworkLoggerPort(); 32 33 /** 34 * Returns a host where {@link NetworkLogManager} is listening. 35 * <p><p> 36 * Returns null if network logging is not enabled. 37 * 38 * @return 39 */ 40 public String getNetworkLoggerHost(); 41 42 /** 43 * Returns LogCategory for specified {@link IComponent}. 44 * @param component 45 * @return 46 */ 47 public LogCategory getCategory(IComponent component); 48 49 /** 50 * Returns LogCategory for specified name. If category with 51 * this name doesn't exist new is created. 52 * @param name 53 * @return 54 */ 55 public LogCategory getCategory(String name); 56 57 /** 58 * Return immutable map of all log categories. You have to synchronize on it before iterating through its elements. 59 * <p><p> 60 * Does not contain agent logger itself. 61 * 62 * @return 63 */ 64 public Map<String, LogCategory> getCategories(); 65 66 /** 67 * Adds console handler to every existing {@link LogCategory} plus to every new one. 68 * <p><p> 69 * Shortcut for quick usage. 70 */ 71 public void addDefaultConsoleHandler(); 72 73 /** 74 * Returns {@link Handler} that provides console publishing of all logs. 75 * <p><p> 76 * May return null in case that console logging is not enabled on the logger, i.e., you have to call 77 * {@link IAgentLogger#addDefaultConsoleHandler()}. 78 * 79 * @return 80 */ 81 public Handler getDefaultConsoleHandler(); 82 83 /** 84 * Removes default console handler from every existing {@link LogCategory}. 85 */ 86 public void removeDefaultConsoleHandler(); 87 88 /** 89 * Tells whether the logger has default console handler attached. 90 * @return 91 */ 92 public boolean isDefaultConsoleHandler(); 93 94 /** 95 * Adds network handler to every existing {@link LogCategory} plus to every new one. 96 * <p><p> 97 * Enables utilization of {@link NetworkLogManager} for publishing all logs of this logger. 98 */ 99 public void addDefaultNetworkHandler(); 100 101 /** 102 * Returns {@link Handler} that provides publishing of all logs through {@link NetworkLogPublisher}. 103 * <p><p> 104 * May return null in case that network logging is not enabled on the logger, i.e., you have to call 105 * {@link IAgentLogger#addDefaultNetworkHandler()}. 106 * 107 * @return 108 */ 109 public Handler getDefaultNetworkHandler(); 110 111 /** 112 * Removes default network handler from every existing {@link LogCategory}. 113 * <p><p> 114 * Note that this method is automatically called whenever the AbstractAgent is stopped/killed. 115 */ 116 public void removeDefaultNetworkHandler(); 117 118 /** 119 * Tells whether the logger has default network handler attached. 120 * <p><p> 121 * It allows you to query whether the agent logger is outputting its logs to the {@link NetworkLogManager} 122 * or not. 123 * 124 * @return 125 */ 126 public boolean isDefaultNetworkHandler(); 127 128 /** 129 * Adds console handler to every existing {@link LogCategory} plus to every new one. 130 * <p><p> 131 * Shortcut for quick usage. 132 * 133 * @return new added handler 134 */ 135 public Handler addDefaultFileHandler(File file); 136 137 /** 138 * Adds publisher to every existing {@link LogCategory} plus to every new one. 139 * @param publisher 140 * @return newly added handler 141 */ 142 public Handler addDefaultPublisher(ILogPublisher publisher); 143 144 /** 145 * Adds handler to every existing {@link LogCategory} plus to every new one. 146 * @param handler 147 */ 148 public void addDefaultHandler(Handler handler); 149 150 /** 151 * Removes default handler from all existing {@link LogCategory}. 152 * 153 * @param handler 154 */ 155 public void removeDefaultHandler(Handler handler); 156 157 /** 158 * Adds new publisher to all categories. 159 * @param logPublisher 160 */ 161 public void addToAllCategories(ILogPublisher logPublisher); 162 163 /** 164 * Adds new handler to all categories. 165 * @param handler 166 */ 167 public void addToAllCategories(Handler handler); 168 169 /** 170 * Removes a handler from all categories. 171 * @param handler 172 */ 173 public void removeFromAllCategories(Handler handler); 174 175 /** 176 * Set level for all handlers of all categories. 177 * @param newLevel 178 */ 179 public void setLevel(Level newLevel); 180 181 }