使用指定类初始化日志对象,在日志输出的时候,可以打印出日志信息所在类 如:Logger logger = LoggerFactory.getLogger(com.Book.class); logger.debug("日志信息"); 将会打印出: com.Book : 日志信息 VirtualNetworkFilter类中LoggerFactory的用法 protected static Logger log = LoggerFactory.getLogger(VirtualNetworkFilter.class); protected void addGateway(String guid, Integer ip) { if (ip.intValue() != 0) { if (log.isDebugEnabled()) log.debug("Adding {} as gateway for GUID {}", IPv4.fromIPv4Address(ip), guid); guidToGateway.put(guid, ip); if (vNetsByGuid.get(guid) != null) vNetsByGuid.get(guid).setGateway(IPv4.fromIPv4Address(ip)); if (gatewayToGuid.containsKey(ip)) { Set<String> gSet = gatewayToGuid.get(ip); gSet.add(guid); } else { Set<String> gSet = Collections.synchronizedSet(new HashSet<String>()); gSet.add(guid); gatewayToGuid.put(ip, gSet); } } } @Override public void createNetwork(String guid, String network, Integer gateway) { if (log.isDebugEnabled()) { String gw = null; try { gw = IPv4.fromIPv4Address(gateway); } catch (Exception e) { // fail silently } log.debug("Creating network {} with ID {} and gateway {}", new Object[] {network, guid, gw}); } if (!nameToGuid.isEmpty()) { // We have to iterate all the networks to handle name/gateway changes for (Entry<String, String> entry : nameToGuid.entrySet()) { if (entry.getValue().equals(guid)) { nameToGuid.remove(entry.getKey()); break; } } } if(network != null) nameToGuid.put(network, guid); if (vNetsByGuid.containsKey(guid)) vNetsByGuid.get(guid).setName(network); //network already exists, just updating name else vNetsByGuid.put(guid, new VirtualNetwork(network, guid)); //new network // If they don't specify a new gateway the old one will be preserved if ((gateway != null) && (gateway != 0)) { addGateway(guid, gateway); if(vNetsByGuid.get(guid)!=null) vNetsByGuid.get(guid).setGateway(IPv4.fromIPv4Address(gateway)); } }
LoggerFactory类
最新推荐文章于 2024-01-31 10:38:12 发布