org.slf4j.helpers.Util Java Examples

The following examples show how to use org.slf4j.helpers.Util. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
private static final void versionSanityCheck() {
    try {
        String e = StaticLoggerBinder.REQUESTED_API_VERSION;
        boolean match = false;
        String[] arr$ = API_COMPATIBILITY_LIST;
        int len$ = arr$.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            String aAPI_COMPATIBILITY_LIST = arr$[i$];
            if(e.startsWith(aAPI_COMPATIBILITY_LIST)) {
                match = true;
            }
        }

        if(!match) {
            Util.report("The requested version " + e + " by your slf4j binding is not compatible with " + Arrays.asList(API_COMPATIBILITY_LIST));
            Util.report("See http://www.slf4j.org/codes.html#version_mismatch for further details.");
        }
    } catch (NoSuchFieldError var6) {
    } catch (Throwable var7) {
        Util.report("Unexpected problem occured during version sanity check", var7);
    }

}
 
Example #2
Source File: SimpleLogger.java    From JDA with Apache License 2.0 6 votes vote down vote up
private static PrintStream computeTargetStream(String logFile) {
    if ("System.err".equalsIgnoreCase(logFile))
        return System.err;
    else if ("System.out".equalsIgnoreCase(logFile)) {
        return System.out;
    } else {
        try {
            FileOutputStream fos = new FileOutputStream(logFile);
            PrintStream printStream = new PrintStream(fos);
            return printStream;
        } catch (FileNotFoundException e) {
            Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
            return System.err;
        }
    }
}
 
Example #3
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) {
    if(!isAndroid()) {
        if(isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
            Util.report("Class path contains multiple SLF4J bindings.");
            Iterator i$ = staticLoggerBinderPathSet.iterator();

            while(i$.hasNext()) {
                URL path = (URL)i$.next();
                Util.report("Found binding in [" + path + ']');
            }

            Util.report("See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
        }

    }
}
 
Example #4
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
static Set<URL> findPossibleStaticLoggerBinderPathSet() {
    LinkedHashSet staticLoggerBinderPathSet = new LinkedHashSet();

    try {
        ClassLoader ioe = LoggerFactory.class.getClassLoader();
        Enumeration paths;
        if(ioe == null) {
            paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH);
        } else {
            paths = ioe.getResources(STATIC_LOGGER_BINDER_PATH);
        }

        while(paths.hasMoreElements()) {
            URL path = (URL)paths.nextElement();
            staticLoggerBinderPathSet.add(path);
        }
    } catch (IOException var4) {
        Util.report("Error getting resources from path", var4);
    }

    return staticLoggerBinderPathSet;
}
 
Example #5
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
private static final void fixSubstitutedLoggers() {
    List loggers = TEMP_FACTORY.getLoggers();
    if(!loggers.isEmpty()) {
        Util.report("The following set of substitute loggers may have been accessed");
        Util.report("during the initialization phase. Logging calls during this");
        Util.report("phase were not honored. However, subsequent logging calls to these");
        Util.report("loggers will work as normally expected.");
        Util.report("See also http://www.slf4j.org/codes.html#substituteLogger");
        Iterator i$ = loggers.iterator();

        while(i$.hasNext()) {
            SubstituteLogger subLogger = (SubstituteLogger)i$.next();
            subLogger.setDelegate(getKonkerLogger(subLogger.getName()));
            Util.report(subLogger.getName());
        }

        TEMP_FACTORY.clear();
    }
}
 
Example #6
Source File: KonkerStaticLoggerBinder.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
void init() {
    try {
        try {
            (new KonkerContextInitializer(this.defaultLoggerContext)).autoConfig();
        } catch (JoranException var2) {
            Util.report("Failed to auto configure default logger context", var2);
        }

        if(!StatusUtil.contextHasStatusListener(this.defaultLoggerContext)) {
            StatusPrinter.printInCaseOfErrorsOrWarnings(this.defaultLoggerContext);
        }

        this.contextSelectorBinder.init(this.defaultLoggerContext, KEY);
        this.initialized = true;
    } catch (Throwable var3) {
        Util.report("Failed to instantiate [" + LoggerContext.class.getName() + ']', var3);
    }

}
 
