Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to fetch all logged warning programmatically, see #76 #489

Merged
merged 2 commits into from
Jul 11, 2020
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 @@ -26,6 +26,7 @@
import java.util.logging.Level;

import com.openhtmltopdf.css.sheet.FontFaceRule;
import com.openhtmltopdf.util.LogMessageId;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -99,8 +100,8 @@ public void setDocumentContext(SharedContext context, NamespaceHandler nsh, Docu
AttributeResolver attRes = new StandardAttributeResolver(_nsh, _uac, ui);

List<StylesheetInfo> infos = getStylesheets();
XRLog.match("media = " + _context.getMedia());

XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.MATCH_MEDIA_IS, _context.getMedia());

_matcher = new com.openhtmltopdf.css.newmatch.Matcher(
new DOMTreeResolver(),
Expand Down Expand Up @@ -128,7 +129,7 @@ private List<Stylesheet> readAndParseAll(List<StylesheetInfo> infos, String medi

result.add(sheet);
} else {
XRLog.load(Level.WARNING, "Unable to load CSS from "+info.getUri());
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.LOAD_UNABLE_TO_LOAD_CSS_FROM_URI, info.getUri());
}
}
}
Expand Down Expand Up @@ -212,10 +213,9 @@ public void flushStyleSheets() {
info.setOrigin(StylesheetInfo.AUTHOR);
if (_stylesheetFactory.containsStylesheet(uri)) {
_stylesheetFactory.removeCachedStylesheet(uri);
XRLog.cssParse("Removing stylesheet '" + uri + "' from cache by request.");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.CSS_PARSE_REMOVING_STYLESHEET_URI_FROM_CACHE_BY_REQUEST, uri);
} else {
XRLog.cssParse("Requested removing stylesheet '" + uri + "', but it's not in cache.");

XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.CSS_PARSE_REQUESTED_REMOVING_STYLESHEET_URI_NOT_IN_CACHE, uri);
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ private List<StylesheetInfo> getStylesheets() {
// TODO: here we should also get user stylesheet from userAgent

long el = System.currentTimeMillis() - st;
XRLog.load("TIME: parse stylesheets " + el + "ms");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.LOAD_PARSE_STYLESHEETS_TIME, el);

return infos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.openhtmltopdf.css.sheet.StylesheetInfo;
import com.openhtmltopdf.extend.UserAgentCallback;
import com.openhtmltopdf.resource.CSSResource;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;

/**
Expand Down Expand Up @@ -64,18 +65,16 @@ protected boolean removeEldestEntry(java.util.Map.Entry<String, Stylesheet> elde

public StylesheetFactoryImpl(UserAgentCallback userAgentCallback) {
_userAgentCallback = userAgentCallback;
_cssParser = new CSSParser(new CSSErrorHandler() {
public void error(String uri, String message) {
XRLog.cssParse(Level.WARNING, "(" + uri + ") " + message);
}
_cssParser = new CSSParser((uri, message) -> {
XRLog.log(Level.WARNING, LogMessageId.LogMessageId2Param.CSS_PARSE_GENERIC_MESSAGE, uri, message);
});
}

public Stylesheet parse(Reader reader, StylesheetInfo info) {
try {
return _cssParser.parseStylesheet(info.getUri(), info.getOrigin(), reader);
} catch (IOException e) {
XRLog.cssParse(Level.WARNING, "Couldn't parse stylesheet at URI " + info.getUri() + ": " + e.getMessage(), e);
XRLog.log(Level.WARNING, LogMessageId.LogMessageId2Param.CSS_PARSE_COULDNT_PARSE_STYLESHEET_AT_URI, info.getUri(), e.getMessage(), e);
return new Stylesheet(info.getUri(), info.getOrigin());
}
}
Expand Down Expand Up @@ -170,7 +169,7 @@ public void flushCachedStylesheets() {
*/
//TODO: this looks a bit odd
public Stylesheet getStylesheet(StylesheetInfo info) {
XRLog.load("Requesting stylesheet: " + info.getUri());
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.LOAD_REQUESTING_STYLESHEET_AT_URI, info.getUri());

