@@ -489,7 +489,7 @@ Java properties::
489
489
+
490
490
[source,properties]
491
491
----
492
- include::example$manual/configuration/loggers.properties[]
492
+ include::example$manual/configuration/loggers.properties[tags=loggers ]
493
493
----
494
494
====
495
495
@@ -818,6 +818,107 @@ To prevent the expansion of one of the expressions above, the initial `$` must b
818
818
The same rule applies to the `name` parameter: if it contains a `${` sequence, the sequence must be escaped as `$${`.
819
819
====
820
820
821
+ .Property substitution example
822
+ =====
823
+
824
+ If your configuration file contains the following definitions:
825
+ [tabs]
826
+ ====
827
+ XML::
828
+ +
829
+ [source,xml]
830
+ ----
831
+ include::example$manual/configuration/properties-example.xml[lines=18..-1]
832
+ ----
833
+
834
+ JSON::
835
+ +
836
+ [source,json]
837
+ ----
838
+ include::example$manual/configuration/properties-example.json[]
839
+ ----
840
+
841
+ YAML::
842
+ +
843
+ [source,yaml]
844
+ ----
845
+ include::example$manual/configuration/properties-example.yaml[lines=17..-1]
846
+ ----
847
+
848
+ Java properties::
849
+ +
850
+ [source,properties]
851
+ ----
852
+ include::example$manual/configuration/properties-example.properties[lines=17..-1]
853
+ ----
854
+ ====
855
+
856
+ and the OS environment variable `FOO` has a value of `environment`, Log4j will evaluate expression as follows
857
+
858
+ [cols="1m,1m"]
859
+ |===
860
+ | Expression | Value
861
+
862
+ | $\{FOO} | foo
863
+ | $\{BAZ} | $\{BAZ}
864
+ | ${BAR:-$\{FOO}} | bar
865
+ | ${BAZ:-$\{FOO}} | foo
866
+ | ${env:FOO} | environment
867
+ | ${env:BAR} | bar
868
+ | ${env:BAZ} | $\{BAZ}
869
+ | ${env:BAR:-$\{FOO}} | bar
870
+ | ${env:BAZ:-$\{FOO}} | foo
871
+ |===
872
+ =====
873
+
874
+ [CAUTION]
875
+ =====
876
+ For security reasons, if the **expansion** of a `${...}` expression contains other expressions, these will **not** be expanded.
877
+ The only exception to this rule is the expansion of properties in the `Properties` container.
878
+
879
+ Properties defined in the `Properties` container can depend on each other.
880
+ If your configuration contains, for example:
881
+
882
+ [tabs]
883
+ ====
884
+ XML::
885
+ +
886
+ [source,xml]
887
+ ----
888
+ include::example$manual/configuration/properties-recursion.xml[lines=18..-1]
889
+ ----
890
+
891
+ JSON::
892
+ +
893
+ [source,json]
894
+ ----
895
+ include::example$manual/configuration/properties-recursion.json[]
896
+ ----
897
+
898
+ YAML::
899
+ +
900
+ [source,yaml]
901
+ ----
902
+ include::example$manual/configuration/properties-recursion.yaml[lines=17..-1]
903
+ ----
904
+
905
+ Java properties::
906
+ +
907
+ [source,properties]
908
+ ----
909
+ include::example$manual/configuration/properties-recursion.properties[lines=17..-1]
910
+ ----
911
+ ====
912
+
913
+ the `logging.dir` property will be expanded **before** the `logging.file` property and the expanded value will be substituted in `${logging.dir}/app.log`.
914
+ Therefore, the value of the `logging.file` property will be:
915
+
916
+ * `./logs/app.log` if the environment variable `APP_BASE` is not defined,
917
+ * `/var/lib/app/logs/app.log` if the environment variable `APP_BASE` has a value of `/var/lib/app`.
918
+
919
+
920
+ =====
921
+
821
922
[id=lazy-property-substitution]
822
923
==== Lazy property substitution
823
924
0 commit comments