Skip to content

Commit

Permalink
Move logging from user manager to procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Sep 12, 2016
1 parent db2bdfd commit f6b0406
Show file tree
Hide file tree
Showing 9 changed files with 717 additions and 235 deletions.
Expand Up @@ -25,11 +25,13 @@
import java.util.function.Consumer;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.security.AuthSubject;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.logging.FormattedLog;
import org.neo4j.logging.Log;
import org.neo4j.logging.Logger;

import static org.neo4j.helpers.Strings.escape;
import static org.neo4j.io.file.Files.createOrOpenAsOuputStream;
import static org.neo4j.kernel.impl.enterprise.configuration.EnterpriseEditionSettings.security_log_filename;

Expand All @@ -39,10 +41,15 @@ public class SecurityLog implements Log

SecurityLog( Config config, FileSystemAbstraction fileSystem )
{
inner = createLog( config, fileSystem );
this( createLog( config, fileSystem ) );
}

private Log createLog( Config config, FileSystemAbstraction fileSystem )
public SecurityLog( Log log )
{
inner = log;
}

private static Log createLog( Config config, FileSystemAbstraction fileSystem )
{
FormattedLog.Builder builder = FormattedLog.withUTCTimeZone();
File logFile = config.get( security_log_filename );
Expand All @@ -58,6 +65,11 @@ private Log createLog( Config config, FileSystemAbstraction fileSystem )
return builder.toOutputStream( ouputStream );
}

private static String withSubject( AuthSubject subject, String msg )
{
return "[" + escape( subject.username() ) + "]: " + msg;
}

@Override
public boolean isDebugEnabled()
{
Expand Down Expand Up @@ -88,6 +100,11 @@ public void debug( String format, Object... arguments )
inner.debug( format, arguments );
}

public void debug( AuthSubject subject, String format, Object... arguments )
{
inner.debug( withSubject( subject, format ), arguments );
}

@Override
public Logger infoLogger()
{
Expand All @@ -112,6 +129,16 @@ public void info( String format, Object... arguments )
inner.info( format, arguments );
}

public void info( AuthSubject subject, String format, Object... arguments )
{
inner.info( withSubject( subject, format ), arguments );
}

public void info( AuthSubject subject, String format )
{
inner.info( withSubject( subject, format ) );
}

@Override
public Logger warnLogger()
{
Expand All @@ -136,6 +163,11 @@ public void warn( String format, Object... arguments )
inner.warn( format, arguments );
}

public void warn( AuthSubject subject, String format, Object... arguments )
{
inner.warn( withSubject( subject, format ), arguments );
}

@Override
public Logger errorLogger()
{
Expand All @@ -160,6 +192,11 @@ public void error( String format, Object... arguments )
inner.error( format, arguments );
}

public void error( AuthSubject subject, String format, Object... arguments )
{
inner.error( withSubject( subject, format ), arguments );
}

@Override
public void bulk( Consumer<Log> consumer )
{
Expand Down

0 comments on commit f6b0406

Please sign in to comment.