001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.spi; 015 016import java.io.Serializable; 017import java.util.Map; 018 019import ch.qos.logback.classic.LoggerContext; 020 021/** 022 * LoggerContextVO offers a restricted view of LoggerContext intended to be 023 * exposed by LoggingEvent to remote systems. This restricted view is optimized 024 * for serialization. 025 * 026 * <p> 027 * Some of the LoggerContext or Logger attributes MUST not survive 028 * serialization, e.g. appenders, level values etc., as these attributes may have 029 * other values on the remote platform. LoggerContextVO class exposes the 030 * minimal and relevant attributes to the remote host, instead of having to deal 031 * with an incomplete LoggerContext with many null references. 032 * 033 * @author Ceki Gülcü 034 * @author Sébastien Pennec 035 */ 036public class LoggerContextVO implements Serializable { 037 038 private static final long serialVersionUID = 5488023392483144387L; 039 040 protected String name; 041 protected Map<String, String> propertyMap; 042 protected long birthTime; 043 044 public LoggerContextVO(LoggerContext lc) { 045 this.name = lc.getName(); 046 this.propertyMap = lc.getCopyOfPropertyMap(); 047 this.birthTime = lc.getBirthTime(); 048 } 049 050 public LoggerContextVO(String name, Map<String, String> propertyMap, long birthTime) { 051 this.name = name; 052 this.propertyMap = propertyMap; 053 this.birthTime = birthTime; 054 } 055 056 public String getName() { 057 return name; 058 } 059 060 public Map<String, String> getPropertyMap() { 061 return propertyMap; 062 } 063 064 public long getBirthTime() { 065 return birthTime; 066 } 067 068 @Override 069 public String toString() { 070 return "LoggerContextVO{" + "name='" + name + '\'' + ", propertyMap=" + propertyMap + ", birthTime=" + birthTime 071 + '}'; 072 } 073 074 @Override 075 public boolean equals(Object o) { 076 if (this == o) 077 return true; 078 if (!(o instanceof LoggerContextVO)) 079 return false; 080 081 LoggerContextVO that = (LoggerContextVO) o; 082 083 if (birthTime != that.birthTime) 084 return false; 085 if (name != null ? !name.equals(that.name) : that.name != null) 086 return false; 087 if (propertyMap != null ? !propertyMap.equals(that.propertyMap) : that.propertyMap != null) 088 return false; 089 090 return true; 091 } 092 093 @Override 094 public int hashCode() { 095 int result = name != null ? name.hashCode() : 0; 096 result = 31 * result + (propertyMap != null ? propertyMap.hashCode() : 0); 097 result = 31 * result + (int) (birthTime ^ (birthTime >>> 32)); 098 099 return result; 100 } 101}