Skip to content
Permalink
Browse files Browse the repository at this point in the history
XWIKI-20291: Improved translations of logging administration
  • Loading branch information
manuelleduc committed Oct 28, 2022
1 parent 3376f78 commit 49fdfd6
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 15 deletions.
Expand Up @@ -62,4 +62,26 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>**/LoggingScriptServiceComponentList.class</include>
<include>**/NullLoggerManager.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,53 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.logging;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import org.xwiki.logging.script.LoggingScriptService;
import org.xwiki.test.annotation.ComponentList;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Component list for {@link LoggingScriptService}.
*
* @version $Id$
* @since 13.10.11
* @since 14.4.7
* @since 14.10RC1
*/
@Documented
@Retention(RUNTIME)
@Target({ TYPE, METHOD, ANNOTATION_TYPE })
@ComponentList({
LoggingScriptService.class,
NullLoggerManager.class
})
@Inherited
public @interface LoggingScriptServiceComponentList
{
}
@@ -0,0 +1,66 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.logging;

import java.util.Collection;

import org.slf4j.Logger;
import org.xwiki.observation.EventListener;

/**
* Null logger manager, to be overridden if need be.
*
* @version $Id$
* @since 13.10.11
* @since 14.4.7
* @since 14.10RC1
*/
public class NullLoggerManager implements LoggerManager
{
@Override
public void pushLogListener(EventListener listener)
{

}

@Override
public EventListener popLogListener()
{
return null;
}

@Override
public void setLoggerLevel(String loggerName, LogLevel level)
{

}

@Override
public LogLevel getLoggerLevel(String loggerName)
{
return null;
}

@Override
public Collection<Logger> getLoggers()
{
return null;
}
}
Expand Up @@ -80,5 +80,36 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Test dependencies. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-test-page</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- Provides the component list for RenderingScriptService. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-rendering-xwiki</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!-- Provides the component list for the LiveData macro. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-livedata-macro</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!-- Required for LoggingScriptService. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-logging-script</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,79 @@
<?xml version="1.1" encoding="UTF-8"?>

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<xwikidoc version="1.5" reference="XWiki.Logging.Code.Translations" locale="">
<web>XWiki.Logging.Code</web>
<name>Translations</name>
<language/>
<defaultLanguage>en</defaultLanguage>
<translation>0</translation>
<creator>xwiki:XWiki.Admin</creator>
<parent>WebHome</parent>
<author>xwiki:XWiki.Admin</author>
<contentAuthor>xwiki:XWiki.Admin</contentAuthor>
<version>1.1</version>
<title>Translations</title>
<comment/>
<minorEdit>false</minorEdit>
<syntaxId>plain/1.0</syntaxId>
<hidden>true</hidden>
<content>logging.admin.unsetLevel.success=Logger "{0}" level has been unset.
logging.admin.setLevel.success=Logger "{0}" level has been set to "{1}".
logging.admin.setLevel.error=Failed to set log level: the logger "{0}" doesn't exist.</content>
<object>
<name>XWiki.Logging.Code.Translations</name>
<number>0</number>
<className>XWiki.TranslationDocumentClass</className>
<guid>fc29bfac-011a-4573-80ba-3f5713f1e847</guid>
<class>
<name>XWiki.TranslationDocumentClass</name>
<customClass/>
<customMapping/>
<defaultViewSheet/>
<defaultEditSheet/>
<defaultWeb/>
<nameField/>
<validationScript/>
<scope>
<cache>0</cache>
<disabled>0</disabled>
<displayType>select</displayType>
<freeText>forbidden</freeText>
<largeStorage>0</largeStorage>
<multiSelect>0</multiSelect>
<name>scope</name>
<number>1</number>
<prettyName>Scope</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<unmodifiable>0</unmodifiable>
<values>GLOBAL|WIKI|USER|ON_DEMAND</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</scope>
</class>
<property>
<scope>WIKI</scope>
</property>
</object>
</xwikidoc>
Expand Up @@ -44,20 +44,28 @@
##
## Setting the logger level if button has been pressed ##
##
#if ($request.loggeraction_set &amp;&amp; $request.logger_name &amp;&amp; $xwiki.hasAccessLevel('programming'))
#set ($loggerName = $request.logger_name)
#set ($loggerNameEscaped = $services.rendering.escape($escapetool.java($loggerName), 'xwiki/2.1'))
#set ($loggerLevel = $request.logger_level)
#set ($loggerLevelEscaped = $services.rendering.escape($escapetool.java($loggerLevel), 'xwiki/2.1'))
#if ($request.loggeraction_set &amp;&amp; $loggerName &amp;&amp; $xwiki.hasAccessLevel('programming'))
#set($logger_list = $logging.getLevels())
#if ($!logger_list.containsKey($request.logger_name))
#if ($!logger_list.containsKey($loggerName))
#if ($request.logger_level == '')
{{success}}Logger ${request.logger_name} level has been unset.{{/success}}
#set($void = $logging.setLevel($request.logger_name, $null))
{{success}}
{{translation key='logging.admin.unsetLevel.success' parameters="~"${loggerNameEscaped}~""/}}
{{/success}}
#set($void = $logging.setLevel($loggerName, $null))
#else
{{success}}Logger ${request.logger_name} level has been set to ${request.logger_level}.{{/success}}
#set($void = $logging.setLevel($request.logger_name, $request.logger_level))
{{success}}
{{translation key='logging.admin.setLevel.success'
parameters="~"${loggerNameEscaped}~",~"${loggerLevelEscaped}~""/}}
{{/success}}
#set($void = $logging.setLevel($loggerName, $request.logger_level))
#end
#else
{{error}}Failed to set log level: the logger "$request.logger_name" doesn't exist.{{/error}}
{{error}}{{translation key='logging.admin.setLevel.error' parameters="~"${loggerNameEscaped}~""/}}{{/error}}
#end

#end
##
## Live Data
Expand All @@ -77,6 +85,7 @@
'filterable': false
}))
#end

{{liveData
id="logging"
properties="$stringtool.join($properties, ',')"
Expand Down

0 comments on commit 49fdfd6

Please sign in to comment.