Skip to content

Commit

Permalink
* added LoggingConverter
Browse files Browse the repository at this point in the history
* modified logback.xml to use of LoggingConverter
  • Loading branch information
Daniel Zabel committed Apr 17, 2013
1 parent b4c6d0e commit dff5248
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/main/java/com/coremedia/nexus/plugins/LoggingConverter.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
5 changes: 4 additions & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
<!-- always a good activate OnConsoleStatusListener -->
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>

<conversionRule conversionWord="username"
converterClass="com.coremedia.nexus.plugins.LoggingConverter" />

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/nexus-ga.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/nexus-ga.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
</rollingPolicy>

<encoder>
<pattern>combined</pattern>
<pattern>%h %l %-5username [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"</pattern>
<!--<pattern>%date %h %u "%i{Referer}" "%i{User-Agent}"</pattern>-->
</encoder>
</appender>
Expand Down

0 comments on commit dff5248

Please sign in to comment.