Skip to content

Commit 95b7c3a

Browse files
Soy Authorscopybara-github
authored andcommitted
Relax check to not throw error for non-overlapping logging attributes.
PiperOrigin-RevId: 910040392
1 parent 75865a0 commit 95b7c3a

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

java/src/com/google/template/soy/jbcsrc/api/OutputAppendable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.template.soy.data.LoggingAdvisingAppendable;
2828
import com.google.template.soy.data.LoggingFunctionInvocation;
2929
import com.google.template.soy.logging.SoyLogger;
30+
import com.google.template.soy.logging.SoyLogger.LoggingAttrs;
3031
import java.io.IOException;
3132
import java.util.Optional;
3233
import java.util.function.Function;
@@ -173,7 +174,7 @@ public LoggingAdvisingAppendable enterLoggableElement(LogStatement statement) {
173174
}
174175
var enterData = logger.enter(statement);
175176
appendDebugOutput(enterData.debugHtml());
176-
var loggingAttrs = enterData.loggingAttrs().orElse(null);
177+
LoggingAttrs loggingAttrs = enterData.loggingAttrs().orElse(null);
177178
if (loggingAttrs != null && depth > 0) {
178179
loggingAttrs = null; // we cannot render them when logonly is set, so drop them now.
179180
}
@@ -199,7 +200,7 @@ public LoggingAdvisingAppendable exitLoggableElement() {
199200
}
200201

201202
private void setLoggingAttrs(@Nullable SoyLogger.LoggingAttrs loggingAttrs) {
202-
if (this.loggingAttrs != null) {
203+
if (loggingAttrs != null && loggingAttrs.hasOverlappingAttributes(this.loggingAttrs)) {
203204
googleLogger.atWarning().withStackTrace(StackSize.LARGE).log(
204205
"a logger configured logging attrs that were not rendered onto an element. Your {velog}"
205206
+ " command must not be wrapping an element, this is undefined behavior.");

java/src/com/google/template/soy/logging/SoyLogger.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public static Builder builder() {
5555

5656
abstract boolean hasAnchorAttributes();
5757

58+
public boolean hasOverlappingAttributes(LoggingAttrs other) {
59+
if (other == null) {
60+
return false;
61+
}
62+
return attrs().keySet().stream().anyMatch(other.attrs()::containsKey);
63+
}
64+
5865
/** Writes the attributes to the output appendable. */
5966
public void writeTo(boolean isAnchorTag, Appendable outputAppendable) throws IOException {
6067
if (hasAnchorAttributes() && !isAnchorTag) {

0 commit comments

Comments
 (0)