freemarker.log.Logger类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(391)

本文整理了Java中freemarker.log.Logger类的一些代码示例,展示了Logger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger类的具体详情如下:
包路径:freemarker.log.Logger
类名称:Logger

Logger介绍

[英]Delegates logger creation to an actual logging library. By default it looks for logger libraries in this order (in FreeMarker 2.3.x): Log4J, Avalon LogKit, JUL (i.e., java.util.logging). Prior to FreeMarker 2.4, SLF4J and Apache Commons Logging aren't searched automatically due to backward compatibility constraints. But if you have log4j-over-slf4j properly installed (means, you have no real Log4j in your class path, and SLF4J has a backing implementation like logback-classic), then FreeMarker will use SLF4J directly instead of Log4j (since FreeMarker 2.3.22).

If the auto detection sequence describet above doesn't give you the result that you want, see #SYSTEM_PROPERTY_NAME_LOGGER_LIBRARY.
[中]将记录器创建委托给实际的日志库。默认情况下,它按以下顺序查找记录器库(在FreeMarker 2.3.x中):Log4J、Avalon LogKit、JUL(即java.util.logging)。在FreeMarker 2.4之前,由于向后兼容性限制,SLF4J和Apache Commons日志不会自动搜索。但是,如果您正确安装了log4j-over-slf4j(这意味着,您的类路径中没有真正的log4j,并且slf4j具有类似logback classic的支持实现),那么FreeMarker将直接使用slf4j而不是log4j(自FreeMarker 2.3.22以来)。
如果上面的自动检测序列描述没有给出您想要的结果,请参阅#系统(u属性)名称(u记录器)库。

代码示例

代码示例来源:origin: org.freemarker/freemarker

  1. private static Class getClass(String className) {
  2. try {
  3. return ClassUtil.forName(className);
  4. } catch (Exception e) {
  5. if (LOG.isDebugEnabled()) {
  6. LOG.debug("Couldn't load class " + className, e);
  7. }
  8. return null;
  9. }
  10. }

代码示例来源:origin: org.freemarker/freemarker

  1. private static ExpressionFactory tryExpressionFactoryImplementation(String packagePrefix) {
  2. String className = packagePrefix + ".el.ExpressionFactoryImpl";
  3. try {
  4. Class cl = ClassUtil.forName(className);
  5. if (ExpressionFactory.class.isAssignableFrom(cl)) {
  6. LOG.info("Using " + className + " as implementation of " +
  7. ExpressionFactory.class.getName());
  8. return (ExpressionFactory) cl.newInstance();
  9. }
  10. LOG.warn("Class " + className + " does not implement " +
  11. ExpressionFactory.class.getName());
  12. } catch (ClassNotFoundException e) {
  13. } catch (Exception e) {
  14. LOG.error("Failed to instantiate " + className, e);
  15. }
  16. return null;
  17. }

代码示例来源:origin: org.freemarker/freemarker

  1. private void onSameNameClassesDetected(String className) {
  2. // TODO: This behavior should be pluggable, as in environments where
  3. // some classes are often reloaded or multiple versions of the
  4. // same class is normal (OSGi), this will drop the cache contents
  5. // too often.
  6. if (LOG.isInfoEnabled()) {
  7. LOG.info(
  8. "Detected multiple classes with the same name, \"" + className +
  9. "\". Assuming it was a class-reloading. Clearing class introspection " +
  10. "caches to release old data.");
  11. }
  12. forcedClearCache();
  13. }

代码示例来源:origin: org.freemarker/freemarker

  1. public void report(TemplateException te, Environment env) {
  2. String message = "Error executing FreeMarker template part in the #attempt block";
  3. if (!logAsWarn) {
  4. LOG.error(message, te);
  5. } else {
  6. LOG.warn(message, te);
  7. }
  8. }

代码示例来源:origin: org.freemarker/freemarker

  1. TldParserForTaglibBuilding(ObjectWrapper wrapper) {
  2. if (wrapper instanceof BeansWrapper) {
  3. beansWrapper = (BeansWrapper) wrapper;
  4. } else {
  5. beansWrapper = null;
  6. if (LOG.isWarnEnabled()) {
  7. LOG.warn("Custom EL functions won't be loaded because "
  8. + (wrapper == null
  9. ? "no ObjectWrapper was specified for the TaglibFactory "
  10. + "(via TaglibFactory.setObjectWrapper(...), exists since 2.3.22)"
  11. : "the ObjectWrapper wasn't instance of " + BeansWrapper.class.getName())
  12. + ".");
  13. }
  14. }
  15. }

