Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.template.soy.data.LoggingAdvisingAppendable;
import com.google.template.soy.data.LoggingFunctionInvocation;
import com.google.template.soy.logging.SoyLogger;
import com.google.template.soy.logging.SoyLogger.LoggingAttrs;
import java.io.IOException;
import java.util.Optional;
import java.util.function.Function;
Expand Down Expand Up @@ -173,7 +174,7 @@ public LoggingAdvisingAppendable enterLoggableElement(LogStatement statement) {
}
var enterData = logger.enter(statement);
appendDebugOutput(enterData.debugHtml());
var loggingAttrs = enterData.loggingAttrs().orElse(null);
LoggingAttrs loggingAttrs = enterData.loggingAttrs().orElse(null);
if (loggingAttrs != null && depth > 0) {
loggingAttrs = null; // we cannot render them when logonly is set, so drop them now.
}
Expand All @@ -199,7 +200,7 @@ public LoggingAdvisingAppendable exitLoggableElement() {
}

private void setLoggingAttrs(@Nullable SoyLogger.LoggingAttrs loggingAttrs) {
if (this.loggingAttrs != null) {
if (loggingAttrs != null && loggingAttrs.hasOverlappingAttributes(this.loggingAttrs)) {
googleLogger.atWarning().withStackTrace(StackSize.LARGE).log(
"a logger configured logging attrs that were not rendered onto an element. Your {velog}"
+ " command must not be wrapping an element, this is undefined behavior.");
Expand Down
7 changes: 7 additions & 0 deletions java/src/com/google/template/soy/logging/SoyLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public static Builder builder() {

abstract boolean hasAnchorAttributes();

public boolean hasOverlappingAttributes(LoggingAttrs other) {
if (other == null) {
return false;
}
return attrs().keySet().stream().anyMatch(other.attrs()::containsKey);
}

/** Writes the attributes to the output appendable. */
public void writeTo(boolean isAnchorTag, Appendable outputAppendable) throws IOException {
if (hasAnchorAttributes() && !isAnchorTag) {
Expand Down
Loading