mirror of https://github.com/apache/archiva.git
add a remote log to log from javascript to server log
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1436858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fc0b17de62
commit
2f96f5acee
|
@ -0,0 +1,80 @@
|
||||||
|
package org.apache.archiva.web.api;
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.archiva.web.model.JavascriptLog;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
* @since 1.4-M4
|
||||||
|
*/
|
||||||
|
@Service( "javascriptLogger#default" )
|
||||||
|
public class DefaultJavascriptLogger
|
||||||
|
implements JavascriptLogger
|
||||||
|
{
|
||||||
|
private Logger logger = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
|
public Boolean trace( JavascriptLog javascriptLog )
|
||||||
|
{
|
||||||
|
Logger toUse =
|
||||||
|
javascriptLog.getLoggerName() == null ? logger : LoggerFactory.getLogger( javascriptLog.getLoggerName() );
|
||||||
|
|
||||||
|
toUse.trace( javascriptLog.getMessage() );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean debug( JavascriptLog javascriptLog )
|
||||||
|
{
|
||||||
|
Logger toUse =
|
||||||
|
javascriptLog.getLoggerName() == null ? logger : LoggerFactory.getLogger( javascriptLog.getLoggerName() );
|
||||||
|
|
||||||
|
toUse.debug( javascriptLog.getMessage() );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean info( JavascriptLog javascriptLog )
|
||||||
|
{
|
||||||
|
Logger toUse =
|
||||||
|
javascriptLog.getLoggerName() == null ? logger : LoggerFactory.getLogger( javascriptLog.getLoggerName() );
|
||||||
|
|
||||||
|
toUse.info( javascriptLog.getMessage() );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean warn( JavascriptLog javascriptLog )
|
||||||
|
{
|
||||||
|
Logger toUse =
|
||||||
|
javascriptLog.getLoggerName() == null ? logger : LoggerFactory.getLogger( javascriptLog.getLoggerName() );
|
||||||
|
|
||||||
|
toUse.warn( javascriptLog.getMessage() );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean error( JavascriptLog javascriptLog )
|
||||||
|
{
|
||||||
|
Logger toUse =
|
||||||
|
javascriptLog.getLoggerName() == null ? logger : LoggerFactory.getLogger( javascriptLog.getLoggerName() );
|
||||||
|
|
||||||
|
toUse.error( javascriptLog.getMessage() );
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.apache.archiva.web.api;
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.archiva.redback.authorization.RedbackAuthorization;
|
||||||
|
import org.apache.archiva.web.model.JavascriptLog;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
* @since 1.4-M4
|
||||||
|
*/
|
||||||
|
@Path( "/javascriptLogger/" )
|
||||||
|
public interface JavascriptLogger
|
||||||
|
{
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path( "trace" )
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( noRestriction = true, noPermission = true)
|
||||||
|
Boolean trace( JavascriptLog javascriptLog );
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path( "debug" )
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( noRestriction = true, noPermission = true)
|
||||||
|
Boolean debug( JavascriptLog javascriptLog );
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path( "info" )
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( noRestriction = true, noPermission = true)
|
||||||
|
Boolean info( JavascriptLog javascriptLog );
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path( "warn" )
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( noRestriction = true, noPermission = true)
|
||||||
|
Boolean warn( JavascriptLog javascriptLog );
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path( "error" )
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
|
@RedbackAuthorization( noRestriction = true, noPermission = true)
|
||||||
|
Boolean error( JavascriptLog javascriptLog );
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package org.apache.archiva.web.model;
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
* @since 1.4-M4
|
||||||
|
*/
|
||||||
|
@XmlRootElement( name = "javascriptLog" )
|
||||||
|
public class JavascriptLog
|
||||||
|
implements Serializable
|
||||||
|
{
|
||||||
|
|
||||||
|
private String loggerName;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public JavascriptLog()
|
||||||
|
{
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoggerName()
|
||||||
|
{
|
||||||
|
return loggerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoggerName( String loggerName )
|
||||||
|
{
|
||||||
|
this.loggerName = loggerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage( String message )
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append( "JavascriptLog" );
|
||||||
|
sb.append( "{loggerName='" ).append( loggerName ).append( '\'' );
|
||||||
|
sb.append( ", message='" ).append( message ).append( '\'' );
|
||||||
|
sb.append( '}' );
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,7 @@
|
||||||
<ref bean="runtimeInfoService#rest"/>
|
<ref bean="runtimeInfoService#rest"/>
|
||||||
<ref bean="dataValidatorService#rest"/>
|
<ref bean="dataValidatorService#rest"/>
|
||||||
<ref bean="fileUploadService#rest"/>
|
<ref bean="fileUploadService#rest"/>
|
||||||
|
<ref bean="javascriptLogger#default"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
|
|
||||||
<jaxrs:outInterceptors>
|
<jaxrs:outInterceptors>
|
||||||
|
|
|
@ -495,6 +495,53 @@ require(["jquery","jquery.tmpl","i18n","knockout"], function(jquery,jqueryTmpl,i
|
||||||
mainContent.find(".tooltip-doc" ).tooltip({html: true, trigger: 'hover'});
|
mainContent.find(".tooltip-doc" ).tooltip({html: true, trigger: 'hover'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
// remote logging
|
||||||
|
//------------------------------------
|
||||||
|
JavascriptLog=function(loggerName,message){
|
||||||
|
this.loggerName=loggerName;
|
||||||
|
this.message=message;
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteLogTrace=function(loggerName,message){
|
||||||
|
var javascriptLog=new JavascriptLog(loggerName,message);
|
||||||
|
remoteLog("trace",javascriptLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteLogDebug=function(loggerName,message){
|
||||||
|
var javascriptLog=new JavascriptLog(loggerName,message);
|
||||||
|
remoteLog("debug",javascriptLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteLogInfo=function(loggerName,message){
|
||||||
|
var javascriptLog=new JavascriptLog(loggerName,message);
|
||||||
|
remoteLog("info",javascriptLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteLogWarn=function(loggerName,message){
|
||||||
|
var javascriptLog=new JavascriptLog(loggerName,message);
|
||||||
|
remoteLog("warn",javascriptLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteLogError=function(loggerName,message){
|
||||||
|
var javascriptLog=new JavascriptLog(loggerName,message);
|
||||||
|
remoteLog("error",javascriptLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param level trace/debug/info/warn/error
|
||||||
|
* @param javascriptLog
|
||||||
|
*/
|
||||||
|
remoteLog=function(level,javascriptLog){
|
||||||
|
$.ajax("restServices/archivaUiServices/javascriptLogger/"+level,{
|
||||||
|
type: "PUT",
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: $.toJSON(javascriptLog)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
// extends jquery tmpl to support var def
|
// extends jquery tmpl to support var def
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue