如何在服务器插件中记录到 neo4j.log
作为 3.0 版本重大变更的一部分,将日志记录到用户日志(在服务器模式下现在是 neo4j.log)的方式已经改变。要在服务器插件中记录日志,请遵循以下步骤:
-
包含以下包
import org.neo4j.logging.Log;
import org.neo4j.logging.LogService;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
+ 。在服务器插件的方法中,您需要使用以下代码来使用日志记录器:
@PluginTarget(GraphDatabaseService.class)
public Iterable<String> getAllLabels(@Source GraphDatabaseService graphDb) {
LogService logService = ((GraphDatabaseAPI)graphDb).getDependencyResolver().resolveDependency( LogService.class );
Log log = logService.getUserLog( getClass() );
+ 。现在使用 log
对象的适当方法进行日志记录:
log.info( "Hello world!" );
log.debug( "Hello debuggers!" );
我们会得到一个包含如下行的日志:
2016-12-05 17:33:21.223+0000 INFO Hello world! 2016-12-05 17:33:21.345+0000 DEBUG Hello debuggers!
此页面有帮助吗?