Example #7
Source File: SimpleLogger.java    From HttpSessionReplacer with MIT License 6 votes vote down vote up
private static PrintStream computeTargetStream(String logFile) {
  if ("System.err".equalsIgnoreCase(logFile))
    return System.err; // NOSONAR
  else if ("System.out".equalsIgnoreCase(logFile)) {
    return System.out; // NOSONAR
  } else {
    try {
      FileOutputStream fos = new FileOutputStream(logFile);
      PrintStream printStream = new PrintStream(fos);
      return printStream;
    } catch (FileNotFoundException e) {
      Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
      return System.err; // NOSONAR
    }
  }
}
 
Example #8
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private static final void bind() {
    String msg;
    try {
        Set e = findPossibleStaticLoggerBinderPathSet();
        reportMultipleBindingAmbiguity(e);
        StaticLoggerBinder.getSingleton();
        INITIALIZATION_STATE = 3;
        reportActualBinding(e);
        fixSubstitutedLoggers();
    } catch (NoClassDefFoundError var2) {
        msg = var2.getMessage();
        if(!messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
            failedBinding(var2);
            throw var2;
        }

        INITIALIZATION_STATE = 4;
        Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
        Util.report("Defaulting to no-operation (NOP) logger implementation");
        Util.report("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.");
    } catch (NoSuchMethodError var3) {
        msg = var3.getMessage();
        if(msg != null && msg.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) {
            INITIALIZATION_STATE = 2;
            Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding.");
            Util.report("Your binding is version 1.5.5 or earlier.");
            Util.report("Upgrade your binding to version 1.6.x.");
        }

        throw var3;
    } catch (Exception var4) {
        failedBinding(var4);
        throw new IllegalStateException("Unexpected initialization failure", var4);
    }

}
 
Example #9
Source File: CasLoggerFactory.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Instantiates a new Cas logger factory.
 * Configures the reflection scanning engine to be prepared to scan <code>org.slf4j.impl</code>
 * in order to find other available factories.
 */
public CasLoggerFactory() {
    this.loggerMap = new ConcurrentHashMap<>();
    final Collection<URL> set = ClasspathHelper.forPackage(PACKAGE_TO_SCAN);
    final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));

    final Set<Class<? extends ILoggerFactory>> subTypesOf = reflections.getSubTypesOf(ILoggerFactory.class);
    subTypesOf.remove(this.getClass());

    if (subTypesOf.size() > 1) {
        Util.report("Multiple ILoggerFactory bindings are found on the classpath:");
        for (final Class<? extends ILoggerFactory> c : subTypesOf) {
            Util.report("* " + c.getCanonicalName());
        }
    }

    if (subTypesOf.isEmpty()) {
        final RuntimeException e = new RuntimeException("No ILoggerFactory could be found on the classpath."
                + " CAS cannot determine the logging framework."
                + " Examine the project dependencies and ensure that there is one and only one logging framework available.");

        Util.report(e.getMessage(), e);
        throw e;
    }
    this.realLoggerFactoryClass = subTypesOf.iterator().next();
    Util.report("ILoggerFactory to be used for logging is: " + this.realLoggerFactoryClass.getName());
}
 
Example #10
Source File: SimpleLogger.java    From HttpSessionReplacer with MIT License 5 votes vote down vote up
static synchronized void init() {
  INITIALIZED = true;
  loadProperties();

  String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
  if (defaultLogLevelString != null)
    DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);

  SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
  SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
  SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
  SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
  DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
  LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);
  WARN_LEVEL_STRING = getStringProperty(WARN_LEVEL_STRING_KEY, WARN_LEVEL_STRING);

  LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
  TARGET_STREAM = computeTargetStream(LOG_FILE);

  if (DATE_TIME_FORMAT_STR != null) {
    try {
      DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
    } catch (IllegalArgumentException e) {
      Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
    }
  }
}
 
