Search in sources :

Example 6 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class NLS method log.

/*
	 * The method adds a log entry based on the error message and exception. 
	 * The output is written to the System.err.
	 * 
	 * This method is only expected to be called if there is a problem in
	 * the NLS mechanism. As a result, translation facility is not available 
	 * here and messages coming out of this log are generally not translated.
	 * 
	 * @param severity - severity of the message (SEVERITY_ERROR or SEVERITY_WARNING)
	 * @param message - message to log
	 * @param e - exception to log
	 */
static void log(int severity, String message, Exception e) {
    if (severity == SEVERITY_WARNING && ignoreWarnings)
        // ignoring warnings; bug 292980
        return;
    if (frameworkLog != null) {
        // $NON-NLS-1$
        frameworkLog.log(new FrameworkLogEntry("org.eclipse.osgi", severity, 1, message, 0, e, null));
        return;
    }
    String statusMsg;
    switch(severity) {
        case SEVERITY_ERROR:
            // $NON-NLS-1$
            statusMsg = "Error: ";
            break;
        case SEVERITY_WARNING:
        // intentionally fall through:
        default:
            // $NON-NLS-1$
            statusMsg = "Warning: ";
    }
    if (message != null)
        statusMsg += message;
    if (e != null)
        // $NON-NLS-1$
        statusMsg += ": " + e.getMessage();
    System.err.println(statusMsg);
    if (e != null)
        e.printStackTrace();
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 7 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EquinoxLogWriter method logged.

public void logged(LogEntry entry) {
    if (!(entry instanceof ExtendedLogEntry))
        // TODO this should never happen
        return;
    ExtendedLogEntry extended = (ExtendedLogEntry) entry;
    Object context = extended.getContext();
    if (context instanceof FrameworkLogEntry) {
        log((FrameworkLogEntry) context);
        return;
    }
    // OK we are now in a case where someone logged a normal entry to the real LogService
    log(new FrameworkLogEntry(getFwkEntryTag(entry), convertSeverity(entry.getLevel()), 0, entry.getMessage(), 0, entry.getException(), null));
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 8 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class LoggingTests method testLogService.

public void testLogService() throws BundleException {
    // Tests listeners at all levels when logged with the LogService
    // $NON-NLS-1$
    Bundle testBundle = installer.installBundle("test.logging.a");
    testBundle.start();
    BundleContext bc = testBundle.getBundleContext();
    LogServiceReference logRef = getLogService(bc);
    IStatus a = new Status(IStatus.ERROR, testBundle.getSymbolicName(), getName());
    List context = new ArrayList();
    context.add(a);
    TestILogListener iLogListener1 = new TestILogListener(new ArrayList(context));
    TestILogListener iLogListener2 = new TestILogListener(new ArrayList(context));
    TestLogListener logListener = new TestLogListener(new ArrayList(context));
    ILog testLog = Platform.getLog(testBundle);
    testLog.addLogListener(iLogListener1);
    Platform.addLogListener(iLogListener2);
    logRef.readerService.addLogListener(logListener, logListener);
    try {
        ExtendedLogService logService = logRef.logService;
        Logger logger = logService.getLogger(testBundle, EQUINOX_LOGGER);
        logger.log(a, LogService.LOG_ERROR, a.getMessage());
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        assertTrue("Missing context", logListener.waitforContext());
        iLogListener1.addContext(new ArrayList(context));
        iLogListener2.addContext(new ArrayList(context));
        logListener.addContext(new ArrayList(context));
        logger.log(new FrameworkLogEntry(a, testBundle.getSymbolicName(), a.getSeverity(), a.getCode(), a.getMessage(), 0, null, null), LogService.LOG_ERROR, a.getMessage());
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        assertTrue("Missing context", logListener.waitforContext());
        iLogListener1.addContext(new ArrayList(context));
        iLogListener2.addContext(new ArrayList(context));
        logListener.addContext(new ArrayList(context));
        logListener.entries.clear();
        logger.log(LogService.LOG_ERROR, a.getMessage());
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        // there is no status here
        assertFalse("Missing context", logListener.waitforContext());
        // but we should have received one log entry
        assertEquals("Wrong number of entries", 1, logListener.entries.size());
    } finally {
        testLog.removeLogListener(iLogListener1);
        Platform.removeLogListener(iLogListener2);
        logRef.readerService.removeLogListener(logListener);
        logRef.unget(bc);
    }
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) Logger(org.eclipse.equinox.log.Logger)

Example 9 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class LoggingTests method testBug347183.

public void testBug347183() throws BundleException {
    // test recursive logging
    // $NON-NLS-1$
    final Bundle testBundle = installer.installBundle("test.logging.a");
    testBundle.start();
    LogServiceReference logRef = getLogService(getContext());
    ILogListener recurseLog = new ILogListener() {

        public void logging(IStatus status, String plugin) {
            Platform.getLog(testBundle).log(status);
        }
    };
    Platform.addLogListener(recurseLog);
    try {
        logRef.fwkLog.log(new FrameworkLogEntry(getContext().getBundle().getSymbolicName(), FrameworkLogEntry.ERROR, 0, "Test message", 0, null, null));
        // prime the log so we don't have to create it in the logging call
        Platform.getLog(testBundle);
        logRef.fwkLog.log(new FrameworkLogEntry(getContext().getBundle().getSymbolicName(), FrameworkLogEntry.ERROR, 0, "Test message", 0, null, null));
    } finally {
        Platform.removeLogListener(recurseLog);
    }
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 10 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class LoggingTests method testFrameworkLog.

public void testFrameworkLog() throws BundleException {
    // Tests listeners at all levels when logged with the FrameworkLog
    // $NON-NLS-1$
    Bundle testBundle = installer.installBundle("test.logging.a");
    testBundle.start();
    BundleContext bc = testBundle.getBundleContext();
    LogServiceReference logRef = getLogService(bc);
    IStatus a = new Status(IStatus.ERROR, testBundle.getSymbolicName(), getName());
    List context = new ArrayList();
    context.add(a);
    TestILogListener iLogListener1 = new TestILogListener(new ArrayList(context));
    TestILogListener iLogListener2 = new TestILogListener(new ArrayList(context));
    TestLogListener logListener = new TestLogListener(new ArrayList(context));
    ILog testLog = Platform.getLog(testBundle);
    testLog.addLogListener(iLogListener1);
    Platform.addLogListener(iLogListener2);
    logRef.readerService.addLogListener(logListener, logListener);
    try {
        FrameworkLogEntry fwkLogEntry = new FrameworkLogEntry(a, testBundle.getSymbolicName(), a.getSeverity(), a.getCode(), a.getMessage(), 0, null, null);
        logRef.fwkLog.log(fwkLogEntry);
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        assertTrue("Missing context", logListener.waitforContext());
        iLogListener1.addContext(new ArrayList(context));
        iLogListener2.addContext(new ArrayList(context));
        logListener.addContext(new ArrayList(context));
        logRef.fwkLog.log(fwkLogEntry);
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        assertTrue("Missing context", logListener.waitforContext());
        iLogListener1.addContext(new ArrayList(context));
        iLogListener2.addContext(new ArrayList(context));
        logListener.addContext(new ArrayList(context));
        logListener.entries.clear();
        logRef.fwkLog.log(new FrameworkLogEntry(testBundle.getSymbolicName(), a.getSeverity(), a.getCode(), a.getMessage(), 0, null, null));
        assertTrue("Missing context", iLogListener1.waitforContext());
        assertTrue("Missing context", iLogListener2.waitforContext());
        // there is no status here
        assertFalse("Missing context", logListener.waitforContext());
        // but we should have received one log entry
        assertEquals("Wrong number of entries", 1, logListener.entries.size());
    } finally {
        testLog.removeLogListener(iLogListener1);
        Platform.removeLogListener(iLogListener2);
        logRef.readerService.removeLogListener(logListener);
        logRef.unget(bc);
    }
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Aggregations

FrameworkLogEntry (org.eclipse.osgi.framework.log.FrameworkLogEntry)16 Logger (org.eclipse.equinox.log.Logger)2 FrameworkLog (org.eclipse.osgi.framework.log.FrameworkLog)2 WeavingHookConfigurator (org.eclipse.osgi.internal.weaving.WeavingHookConfigurator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Module (org.eclipse.osgi.container.Module)1 DevClassLoadingHook (org.eclipse.osgi.internal.hooks.DevClassLoadingHook)1 EclipseLazyStarter (org.eclipse.osgi.internal.hooks.EclipseLazyStarter)1 SignedBundleHook (org.eclipse.osgi.internal.signedcontent.SignedBundleHook)1 Equinox (org.eclipse.osgi.launch.Equinox)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 Location (org.eclipse.osgi.service.datalocation.Location)1 EnvironmentInfo (org.eclipse.osgi.service.environment.EnvironmentInfo)1 Framework (org.osgi.framework.launch.Framework)1 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1 Resource (org.osgi.resource.Resource)1