Search in sources :

Example 6 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class NeoBootstrapper method start.

@Override
public final int start(Path homeDir, Path configFile, Map<String, String> configOverrides, boolean expandCommands) {
    addShutdownHook();
    installSignalHandlers();
    Config config = Config.newBuilder().commandExpansion(expandCommands).setDefaults(GraphDatabaseSettings.SERVER_DEFAULTS).fromFileNoThrow(configFile).setRaw(configOverrides).set(GraphDatabaseSettings.neo4j_home, homeDir.toAbsolutePath()).build();
    Log4jLogProvider userLogProvider = setupLogging(config);
    userLogFileStream = userLogProvider;
    dependencies = dependencies.userLogProvider(userLogProvider);
    log = userLogProvider.getLog(getClass());
    // Log any messages written before logging was configured.
    startupLog.replayInto(log);
    config.setLogger(log);
    if (requestedMemoryExceedsAvailable(config)) {
        log.error(format("Invalid memory configuration - exceeds physical memory. Check the configured values for %s and %s", GraphDatabaseSettings.pagecache_memory.name(), BootloaderSettings.max_heap_size.name()));
        return INVALID_CONFIGURATION_ERROR_CODE;
    }
    try {
        serverAddress = HttpConnector.listen_address.toString();
        log.info("Starting...");
        databaseManagementService = createNeo(config, dependencies);
        log.info("Started.");
        return OK;
    } catch (ServerStartupException e) {
        e.describeTo(log);
        return WEB_SERVER_STARTUP_ERROR_CODE;
    } catch (TransactionFailureException tfe) {
        String locationMsg = (databaseManagementService == null) ? "" : " Another process may be using databases at location: " + config.get(GraphDatabaseInternalSettings.databases_root_path);
        log.error(format("Failed to start Neo4j on %s.", serverAddress) + locationMsg, tfe);
        return GRAPH_DATABASE_STARTUP_ERROR_CODE;
    } catch (Exception e) {
        log.error(format("Failed to start Neo4j on %s.", serverAddress), e);
        return WEB_SERVER_STARTUP_ERROR_CODE;
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Config(org.neo4j.configuration.Config) LogConfig(org.neo4j.logging.log4j.LogConfig) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Example 7 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class NeoBootstrapper method setupLogging.

private static Log4jLogProvider setupLogging(Config config) {
    LogConfig.Builder builder = LogConfig.createBuilder(new DefaultFileSystemAbstraction(), config.get(GraphDatabaseSettings.store_user_log_path), config.get(GraphDatabaseSettings.store_internal_log_level)).withTimezone(config.get(GraphDatabaseSettings.db_timezone)).withFormat(config.get(GraphDatabaseSettings.store_user_log_format)).withCategory(false).withRotation(config.get(GraphDatabaseSettings.store_user_log_rotation_threshold), config.get(GraphDatabaseSettings.store_user_log_max_archives));
    if (config.get(GraphDatabaseSettings.store_user_log_to_stdout)) {
        builder.logToSystemOut();
    }
    Neo4jLoggerContext ctx = builder.build();
    Log4jLogProvider userLogProvider = new Log4jLogProvider(ctx);
    JULBridge.resetJUL();
    Logger.getLogger("").setLevel(Level.WARNING);
    JULBridge.forwardTo(userLogProvider);
    JettyLogBridge.setLogProvider(userLogProvider);
    return userLogProvider;
}
Also used : Neo4jLoggerContext(org.neo4j.logging.log4j.Neo4jLoggerContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) LogConfig(org.neo4j.logging.log4j.LogConfig)

Example 8 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class NeoBootstrapper method switchToErrorLoggingIfLoggingNotConfigured.

/**
 * If we ran into an error before logging was properly setup we log what we have buffered and any following messages directly to System.out.
 */
private void switchToErrorLoggingIfLoggingNotConfigured() {
    // Logging isn't configured yet
    if (userLogFileStream == null) {
        Log4jLogProvider outProvider = new Log4jLogProvider(System.out);
        userLogFileStream = outProvider;
        log = outProvider.getLog(getClass());
        startupLog.replayInto(log);
    }
}
Also used : Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider)

Example 9 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class GlobalModule method createLogService.

protected LogService createLogService(LogProvider userLogProvider) {
    // Will get diagnostics as header in each newly created log file (diagnostics in the first file is printed during start up).
    Neo4jLoggerContext loggerContext = LogConfig.createBuilder(fileSystem, globalConfig.get(store_internal_log_path), globalConfig.get(store_internal_log_level)).withFormat(globalConfig.get(store_internal_log_format)).withTimezone(globalConfig.get(db_timezone)).withHeaderLogger(log -> dbmsDiagnosticsManager.dumpAll(log), DiagnosticsManager.class.getCanonicalName()).withRotation(globalConfig.get(store_internal_log_rotation_threshold), globalConfig.get(store_internal_log_max_archives)).build();
    Log4jLogProvider internalLogProvider = new Log4jLogProvider(loggerContext);
    userLogProvider = userLogProvider == null ? NullLogProvider.getInstance() : userLogProvider;
    SimpleLogService logService = new SimpleLogService(userLogProvider, internalLogProvider);
    // Listen to changes to the dynamic log level settings.
    globalConfig.addListener(store_internal_log_level, (before, after) -> internalLogProvider.updateLogLevel(after));
    // If the user log provider comes from us we make sure that it starts with the default log level and listens to updates.
    if (userLogProvider instanceof Log4jLogProvider) {
        Log4jLogProvider provider = (Log4jLogProvider) userLogProvider;
        provider.updateLogLevel(globalConfig.get(store_internal_log_level));
        globalConfig.addListener(store_internal_log_level, (before, after) -> provider.updateLogLevel(after));
    }
    return globalLife.add(logService);
}
Also used : Neo4jLoggerContext(org.neo4j.logging.log4j.Neo4jLoggerContext) DiagnosticsManager(org.neo4j.internal.diagnostics.DiagnosticsManager) DbmsDiagnosticsManager(org.neo4j.kernel.diagnostics.providers.DbmsDiagnosticsManager) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider)

Example 10 with Log4jLogProvider

use of org.neo4j.logging.log4j.Log4jLogProvider in project neo4j by neo4j.

the class ConcurrentChangesOnEntitiesTest method assertDatabaseConsistent.

private void assertDatabaseConsistent() {
    LogProvider logProvider = new Log4jLogProvider(System.out);
    assertDoesNotThrow(() -> {
        ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(databaseLayout, Config.defaults(), ProgressMonitorFactory.textual(System.err), logProvider, false);
        Assertions.assertTrue(result.isSuccessful());
    });
}
Also used : LogProvider(org.neo4j.logging.LogProvider) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService)

Aggregations

Log4jLogProvider (org.neo4j.logging.log4j.Log4jLogProvider)15 Config (org.neo4j.configuration.Config)4 Neo4jLoggerContext (org.neo4j.logging.log4j.Neo4jLoggerContext)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)3 LogConfig (org.neo4j.logging.log4j.LogConfig)3 OutputStream (java.io.OutputStream)2 Test (org.junit.jupiter.api.Test)2 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)2 Node (org.neo4j.graphdb.Node)2 Log (org.neo4j.logging.Log)2 LogProvider (org.neo4j.logging.LogProvider)2 JobScheduler (org.neo4j.scheduler.JobScheduler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Closeable (java.io.Closeable)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1