Stylesheet s = getCachedStylesheet(info.getUri());
if (s == null && !containsStylesheet(info.getUri())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;

import com.openhtmltopdf.css.parser.CSSErrorHandler;
import com.openhtmltopdf.css.parser.CSSParser;
import com.openhtmltopdf.css.parser.PropertyValue;
Expand All @@ -42,6 +44,7 @@
import com.openhtmltopdf.css.sheet.StylesheetInfo;
import com.openhtmltopdf.css.style.FSDerivedValue;
import com.openhtmltopdf.css.style.derived.DerivedValueFactory;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;


Expand Down Expand Up @@ -1959,11 +1962,8 @@ private static synchronized CSSName addProperty(
}

static {
CSSParser parser = new CSSParser(new CSSErrorHandler() {
@Override
public void error(String uri, String message) {
XRLog.cssParse("(" + uri + ") " + message);
}
CSSParser parser = new CSSParser((uri, message) -> {
XRLog.log(Level.INFO, LogMessageId.LogMessageId2Param.CSS_PARSE_GENERIC_MESSAGE, uri, message);
});
for (Iterator<CSSName> i = ALL_PRIMITIVE_PROPERTY_NAMES.values().iterator(); i.hasNext(); ) {
CSSName cssName = i.next();
Expand All @@ -1972,7 +1972,7 @@ public void error(String uri, String message) {
cssName, StylesheetInfo.USER_AGENT, cssName.initialValue);

if (value == null) {
XRLog.exception("Unable to derive initial value for " + cssName);
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.EXCEPTION_CSS_UNABLE_TO_DERIVE_INITIAL_VALUE_FOR_CLASSNAME, cssName);
} else {
cssName.initialDerivedValue = DerivedValueFactory.newDerivedValue(
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.openhtmltopdf.css.parser.CSSPrimitiveValue;
import com.openhtmltopdf.css.parser.CSSValue;
import com.openhtmltopdf.util.GeneralUtil;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;
import com.openhtmltopdf.util.XRRuntimeException;

Expand Down Expand Up @@ -120,8 +121,7 @@ public static boolean isAbsoluteUnit(short type) {
case CSSPrimitiveValue.CSS_STRING:
return true;
case CSSPrimitiveValue.CSS_UNKNOWN:
XRLog.cascade(Level.WARNING, "Asked whether type was absolute, given CSS_UNKNOWN as the type. " +
"Might be one of those funny values like background-position.");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.CASCADE_IS_ABSOLUTE_CSS_UNKNOWN_GIVEN);
GeneralUtil.dumpShortException(new Exception());
// fall-through
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;

import com.openhtmltopdf.css.constants.MarginBoxName;
import com.openhtmltopdf.css.extend.AttributeResolver;
import com.openhtmltopdf.css.extend.StylesheetFactory;
import com.openhtmltopdf.css.extend.TreeResolver;
import com.openhtmltopdf.css.sheet.*;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;


Expand Down Expand Up @@ -149,7 +151,7 @@ protected Mapper matchElement(Object e) {
Mapper createDocumentMapper(List<Stylesheet> stylesheets, String medium) {
java.util.TreeMap<String,Selector> sorter = new java.util.TreeMap<String,Selector>();
addAllStylesheets(stylesheets, sorter, medium);
XRLog.match("Matcher created with " + sorter.size() + " selectors");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.MATCH_MATCHER_CREATED_WITH_SELECTOR, sorter.size());
return new Mapper(sorter.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.openhtmltopdf.css.extend.AttributeResolver;
import com.openhtmltopdf.css.extend.TreeResolver;
import com.openhtmltopdf.css.sheet.Ruleset;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;

import java.util.logging.Level;
Expand Down Expand Up @@ -299,7 +300,7 @@ public void setPseudoClass(int pc) {
public void setPseudoElement(String pseudoElement) {
if (_pe != null) {
addUnsupportedCondition();
XRLog.match(Level.WARNING, "Trying to set more than one pseudo-element");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.MATCH_TRYING_TO_SET_MORE_THAN_ONE_PSEUDO_ELEMENT);
} else {
_specificityD++;
_pe = pseudoElement;
Expand Down Expand Up @@ -408,7 +409,7 @@ Object getAppropriateSibling(Object e, TreeResolver treeRes) {
sibling = treeRes.getPreviousSiblingElement(e);
break;
default:
XRLog.exception("Bad sibling axis");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.EXCEPTION_SELECTOR_BAD_SIBLING_AXIS);
}
return sibling;
}
Expand All @@ -424,7 +425,7 @@ private void addCondition(Condition c) {
}
if (_pe != null) {
conditions.add(Condition.createUnsupportedCondition());
XRLog.match(Level.WARNING, "Trying to append conditions to pseudoElement " + _pe);
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.MATCH_TRYING_TO_APPEND_CONDITIONS_TO_PSEUDO_ELEMENT, _pe);
}
conditions.add(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.openhtmltopdf.css.newmatch.Selector;
import com.openhtmltopdf.css.parser.property.PropertyBuilder;
import com.openhtmltopdf.css.sheet.*;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.ThreadCtx;
import com.openhtmltopdf.util.XRLog;

Expand Down Expand Up @@ -257,7 +258,7 @@ private void import_rule(Stylesheet stylesheet) throws IOException {
String resolved = ThreadCtx.get().sharedContext().getUserAgentCallback().resolveUri(baseUri, uri);

if (resolved == null) {
XRLog.load(Level.INFO, "URI resolver rejected resolving CSS import at (" + uri + ")");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.LOAD_URI_RESOLVER_REJECTED_RESOLVING_CSS_IMPORT_AT_URI, uri);
}

info.setUri(resolved);
Expand Down Expand Up @@ -1950,7 +1951,7 @@ private String getTokenValue(Token t, boolean literal) {
String uriResolved = ThreadCtx.get().sharedContext().getUserAgentCallback().resolveUri(_URI, uriResult);

if (uriResolved == null) {
XRLog.load(Level.INFO, "URI resolver rejected resolving URI at (" + uriResult + ") in CSS stylehseet");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.LOAD_URI_RESOLVER_REJECTED_RESOLVING_URI_AT_URI_IN_CSS_STYLESHEET, uriResult);
}

return uriResolved == null ? "" : uriResolved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.openhtmltopdf.render.FSFont;
import com.openhtmltopdf.render.FSFontMetrics;
import com.openhtmltopdf.render.RenderingContext;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;
import com.openhtmltopdf.util.XRRuntimeException;

Expand Down Expand Up @@ -252,9 +253,7 @@ public boolean hasAbsoluteUnit(CSSName cssName) {
try {
isAbs = valueByName(cssName).hasAbsoluteUnit();
} catch (Exception e) {
XRLog.layout(Level.WARNING, "Property " + cssName + " has an assignment we don't understand, " +
"and can't tell if it's an absolute unit or not. Assuming it is not. Exception was: " +
e.getMessage());
XRLog.log(Level.WARNING, LogMessageId.LogMessageId2Param.LAYOUT_CSS_PROPERTY_HAS_UNPROCESSABLE_ASSIGNMENT, cssName, e.getMessage());
isAbs = false;
}
return isAbs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.openhtmltopdf.css.style.CssContext;
import com.openhtmltopdf.css.style.DerivedValue;
import com.openhtmltopdf.css.value.FontSpecification;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;

public class LengthValue extends DerivedValue {
Expand Down Expand Up @@ -192,23 +193,15 @@ public static float calcFloatProportionalValue(CalculatedStyle style,
break;
default:
// nothing to do, we only convert those listed above
XRLog.cascade(Level.WARNING,
"Asked to convert " + cssName + " from relative to absolute, " +
" don't recognize the datatype " +
"'" + ValueConstants.stringForSACPrimitiveType(primitiveType) + "' "
+ primitiveType + "(" + stringValue + ")");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId4Param.CASCADE_UNKNOWN_DATATYPE_FOR_RELATIVE_TO_ABSOLUTE, cssName, ValueConstants.stringForSACPrimitiveType(primitiveType), primitiveType, stringValue);
}
//assert (new Float(absVal).intValue() >= 0);

if (XRLog.isLoggingEnabled()) {
if (cssName == CSSName.FONT_SIZE) {
XRLog.cascade(Level.FINEST, cssName + ", relative= " +
relVal + " (" + stringValue + "), absolute= "
+ absVal);
XRLog.log(Level.FINEST, LogMessageId.LogMessageId4Param.CASCADE_CALC_FLOAT_PROPORTIONAL_VALUE_INFO_FONT_SIZE, cssName, relVal, stringValue, absVal);
} else {
XRLog.cascade(Level.FINEST, cssName + ", relative= " +
relVal + " (" + stringValue + "), absolute= "
+ absVal + " using base=" + baseValue);
XRLog.log(Level.FINEST, LogMessageId.LogMessageId5Param.CASCADE_CALC_FLOAT_PROPORTIONAL_VALUE_INFO, cssName, relVal, stringValue, absVal, baseValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.openhtmltopdf.css.style.derived.BorderPropertySet;
import com.openhtmltopdf.css.style.derived.FSLinearGradient;
import com.openhtmltopdf.render.*;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;

import java.awt.*;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void paintBackground(
public void drawImage(FSImage image, int x, int y, boolean interpolate);

default public void drawLinearGradient(FSLinearGradient backgroundLinearGradient, Shape bounds) {
XRLog.render(Level.WARNING, "linear-gradient(...) is not supported in this output device");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.RENDER_LINEAR_GRADIENT_IS_NOT_SUPPORTED);
}

public void draw(Shape s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.openhtmltopdf.extend.FSCacheEx;
import com.openhtmltopdf.extend.FSCacheValue;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;


Expand All @@ -20,7 +21,7 @@ public class FSDefaultCacheStore implements FSCacheEx<String, FSCacheValue> {

@Override
public void put(String key, FSCacheValue value) {
XRLog.load(Level.INFO, "Putting key(" + key + ") in cache.");
XRLog.log(Level.INFO, LogMessageId.LogMessageId1Param.LOAD_PUTTING_KEY_IN_CACHE, key);
_store.put(key, value);
}

Expand All @@ -38,18 +39,18 @@ public FSCacheValue get(String key, Callable<? extends FSCacheValue> loader) {
_store.put(key, value);
}
} catch (Exception e) {
XRLog.exception("Could not load cache value for key(" + key + ")", e);
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.EXCEPTION_COULD_NOT_CACHE_VALUE_FOR_KEY, key, e);
value = null;
}
XRLog.load(Level.INFO, (value == null ? "Missed" : "Hit") + " key(" + key + ") from cache.");

XRLog.log(Level.INFO, LogMessageId.LogMessageId2Param.LOAD_CACHE_HIT_STATUS, (value == null ? "Missed" : "Hit"), key);
return value;
}

@Override
public FSCacheValue get(String key) {
FSCacheValue value = _store.get(key);
XRLog.load(Level.INFO, (value == null ? "Missed" : "Hit") + " key(" + key + ") from cache.");
XRLog.log(Level.INFO, LogMessageId.LogMessageId2Param.LOAD_CACHE_HIT_STATUS, (value == null ? "Missed" : "Hit"), key);
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.logging.Level;

import com.openhtmltopdf.util.LogMessageId;
import org.w3c.dom.Element;

import com.openhtmltopdf.bidi.BidiSplitter;
Expand Down Expand Up @@ -206,10 +207,8 @@ public static void layoutContent(LayoutContext c, BlockBox box, int initialY, in
}

if (troublesomeAttemptCount > 5) {
XRLog.general(Level.SEVERE,
"A fatal infinite loop bug was detected in the line breaking " +
"algorithm for break-word! Start-substring=[" + lbContext.getStartSubstring() + "], " +
"end=" + lbContext.getEnd());
XRLog.log(Level.SEVERE, LogMessageId.LogMessageId2Param.GENERAL_FATAL_INFINITE_LOOP_BUG_IN_LINE_BREAKING_ALGO,
lbContext.getStartSubstring(), lbContext.getEnd());
throw new RuntimeException("Infinite loop bug in break-word line breaking algorithm!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.openhtmltopdf.newtable.TableCellBox;
import com.openhtmltopdf.render.*;
import com.openhtmltopdf.render.displaylist.TransformCreator;
import com.openhtmltopdf.util.LogMessageId;
import com.openhtmltopdf.util.XRLog;

import java.awt.*;
Expand Down Expand Up @@ -616,11 +617,11 @@ private void applyTransformFunctions(float flipFactor, List<PropertyValue> trans
params.get(2).getFloatValue(), params.get(3).getFloatValue(),
params.get(4).getFloatValue(), params.get(5).getFloatValue()));
} else if ("translate".equalsIgnoreCase(fName)) {
XRLog.layout(Level.WARNING, "translate function not implemented at this time");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.LAYOUT_FUNCTION_NOT_IMPLEMENTED, "translate");
} else if ("translateX".equalsIgnoreCase(fName)) {
XRLog.layout(Level.WARNING, "translateX function not implemented at this time");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.LAYOUT_FUNCTION_NOT_IMPLEMENTED, "translateX");
} else if ("translateY".equalsIgnoreCase(fName)) {
XRLog.layout(Level.WARNING, "translateY function not implemented at this time");
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.LAYOUT_FUNCTION_NOT_IMPLEMENTED, "translateY");
}
}
}
Expand Down
Loading