Example #11
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public static KonkerLogger getLogger(Class<?> clazz) {
    KonkerLogger logger = getKonkerLogger(clazz.getName());
    if(DETECT_LOGGER_NAME_MISMATCH) {
        Class autoComputedCallingClass = Util.getCallingClass();
        if(autoComputedCallingClass != null && nonMatchingClasses(clazz, autoComputedCallingClass)) {
            Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", new Object[]{logger.getName(), autoComputedCallingClass.getName()}));
            Util.report("See http://www.slf4j.org/codes.html#loggerNameMismatch for an explanation");
        }
    }

    return logger;
}
 
Example #12
Source File: LoggerUtil.java    From mdw with Apache License 2.0 5 votes vote down vote up
public static StandardLogger getStandardLogger() {
    String loggerImplClass = System.getProperty(MDW_LOGGER_IMPL);
    if (!accessed && loggerImplClass != null) {
        System.out.println("\nUsing Logger Impl: " + loggerImplClass);
        accessed = true;
    }
    Class<?> callingClass = Util.getCallingClass();
    StandardLogger logger;
    // avoid reflection for known impls
    if (loggerImplClass == null) {
        logger = new Slf4JStandardLoggerImpl(callingClass.getName());
    }
    else if (SimpleLogger.class.getName().equals(loggerImplClass)) {
        logger = SimpleLogger.getSingleton();
    }
    else if (Log4JStandardLoggerImpl.class.getName().equals(loggerImplClass) || org.apache.log4j.Logger.class.getName().equals(loggerImplClass)) {
        logger = new Log4JStandardLoggerImpl();
    }
    else if (Slf4JStandardLoggerImpl.class.getName().equals(loggerImplClass) || org.slf4j.Logger.class.getName().equals(loggerImplClass)) {
        logger = new Slf4JStandardLoggerImpl(callingClass.getName());
    }
    else {
        try {
            logger = Class.forName(loggerImplClass).asSubclass(StandardLogger.class).newInstance();
        }
        catch (Exception ex) {
            ex.printStackTrace();  // logging isn't working
            return null;
        }
    }
    checkWarnActivityLogging(logger, callingClass);
    return logger;
}
 
Example #13
Source File: SimpleLogger.java    From JDA with Apache License 2.0 5 votes vote down vote up
static void init() {
    INITIALIZED = true;
    loadProperties();

    String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
    if (defaultLogLevelString != null)
        DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);

    SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
    SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
    SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
    SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
    DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
    LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);
    WARN_LEVEL_STRING = getStringProperty(WARN_LEVEL_STRING_KEY, WARN_LEVEL_STRING);

    LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
    TARGET_STREAM = computeTargetStream(LOG_FILE);

    if (DATE_TIME_FORMAT_STR != null) {
        try {
            DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
        } catch (IllegalArgumentException e) {
            Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
        }
    }
}
 
Example #14
Source File: CasLoggerFactoryTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws IOException {
    if (LOG_FILE.exists()) {
        Util.report("Initializing log file " + LOG_FILE.getCanonicalPath());
        FileUtils.write(LOG_FILE, "", false);
    }
}
 
Example #15
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
static void failedBinding(Throwable t) {
    INITIALIZATION_STATE = 2;
    Util.report("Failed to instantiate SLF4J LoggerFactory", t);
}
 
Example #16
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
private static boolean isAndroid() {
    String vendor = Util.safeGetSystemProperty("java.vendor.url");
    return vendor == null?false:vendor.toLowerCase().contains("android");
}
 
Example #17
Source File: KonkerLoggerFactory.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
private static void reportActualBinding(Set<URL> staticLoggerBinderPathSet) {
    if(isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
        Util.report("Actual binding is of type [" + StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr() + ']');
    }

}