代码示例来源:origin: org.uberfire/uberfire-workbench-processors

  1. protected AbstractErrorAbsorbingProcessor() {
  2. try {
  3. freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
  4. } catch (ClassNotFoundException e) {
  5. rememberedInitError = e;
  6. }
  7. }

代码示例来源:origin: org.freemarker/freemarker

  1. public void stop() {
  2. this.stop = true;
  3. if (serverSocket != null) {
  4. try {
  5. serverSocket.close();
  6. } catch (IOException e) {
  7. LOG.error("Unable to close server socket.", e);
  8. }
  9. }
  10. }
  11. }

代码示例来源:origin: org.freemarker/freemarker

  1. private void addTldLocationsFromFileDirectory(final File dir) throws IOException, SAXException {
  2. if (dir.isDirectory()) {
  3. if (LOG.isDebugEnabled()) {
  4. LOG.debug("Scanning for *.tld-s in File directory: " + StringUtil.jQuoteNoXSS(dir));
  5. }
  6. File[] tldFiles = dir.listFiles(new FilenameFilter() {
  7. public boolean accept(File urlAsFile, String name) {
  8. return isTldFileNameIgnoreCase(name);
  9. }
  10. });
  11. if (tldFiles == null) {
  12. throw new IOException("Can't list this directory for some reason: " + dir);
  13. }
  14. for (int i = 0; i < tldFiles.length; i++) {
  15. final File file = tldFiles[i];
  16. addTldLocationFromTld(new FileTldLocation(file));
  17. }
  18. } else {
  19. LOG.warn("Skipped scanning for *.tld for non-existent directory: " + StringUtil.jQuoteNoXSS(dir));
  20. }
  21. }

代码示例来源:origin: org.freemarker/freemarker

  1. private static void logInLogger(boolean error, String message, Throwable exception) {
  2. boolean canUseRealLogger;
  3. synchronized (Logger.class) {
  4. canUseRealLogger = loggerFactory != null && !(loggerFactory instanceof _NullLoggerFactory);
  5. }
  6. if (canUseRealLogger) {
  7. try {
  8. final Logger logger = Logger.getLogger("freemarker.logger");
  9. if (error) {
  10. logger.error(message);
  11. } else {
  12. logger.warn(message);
  13. }
  14. } catch (Throwable e) {
  15. canUseRealLogger = false;
  16. }
  17. }
  18. if (!canUseRealLogger) {
  19. System.err.println((error ? "ERROR" : "WARN") + " "
  20. + LoggerFactory.class.getName() + ": " + message);
  21. if (exception != null) {
  22. System.err.println("\tException: " + tryToString(exception));
  23. while (exception.getCause() != null) {
  24. exception = exception.getCause();
  25. System.err.println("\tCaused by: " + tryToString(exception));
  26. }
  27. }
  28. }
  29. }

