Package org.slf4j

Examples of org.slf4j.Logger


     * @param bundle The bundle for which a logger is to be returned.
     * @return The Logger for the bundle.
     */
    private Logger getLogger(Bundle bundle) {
        Long bundleId = new Long((bundle == null) ? 0 : bundle.getBundleId());
        Logger log;
        synchronized (loggers) {
            log = loggers.get(bundleId);
        }
        if (log == null) {

View Full Code Here


    private void logOut(LogEntry logEntry) {
        // /* package */ void logOut(Bundle bundle, ServiceReference sr, int
        // level, String message, Throwable exception) {

        // get the logger for the bundle
        Logger log = getLogger(logEntry.getBundle());

        StringBuffer msg = new StringBuffer();

        ServiceReference sr = logEntry.getServiceReference();
        if (sr != null) {
            msg.append("Service [");
            if (sr.getProperty(Constants.SERVICE_PID) != null) {
                msg.append(sr.getProperty(Constants.SERVICE_PID)).append(',');
            } else if (sr.getProperty(COMPONENT_NAME) != null) {
                msg.append(sr.getProperty(COMPONENT_NAME)).append(',');
            } else if (sr.getProperty(Constants.SERVICE_DESCRIPTION) != null) {
                msg.append(sr.getProperty(Constants.SERVICE_DESCRIPTION)).append(
                    ',');
            }
            msg.append(sr.getProperty(Constants.SERVICE_ID)).append("] ");
        }

        if (logEntry.getMessage() != null) {
            msg.append(logEntry.getMessage());
        }

        Throwable exception = logEntry.getException();
        if (exception != null) {
            msg.append(" (").append(exception).append(')');
        }

        String message = msg.toString();
        switch (logEntry.getLevel()) {
            case LogService.LOG_DEBUG:
                log.debug(message, exception);
                break;
            case LogService.LOG_INFO:
                log.info(message, exception);
                break;
            case LogService.LOG_WARNING:
                log.warn(message, exception);
                break;
            case LogService.LOG_ERROR:
                log.error(message, exception);
                break;
            default:
                if (logEntry.getLevel() > LogService.LOG_DEBUG) {
                    log.trace(message, exception);
                } else if (logEntry.getLevel() < LogService.LOG_ERROR) {
                    log.error(message, exception);
                }
                break;
        }
    }
View Full Code Here

  /**
   * Returns the script logger or the logger of this class as a fallback
   * default if the global log variable is not accessible.
   */
  private Logger getLogger(Context cx, Scriptable scope) {
    Logger log = getProperty(cx, scope, SlingBindings.LOG, Logger.class);
    if (log == null) {
      log = this.defaultLog;
    }
    return log;
  }
View Full Code Here

    private Boolean cachedResult = Boolean.FALSE;

    public void activate(final BundleContext bc, final String[] configuration) {
        final List<RequiredProvider> rps = new ArrayList<RequiredProvider>();
        if ( configuration != null ) {
            final Logger logger = LoggerFactory.getLogger(getClass());
            for(final String r : configuration) {
                if ( r != null && r.trim().length() > 0 ) {
                    final String value = r.trim();
                    RequiredProvider rp = new RequiredProvider();
                    if ( value.startsWith("(") ) {
                        try {
                            rp.filter = bc.createFilter(value);
                        } catch (final InvalidSyntaxException e) {
                            logger.warn("Ignoring invalid filter syntax for required provider: " + value, e);
                            rp = null;
                        }
                    } else {
                        rp.pid = value;
                    }
View Full Code Here

        return mapEntries;
    }

    /** Activates this component */
    protected void activate(final BundleContext bundleContext) {
        final Logger logger = LoggerFactory.getLogger(getClass());
        try {
            plugin = new ResourceResolverWebConsolePlugin(bundleContext, this);
        } catch (final Throwable ignore) {
            // an exception here probably means the web console plugin is not
            // available
            logger.debug("activate: unable to setup web console plugin.", ignore);
        }
        // set up the map entries from configuration
        try {
            mapEntries = new MapEntries(this, bundleContext, this.activator.getEventAdmin());
        } catch (final Exception e) {
            logger.error("activate: Cannot access repository, failed setting up Mapping Support", e);
        }
    }
View Full Code Here

    /**
     * Checks the default settings. It runs the bundle with minimum dependencies
     */
    @Test
    public void testDefaultSettings() throws Exception {
        Logger slf4jLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        assertTrue("Default Log level should be INFO", slf4jLogger.isInfoEnabled());

        // Check for Logback being used
        assertTrue(LoggerFactory.getILoggerFactory() instanceof LoggerContext);
        assertTrue(slf4jLogger instanceof ch.qos.logback.classic.Logger);

View Full Code Here

        p.put(LOG_LEVEL, "DEBUG");
        config.update(p);

        delay();

        Logger slf4jLogger = LoggerFactory.getLogger("foo1.bar");
        assertTrue(slf4jLogger.isDebugEnabled());
        assertTrue(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isInfoEnabled());
        assertFalse(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled());

        // foo1.bar should not have explicit appender attached with it
        Iterator<Appender<ILoggingEvent>> itr = ((ch.qos.logback.classic.Logger) slf4jLogger).iteratorForAppenders();
View Full Code Here

   * @param resp
   * @throws IOException
   * @throws UnsupportedUserStoreException
   */
  public static LoginResult performAuthentication(HttpServletRequest req, HttpServletResponse resp) throws IOException, UnsupportedUserStoreException {
    Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.login"); //$NON-NLS-1$
    String login = req.getParameter("login");//$NON-NLS-1$
    User user = getUserForCredentials(login, req.getParameter("password")); //$NON-NLS-1$

    if (user != null) {
      if (user.getBlocked()) {
        return LoginResult.BLOCKED;
      }
      String actualLogin = user.getUid();
      if (logger.isInfoEnabled())
        logger.info("Login success: " + actualLogin); //$NON-NLS-1$
      req.getSession().setAttribute("user", actualLogin); //$NON-NLS-1$

      IOrionUserProfileNode userProfileNode = getUserProfileService().getUserProfileNode(actualLogin, IOrionUserProfileConstants.GENERAL_PROFILE_PART);
      try {
        // try to store the login timestamp in the user profile
        userProfileNode.put(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, new Long(System.currentTimeMillis()).toString(), false);
        userProfileNode.flush();
      } catch (CoreException e) {
        // just log that the login timestamp was not stored
        LogHelper.log(e);
      }
      return LoginResult.OK;
    }
    //don't bother tracing malformed login attempts
    if (login != null)
      logger.info("Login failed: " + login); //$NON-NLS-1$
    return LoginResult.FAIL;
  }
View Full Code Here

    }

    @Test
    public void test() throws IOException, JoranException {

        Logger logger = LoggerFactory.getLogger(this.getClass());
        MDC.clear();
        String message = "Testing empty MDC";

        // Basic Request
        logger.debug(message);
        sleep();
        lastRequest = server.lastRequest();
        assertMapEquals(makeMap(message), removeFields(lastRequest));
        assertTrue(lastRequest.containsKey("level"));
        assertTrue(lastRequest.containsKey("timestamp"));
        assertTrue(lastRequest.containsKey("host"));

        // Test with IP and requestID in MDC
        ipAddress = "87.345.23.55";
        MDC.put("ipAddress", ipAddress);
        requestID = String.valueOf(new Random().nextInt(100000));
        MDC.put("requestId", requestID);

        message = "this is a new test";
        logger.debug(message);
        sleep();
        lastRequest = server.lastRequest();
        assertMapEquals(makeMap(message), removeFields(lastRequest));
        assertTrue(lastRequest.containsKey("level"));
        assertTrue(lastRequest.containsKey("timestamp"));

        // Test substitution works
        logger.debug("this is a test with ({}) parameter", "this");
        sleep();
        lastRequest = server.lastRequest();
        assertMapEquals(makeMap("this is a test with (this) parameter"), removeFields(lastRequest));
        assertTrue(lastRequest.containsKey("level"));
        assertTrue(lastRequest.containsKey("timestamp"));

        // Test file and line are output for stack trace
        try {
            new URL("app://asdfs");
        } catch (Exception e) {
            int ln = Thread.currentThread().getStackTrace()[1].getLineNumber();
            logger.error("expected error", new IllegalStateException(e));
            sleep();
            lastRequest = server.lastRequest();
            assertEquals(ln + 1, Integer.parseInt((String) lastRequest.get("line")));
            assertEquals(this.getClass().getSimpleName() + ".java", lastRequest.get("file"));
        }

        // Test field in MDC is added even if not included in additional fields
        MDC.put("newField", "the val");
        message = "this is a test with an MDC field (new_field) that is not included in the additional fields. " +
                "However includeFullMDC is set, so it should appear in the additional fields as _newField = the val";
        logger.debug(message, "this");
        sleep();
        lastRequest = server.lastRequest();
        assertMapEquals(addField(makeMap(message), "_newField", "the val"), removeFields(lastRequest));
        assertTrue(lastRequest.containsKey("level"));
        assertTrue(lastRequest.containsKey("timestamp"));

        // Test static additional field
        message = "Testing with a static additional field";
        MDC.clear();
        ipAddress = null;
        requestID = null;
        addStaticFieldToAppender();
        logger.debug(message);
        sleep();
        lastRequest = server.lastRequest();
        assertMapEquals(addField(makeMap(message, "Testing wi"), "_node_name", "www013"), removeFields(lastRequest));
        assertTrue(lastRequest.containsKey("level"));
        assertTrue(lastRequest.containsKey("timestamp"));

        // Test field type conversion
        addTypedFieldToAppender();
        int i = new Random().nextInt(100000);
        MDC.put("requestId", String.valueOf(i));
        message = "Testing requestId as int field conversion";
        logger.debug(message);
        sleep();
        lastRequest = server.lastRequest();
        assertTrue(lastRequest.get("_request_id").getClass().getSimpleName(), lastRequest.get("_request_id") instanceof Number);
        assertEquals(i, ((Number) lastRequest.get("_request_id")).intValue());

        // Test failed type conversion
        MDC.put("requestId", "nonparseablenumber");
        message = "Testing failed requestId as int field conversion";
        logger.debug(message);
        sleep();
        lastRequest = server.lastRequest();
        assertEquals("nonparseablenumber", lastRequest.get("_request_id"));

        // Finish
        server.shutdown();
        logger.debug("This is a test with a really long ending: " + longMessage);
    }
View Full Code Here

    public void logbackSocketAppenderTest() throws InterruptedException {
        final Util.StringContainer container = Util.readLineFromPort(Util.port, Util.timeoutInMs);

        String helloChina = "Hello, \u4E2D\u570B!";

        Logger logger = LoggerFactory.getLogger("splunk.logger");
        logger.info(helloChina);

        synchronized (container) {
            container.wait(Util.timeoutInMs);
        }
View Full Code Here

TOP

Related Classes of org.slf4j.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.