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;
}
}
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;
}
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);
}
}
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);
}
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());
});
}
Aggregations