diff --git a/src/main/java/com/coremedia/nexus/plugins/LoggingConverter.java b/src/main/java/com/coremedia/nexus/plugins/LoggingConverter.java new file mode 100644 index 0000000..a9c4544 --- /dev/null +++ b/src/main/java/com/coremedia/nexus/plugins/LoggingConverter.java @@ -0,0 +1,28 @@ +package com.coremedia.nexus.plugins; + + +import ch.qos.logback.classic.pattern.ClassicConverter; +import ch.qos.logback.classic.spi.ILoggingEvent; +import org.apache.shiro.subject.Subject; +import org.codehaus.plexus.component.annotations.Requirement; +import org.sonatype.security.SecuritySystem; + +public class LoggingConverter extends ClassicConverter { + + @Requirement + private SecuritySystem securitySystem; + + @Override + public String convert(ILoggingEvent event) { + String userName = "anonymous"; + + if (securitySystem != null) { + final Subject subject = securitySystem.getSubject(); + if (subject != null) { + userName = subject.getPrincipal().toString(); + } + } + return userName; + } + +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 482b5ee..83d330f 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -17,6 +17,9 @@ + + logs/nexus-ga.log @@ -24,7 +27,7 @@ - combined + %h %l %-5username [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"