Java slf4j Logger error(final BundleContext b, final String msg, final Throwable t)

Here you can find the source of error(final BundleContext b, final String msg, final Throwable t)

Description

Logs the message to the bundle's error level.

License

Apache License

Parameter

Parameter Description
b BundleContext
msg String
t Throwable

Declaration

public static void error(final BundleContext b, final String msg, final Throwable t) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.osgi.framework.BundleContext;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class Main {
    /**/*ww  w  .j  a va2 s. c o m*/
     * Logs the message to the bundle's error level.
     *
     * @param b {@link BundleContext}
     * @param msg {@link String}
     */
    public static void error(final BundleContext b, final String msg) {
        final String symbolicName = b.getBundle().getSymbolicName();
        final Logger log = getLogger(symbolicName);
        log.error(prefix(b, msg));
    }

    /**
     * Logs the message to the bundle's error level.
     *
     * @param b {@link BundleContext}
     * @param msg {@link String}
     * @param t {@link Throwable}
     */
    public static void error(final BundleContext b, final String msg, final Throwable t) {
        final String symbolicName = b.getBundle().getSymbolicName();
        final Logger log = getLogger(symbolicName);
        log.error(prefix(b, msg), t);
    }

    /**
     * Prefixes string {@code s} with the format:<br/>
     * {@code <symbolicName>: <s>}
     *
     * @param b {@link BundleContext}
     * @param s {@link String}
     * @return {@link String}
     */
    public static String prefix(final BundleContext b, final String s) {
        if (s == null)
            throw new NullPointerException("s cannot be null");
        return b.getBundle().getSymbolicName().concat(": ".concat(s));
    }
}

Related

  1. debug(Logger logger, Exception e)
  2. debug(Logger logger, String format, Object... arguments)
  3. displayProperties(Logger log, Properties prop)
  4. dumpConfiguration(Map map, Logger log)
  5. error(Class clz, String logStr, Throwable e)
  6. error(Logger log, String fmt, String... args)
  7. error(Logger logger, Exception e)
  8. error(String errorMessage, Throwable e)
  9. error(String msg, Throwable e)