代码示例来源:origin: org.freemarker/freemarker

  1. if (getLogTemplateExceptions() && LOG.isErrorEnabled()
  2. LOG.error("Error executing FreeMarker template", templateException);

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * Convenience method. Tells the system to use Xalan for XPath queries.
  3. * @throws Exception if the Xalan XPath classes are not present.
  4. */
  5. static public void useXalanXPathSupport() throws Exception {
  6. Class.forName("org.apache.xpath.XPath");
  7. Class c = Class.forName("freemarker.ext.dom.XalanXPathSupport");
  8. synchronized (STATIC_LOCK) {
  9. xpathSupportClass = c;
  10. }
  11. LOG.debug("Using Xalan classes for XPath support");
  12. }

代码示例来源:origin: org.freemarker/freemarker

  1. LOG.debug("Looking for TLD locations in TLD-s specified in cfg.classpathTlds");
  2. in = tldLocation.getInputStream();
  3. } catch (IOException e) {
  4. if (LOG.isWarnEnabled()) {
  5. LOG.warn("Ignored classpath TLD location " + StringUtil.jQuoteNoXSS(tldResourcePath)
  6. + " because of error", e);

代码示例来源:origin: org.freemarker/freemarker

  1. LOG.info("Failed to check if finetuneMethodAppearance is overidden in " + thisClass.getName()
  2. + "; acting like if it was, but this way it won't utilize the shared class introspection "
  3. + "cache.",
  4. LOG.warn("Overriding " + BeansWrapper.class.getName() + ".finetuneMethodAppearance is deprecated "
  5. + "and will be banned sometimes in the future. Use setMethodAppearanceFineTuner instead.");
  6. ftmaDeprecationWarnLogged = true;

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * Logs flag warning for a limited number of times. This is used to prevent
  3. * log flooding.
  4. */
  5. static void logFlagWarning(String message) {
  6. if (!flagWarningsEnabled) return;
  7. int cnt;
  8. synchronized (flagWarningsCntSync) {
  9. cnt = flagWarningsCnt;
  10. if (cnt < MAX_FLAG_WARNINGS_LOGGED) {
  11. flagWarningsCnt++;
  12. } else {
  13. flagWarningsEnabled = false;
  14. return;
  15. }
  16. }
  17. message += " This will be an error in some later FreeMarker version!";
  18. if (cnt + 1 == MAX_FLAG_WARNINGS_LOGGED) {
  19. message += " [Will not log more regular expression flag problems until restart!]";
  20. }
  21. LOG.warn(message);
  22. }

代码示例来源:origin: org.freemarker/freemarker

  1. if (wrapper.isStrict()) {
  2. throw new InvalidPropertyException("No such bean property: " + key);
  3. } else if (LOG.isDebugEnabled()) {
  4. logNoSuchKey(key, classInfo);

代码示例来源:origin: org.freemarker/com.springsource.freemarker

  1. logger.info("Overwriting value [" + obj + "] for " +
  2. " key '" + name + "' with [" + method +
  3. "] in static model for " + clazz.getName());

代码示例来源:origin: kiegroup/appformer

  1. protected AbstractErrorAbsorbingProcessor() {
  2. try {
  3. freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
  4. } catch (ClassNotFoundException e) {
  5. rememberedInitError = e;
  6. }
  7. }

代码示例来源:origin: org.freemarker/freemarker

  1. private ServletException newServletExceptionWithFreeMarkerLogging(String message, Throwable cause) throws ServletException {
  2. if (cause instanceof TemplateException) {
  3. // For backward compatibility, we log into the same category as Environment did when
  4. // log_template_exceptions was true.
  5. LOG_RT.error(message, cause);
  6. } else {
  7. LOG.error(message, cause);
  8. }
  9. ServletException e = new ServletException(message, cause);
  10. try {
  11. // Prior to Servlet 2.5, the cause exception wasn't set by the above constructor.
  12. // If we are on 2.5+ then this will throw an exception as the cause was already set.
  13. e.initCause(cause);
  14. } catch (Exception ex) {
  15. // Ignored; see above
  16. }
  17. throw e;
  18. }

代码示例来源:origin: org.freemarker/com.springsource.freemarker

  1. private void handleTemplateException(TemplateException te)
  2. throws TemplateException
  3. {
  4. // Logic to prevent double-handling of the exception in
  5. // nested visit() calls.
  6. if(lastThrowable == te) {
  7. throw te;
  8. }
  9. lastThrowable = te;
  10. // Log the exception
  11. if(logger.isErrorEnabled()) {
  12. logger.error("Template processing error: " + StringUtil.jQuoteNoXSS(te.getMessage()), te);
  13. }
  14. // Stop exception is not passed to the handler, but
  15. // explicitly rethrown.
  16. if(te instanceof StopException) {
  17. throw te;
  18. }
  19. // Finally, pass the exception to the handler
  20. getTemplateExceptionHandler().handleTemplateException(te, this, out);
  21. }

代码示例来源:origin: org.freemarker/freemarker

  1. static public void useSunInternalXPathSupport() throws Exception {
  2. Class.forName("com.sun.org.apache.xpath.internal.XPath");
  3. Class c = Class.forName("freemarker.ext.dom.SunInternalXalanXPathSupport");
  4. synchronized (STATIC_LOCK) {
  5. xpathSupportClass = c;
  6. }
  7. LOG.debug("Using Sun's internal Xalan classes for XPath support");
  8. }

相关文章