001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2026, 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 v2.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&uuml;lc&uuml;
034 * @author S&eacute;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    /**
045     * No-arg constructor for serialization frameworks only.
046     *
047     * @since 1.5.21
048     */
049    public LoggerContextVO() {}
050
051    public LoggerContextVO(LoggerContext lc) {
052        this.name = lc.getName();
053        this.propertyMap = lc.getCopyOfPropertyMap();
054        this.birthTime = lc.getBirthTime();
055    }
056
057    public LoggerContextVO(String name, Map<String, String> propertyMap, long birthTime) {
058        this.name = name;
059        this.propertyMap = propertyMap;
060        this.birthTime = birthTime;
061    }
062
063    public String getName() {
064        return name;
065    }
066
067    public Map<String, String> getPropertyMap() {
068        return propertyMap;
069    }
070
071    public long getBirthTime() {
072        return birthTime;
073    }
074
075    @Override
076    public String toString() {
077        return "LoggerContextVO{" + "name='" + name + '\'' + ", propertyMap=" + propertyMap + ", birthTime=" + birthTime
078                + '}';
079    }
080
081    @Override
082    public boolean equals(Object o) {
083        if (this == o)
084            return true;
085        if (!(o instanceof LoggerContextVO))
086            return false;
087
088        LoggerContextVO that = (LoggerContextVO) o;
089
090        if (birthTime != that.birthTime)
091            return false;
092        if (name != null ? !name.equals(that.name) : that.name != null)
093            return false;
094        if (propertyMap != null ? !propertyMap.equals(that.propertyMap) : that.propertyMap != null)
095            return false;
096
097        return true;
098    }
099
100    @Override
101    public int hashCode() {
102        int result = name != null ? name.hashCode() : 0;
103        result = 31 * result + (propertyMap != null ? propertyMap.hashCode() : 0);
104        result = 31 * result + (int) (birthTime ^ (birthTime >>> 32));
105
106        return result;
107    }
108}