001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2025, 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 */ 014 015package ch.qos.logback.core.boolex; 016 017/** 018 * Checks whether a named property is defined in the 019 * context (e.g. system properties, environment, or the configured 020 * property map used by the surrounding framework). 021 * 022 * <p>This condition expects a property name to be provided via 023 * {@link #setKey(String)}. When {@link #evaluate()} is called it returns 024 * {@code true} if the named property is defined and {@code false} 025 * otherwise. 026 */ 027public class IsPropertyDefinedCondition extends PropertyConditionBase { 028 029 /** 030 * The property name to check for definition. Must be set before 031 * starting this evaluator. 032 */ 033 String key; 034 035 /** 036 * Start the evaluator. If the required {@link #key} is not set an 037 * error is reported and startup is aborted. 038 */ 039 public void start() { 040 if (key == null) { 041 addError("In IsPropertyDefinedEvaluator 'key' parameter cannot be null"); 042 return; 043 } 044 super.start(); 045 } 046 047 /** 048 * Return the configured property name (key) that this evaluator will 049 * test for definition. 050 * 051 * @return the property key, or {@code null} if not set 052 */ 053 public String getKey() { 054 return key; 055 } 056 057 /** 058 * Set the property name (key) to be checked by this evaluator. 059 * 060 * @param key the property name to check; must not be {@code null} 061 */ 062 public void setKey(String key) { 063 this.key = key; 064 } 065 066 067 /** 068 * Evaluate whether the configured property is defined. 069 * 070 * @return {@code true} if the property named by {@link #key} is 071 * defined, {@code false} otherwise 072 */ 073 @Override 074 public boolean evaluate() { 075 return isDefined(key); 076 } 077}