You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AuditLog.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package org.apache.archiva.audit;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.metadata.model.facets.AuditEvent;
  21. import org.apache.archiva.repository.events.AuditListener;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.stereotype.Service;
  25. /**
  26. * AuditLog - Audit Log.
  27. *
  28. *
  29. *
  30. */
  31. @Service("auditListener#logging")
  32. public class AuditLog
  33. implements AuditListener
  34. {
  35. public static final Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
  36. private static final String NONE = "-";
  37. private static final char DELIM = ' ';
  38. /**
  39. * Creates a log message in the following format ...
  40. * "{repository_id} {user_id} {remote_ip} \"{resource}\" \"{action}\""
  41. */
  42. @Override
  43. public void auditEvent( AuditEvent event )
  44. {
  45. StringBuilder msg = new StringBuilder();
  46. msg.append( checkNull( event.getRepositoryId() ) ).append( DELIM );
  47. msg.append( event.getUserId() ).append( DELIM );
  48. msg.append( checkNull( event.getRemoteIP() ) ).append( DELIM );
  49. msg.append( '\"' ).append( checkNull( event.getResource() ) ).append( '\"' ).append( DELIM );
  50. msg.append( '\"' ).append( event.getAction() ).append( '\"' );
  51. logger.info( msg.toString() );
  52. }
  53. private String checkNull( String s )
  54. {
  55. return s != null ? s : NONE;
  56. }
  57. }