001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.logging; 018 019import org.springframework.util.Assert; 020import org.springframework.util.ObjectUtils; 021 022/** 023 * Immutable class that represents the configuration of a {@link LoggingSystem}'s logger. 024 * 025 * @author Ben Hale 026 * @since 1.5.0 027 */ 028public final class LoggerConfiguration { 029 030 private final String name; 031 032 private final LogLevel configuredLevel; 033 034 private final LogLevel effectiveLevel; 035 036 /** 037 * Create a new {@link LoggerConfiguration instance}. 038 * @param name the name of the logger 039 * @param configuredLevel the configured level of the logger 040 * @param effectiveLevel the effective level of the logger 041 */ 042 public LoggerConfiguration(String name, LogLevel configuredLevel, 043 LogLevel effectiveLevel) { 044 Assert.notNull(name, "Name must not be null"); 045 Assert.notNull(effectiveLevel, "EffectiveLevel must not be null"); 046 this.name = name; 047 this.configuredLevel = configuredLevel; 048 this.effectiveLevel = effectiveLevel; 049 } 050 051 /** 052 * Returns the configured level of the logger. 053 * @return the configured level of the logger 054 */ 055 public LogLevel getConfiguredLevel() { 056 return this.configuredLevel; 057 } 058 059 /** 060 * Returns the effective level of the logger. 061 * @return the effective level of the logger 062 */ 063 public LogLevel getEffectiveLevel() { 064 return this.effectiveLevel; 065 } 066 067 /** 068 * Returns the name of the logger. 069 * @return the name of the logger 070 */ 071 public String getName() { 072 return this.name; 073 } 074 075 @Override 076 public boolean equals(Object obj) { 077 if (this == obj) { 078 return true; 079 } 080 if (obj == null) { 081 return false; 082 } 083 if (obj instanceof LoggerConfiguration) { 084 LoggerConfiguration other = (LoggerConfiguration) obj; 085 boolean rtn = true; 086 rtn = rtn && ObjectUtils.nullSafeEquals(this.name, other.name); 087 rtn = rtn && ObjectUtils.nullSafeEquals(this.configuredLevel, 088 other.configuredLevel); 089 rtn = rtn && ObjectUtils.nullSafeEquals(this.effectiveLevel, 090 other.effectiveLevel); 091 return rtn; 092 } 093 return super.equals(obj); 094 } 095 096 @Override 097 public int hashCode() { 098 final int prime = 31; 099 int result = 1; 100 result = prime * result + ObjectUtils.nullSafeHashCode(this.name); 101 result = prime * result + ObjectUtils.nullSafeHashCode(this.configuredLevel); 102 result = prime * result + ObjectUtils.nullSafeHashCode(this.effectiveLevel); 103 return result; 104 } 105 106 @Override 107 public String toString() { 108 return "LoggerConfiguration [name=" + this.name + ", configuredLevel=" 109 + this.configuredLevel + ", effectiveLevel=" + this.effectiveLevel + "]"; 110 } 111 112}