1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  import java.io.Serializable;
17  import java.util.Map;
18  
19  import ch.qos.logback.classic.LoggerContext;
20  
21  /**
22   * LoggerContextVO offers a restricted view of LoggerContext intended to be
23   * exposed by LoggingEvent to remote systems. This restricted view is optimized
24   * for serialization.
25   * 
26   * <p>
27   * Some of the LoggerContext or Logger attributes MUST not survive
28   * serialization, e.g. appenders, level values etc., as these attributes may have
29   * other values on the remote platform. LoggerContextVO class exposes the
30   * minimal and relevant attributes to the remote host, instead of having to deal
31   * with an incomplete LoggerContext with many null references.
32   * 
33   * @author Ceki G&uuml;lc&uuml;
34   * @author S&eacute;bastien Pennec
35   */
36  public class LoggerContextVO implements Serializable {
37  
38      private static final long serialVersionUID = 5488023392483144387L;
39  
40      protected String name;
41      protected Map<String, String> propertyMap;
42      protected long birthTime;
43  
44      /**
45       * No-arg constructor for serialization frameworks only.
46       *
47       * @since 1.5.21
48       */
49      public LoggerContextVO() {}
50  
51      public LoggerContextVO(LoggerContext lc) {
52          this.name = lc.getName();
53          this.propertyMap = lc.getCopyOfPropertyMap();
54          this.birthTime = lc.getBirthTime();
55      }
56  
57      public LoggerContextVO(String name, Map<String, String> propertyMap, long birthTime) {
58          this.name = name;
59          this.propertyMap = propertyMap;
60          this.birthTime = birthTime;
61      }
62  
63      public String getName() {
64          return name;
65      }
66  
67      public Map<String, String> getPropertyMap() {
68          return propertyMap;
69      }
70  
71      public long getBirthTime() {
72          return birthTime;
73      }
74  
75      @Override
76      public String toString() {
77          return "LoggerContextVO{" + "name='" + name + '\'' + ", propertyMap=" + propertyMap + ", birthTime=" + birthTime
78                  + '}';
79      }
80  
81      @Override
82      public boolean equals(Object o) {
83          if (this == o)
84              return true;
85          if (!(o instanceof LoggerContextVO))
86              return false;
87  
88          LoggerContextVO that = (LoggerContextVO) o;
89  
90          if (birthTime != that.birthTime)
91              return false;
92          if (name != null ? !name.equals(that.name) : that.name != null)
93              return false;
94          if (propertyMap != null ? !propertyMap.equals(that.propertyMap) : that.propertyMap != null)
95              return false;
96  
97          return true;
98      }
99  
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 }