From b416c3b4656da735301ce0ca1896b1785b4f4926 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Tue, 25 Apr 2017 16:31:03 +0200 Subject: [PATCH 01/13] First version of log4j-snapshot-create webscript --- .../log4j-snapshot-create.get.desc.xml | 11 +++++++ .../log4j-snapshot-create.get.js | 27 +++++++++++++++ .../log4j-snapshot-create.get.json.ftl | 29 ++++++++++++++++ .../admin/ootbee-support-tools/log4j.lib.js | 33 +++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.desc.xml create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.desc.xml b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.desc.xml new file mode 100644 index 00000000..687786d9 --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.desc.xml @@ -0,0 +1,11 @@ + + + Log4J Settings - Log File - Create Snapshot + Accesses a specific Log4J log file + /ootbee/admin/log4j-snapshot-create + admin + + internal + none + OOTBee Support Tools + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js new file mode 100644 index 00000000..4e4bba31 --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js @@ -0,0 +1,27 @@ + + +/** + * Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell + * Copyright (C) 2016 Order of the Bee + * + * This file is part of Community Support Tools + * + * Community Support Tools 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 3 of the License, or + * (at your option) any later version. + * + * Community Support Tools 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 Community Support Tools. If not, see . + */ +/* + * Linked to Alfresco + * Copyright (C) 2005-2016 Alfresco Software Limited. + */ + +model.snapshotLogFile = createSnapshot(); \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl new file mode 100644 index 00000000..4494d691 --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl @@ -0,0 +1,29 @@ +<#compress> +<#-- +Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell +Copyright (C) 2016 Order of the Bee + +This file is part of Community Support Tools + +Community Support Tools 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 3 of the License, or +(at your option) any later version. + +Community Support Tools 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 Community Support Tools. If not, see . + +Linked to Alfresco +Copyright (C) 2005-2016 Alfresco Software Limited. + +--> + +{ + "snapshotLogFile": "${snapshotLogFile}", +} + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 0cd62d85..cda6b2c9 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -420,3 +420,36 @@ function buildLogFilesModel(useAllLoggerAppenders) model.logFiles = logFiles; model.locale = Packages.org.springframework.extensions.surf.util.I18NUtil.getLocale().toString(); } + +function getLoggersToSnapshot() { + var logger, loggers, currentLoggers, loggerRepository; + + logger = Packages.org.apache.log4j.Logger.getRootLogger(); + loggers = [logger]; + + loggerRepository = Packages.org.apache.log4j.LogManager.getLoggerRepository(); + currentLoggers = loggerRepository.currentLoggers; + while (currentLoggers.hasMoreElements()) + { + logger = currentLoggers.nextElement(); + if (!logger.additivity) { + loggers.push(logger); + } + } + return loggers; +} + +/* exported createSnapshot */ +function createSnapshot() { + var snapshotLogFile, logLayout, snapshotAppender, loggers; + + snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", "log"); + logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); + snapshotAppender = new Packages.org.apache.log4j.FileAppender(logLayout, snapshotLogFile); + loggers = getLoggersToSnapshot(); + loggers.forEach(function(logger) { + logger.addAppender(snapshotAppender); + }); + + return snapshotLogFile; +} \ No newline at end of file From 0d25c38e596fefe306421ad6f7dd2b093ca39aa5 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Tue, 25 Apr 2017 16:41:44 +0200 Subject: [PATCH 02/13] Spaces to tab --- .../support-tools/admin/ootbee-support-tools/log4j.lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index cda6b2c9..8f24a486 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -444,7 +444,7 @@ function createSnapshot() { var snapshotLogFile, logLayout, snapshotAppender, loggers; snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", "log"); - logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); + logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); snapshotAppender = new Packages.org.apache.log4j.FileAppender(logLayout, snapshotLogFile); loggers = getLoggersToSnapshot(); loggers.forEach(function(logger) { From 56b14bb2a6743524553a34a587550b28335553db Mon Sep 17 00:00:00 2001 From: Michael Bui Date: Tue, 25 Apr 2017 17:01:08 +0200 Subject: [PATCH 03/13] Minor fix, removed a faulty comma in JSON-response --- .../ootbee-support-tools/log4j-snapshot-create.get.json.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl index 4494d691..746c95bc 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl @@ -24,6 +24,6 @@ Copyright (C) 2005-2016 Alfresco Software Limited. --> { - "snapshotLogFile": "${snapshotLogFile}", + "snapshotLogFile": "${snapshotLogFile}" } \ No newline at end of file From 25a60132aca19d29f2dbd45a2277d5584fc7c68d Mon Sep 17 00:00:00 2001 From: amgouveia Date: Tue, 25 Apr 2017 17:50:42 +0200 Subject: [PATCH 04/13] First version of log4j-snapshot-complete webscript --- .../module-context.xml | 5 + .../log4j-snapshot-complete.get.desc.xml | 10 ++ .../admin/ootbee-support-tools/log4j.lib.js | 4 +- .../repo/web/scripts/LogSnapshotComplete.java | 114 ++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-complete.get.desc.xml create mode 100644 repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java diff --git a/repository/src/main/amp/config/alfresco/module/ootbee-support-tools-repo/module-context.xml b/repository/src/main/amp/config/alfresco/module/ootbee-support-tools-repo/module-context.xml index baab4eae..2d3d41a2 100644 --- a/repository/src/main/amp/config/alfresco/module/ootbee-support-tools-repo/module-context.xml +++ b/repository/src/main/amp/config/alfresco/module/ootbee-support-tools-repo/module-context.xml @@ -38,4 +38,9 @@ + + + + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-complete.get.desc.xml b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-complete.get.desc.xml new file mode 100644 index 00000000..5b8ae3fc --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-complete.get.desc.xml @@ -0,0 +1,10 @@ + + + Log4J Snapshot + Finish log snapshot and shows it + /ootbee/admin/log4j-snapshot-complete/{path} + admin + internal + none + OOTBee Support Tools + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 8f24a486..15ca50e6 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -443,7 +443,7 @@ function getLoggersToSnapshot() { function createSnapshot() { var snapshotLogFile, logLayout, snapshotAppender, loggers; - snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", "log"); + snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", ".log"); logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); snapshotAppender = new Packages.org.apache.log4j.FileAppender(logLayout, snapshotLogFile); loggers = getLoggersToSnapshot(); @@ -452,4 +452,4 @@ function createSnapshot() { }); return snapshotLogFile; -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java new file mode 100644 index 00000000..053cdc61 --- /dev/null +++ b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java @@ -0,0 +1,114 @@ +/** + * Copyright (C) 2016 Order of the Bee + * + * This file is part of Community Support Tools + * + * Community Support Tools 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 3 of the License, + * or (at your option) any later version. + * + * Community Support Tools 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 Community Support Tools. If not, see + * . + */ +package org.orderofthebee.addons.support.tools.repo.web.scripts; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.web.scripts.content.ContentStreamer; +import org.apache.log4j.Appender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; + +/** + * @author Ana Gouveia + */ +public class LogSnapshotComplete extends AbstractLogFileWebScript +{ + protected ContentStreamer delegate; + + /** + * @param delegate + * ContentStreamer + */ + public void setDelegate(final ContentStreamer delegate) + { + this.delegate = delegate; + } + + /** + * Gets the appender, removes it from all the loggers and streams the content back. + * + * {@inheritDoc} + */ + @Override + @SuppressWarnings("rawtypes") + public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException + { + final String servicePath = req.getServicePath(); + final String matchPath = req.getServiceMatch().getPath(); + final String fileAppenderPath = servicePath.substring(servicePath.indexOf(matchPath) + matchPath.length()); + + final Map model = new HashMap(); + final Status status = new Status(); + final Cache cache = new Cache(this.getDescription().getRequiredCache()); + model.put("status", status); + model.put("cache", cache); + + final String attachParam = req.getParameter("a"); + final boolean attach = attachParam != null && Boolean.parseBoolean(attachParam); + + Enumeration appenders = Logger.getRootLogger().getAllAppenders(); + FileAppender snapshotAppender = null; + + while (appenders.hasMoreElements()) + { + Appender appender = (Appender) appenders.nextElement(); + if (appender instanceof FileAppender) + { + FileAppender fileAppender = (FileAppender) appender; + if (fileAppender.getFile().equals(fileAppenderPath)) + { + snapshotAppender = fileAppender; + } + } + } + + if (snapshotAppender != null) + { + final File file = this.validateFilePath(snapshotAppender.getFile()); + this.delegate.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model); + + Enumeration loggers = LogManager.getCurrentLoggers(); + while (loggers.hasMoreElements()) + { + Logger logger = (Logger) loggers.nextElement(); + Enumeration logAppenders = logger.getAllAppenders(); + while (logAppenders.hasMoreElements()) + { + Appender appender = (Appender) logAppenders.nextElement(); + if (appender instanceof FileAppender && ((FileAppender) appender).getFile().equals(fileAppenderPath)) + { + logger.removeAppender(appender); + } + } + } + Logger.getRootLogger().removeAppender(snapshotAppender); + } + } +} From 738d044396c3d40e0171081cb67363523a21f7a0 Mon Sep 17 00:00:00 2001 From: Michael Bui Date: Tue, 25 Apr 2017 18:11:31 +0200 Subject: [PATCH 05/13] Impl. GUI for log snapshot --- .../log4j-loggers.get.html.ftl | 14 ++++++--- .../log4j-loggers.get.properties | 2 ++ .../admin/ootbee-support-tools/log4j.lib.js | 2 +- .../ootbee-support-tools/js/log-settings.js | 30 +++++++++++++++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index 30e9d7ba..bf2ef467 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -54,10 +54,16 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
- <@button id="tailRepoLog" label=msg("log-settings.tail") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-tail');")/> - <@button id="showLogFiles" label=msg("log-settings.logFiles") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-log-files');")/> - <@button id="resetLogSettings" label=msg("log-settings.resetAll") onclick=("AdminLS.resetLogLevel();")/> - <@button id="toggleView" label=msg(showUnconfiguredLoggers?string('log-settings.hideUnconfigured', 'log-settings.showUnconfigured')) onclick=("window.location.href = '" + url.serviceContext + "/ootbee/admin/log4j-loggers?showUnconfiguredLoggers="+ (showUnconfiguredLoggers!false)?string('false','true') + "';")/> +
+ <@button id="tailRepoLog" label=msg("log-settings.tail") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-tail');")/> + <@button id="showLogFiles" label=msg("log-settings.logFiles") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-log-files');")/> + <@button id="resetLogSettings" label=msg("log-settings.resetAll") onclick=("AdminLS.resetLogLevel();")/> + <@button id="toggleView" label=msg(showUnconfiguredLoggers?string('log-settings.hideUnconfigured', 'log-settings.showUnconfigured')) onclick=("window.location.href = '" + url.serviceContext + "/ootbee/admin/log4j-loggers?showUnconfiguredLoggers="+ (showUnconfiguredLoggers!false)?string('false','true') + "';")/> +
+
+ <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> + <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> +
<#if statusMessage?? && statusMessage != "">
${.now?string("HH:mm:ss")} - ${statusMessage?html!""} [X]
diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties index 33c2769d..57895b0f 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties @@ -8,6 +8,8 @@ log-settings.reset=Reset log-settings.hideUnconfigured=Hide unconfigured Loggers log-settings.showUnconfigured=Show unconfigured Loggers log-settings.rootLogger=(Root Logger) +log-settings.startLogSnapshot=Start log Snapshot +log-settings.stopLogSnapshot=Stop log Snapshot log-settings.column.add=Add log-settings.column.addLogger=Add logger diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 15ca50e6..3962d8af 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -452,4 +452,4 @@ function createSnapshot() { }); return snapshotLogFile; -} +} \ No newline at end of file diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index 3318e85b..5a6a2b40 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -33,7 +33,8 @@ var AdminLS = AdminLS || {}; (function() { var serviceContext; - + var snapshotLogFile; + AdminLS.setServiceContext = function setServiceContext(context) { serviceContext = context; @@ -51,5 +52,30 @@ var AdminLS = AdminLS || {}; } }); }; - + + AdminLS.startLogSnapshot = function startLogSnapshot() + { + Admin.request({ + url : serviceContext + '/ootbee/admin/log4j-snapshot-create', + method : 'GET', + fnSuccess : function startLogSnapshot_success(res) + { + if (res.responseText) + { + var json = JSON.parse(res.responseText); + json = res.responseJSON; + snapshotLogFile = json.snapshotLogFile; + document.getElementById("startLogSnapshot").style.display = 'none'; + document.getElementById("stopLogSnapshot").style.display = 'inline'; + } + } + }); + }; + + AdminLS.stopLogSnapshot = function stopLogSnapshot() + { + window.open(serviceContext + '/ootbee/admin/log4j-snapshot-complete/'+snapshotLogFile,'_blank'); + document.getElementById("startLogSnapshot").style.display = 'inline'; + document.getElementById("stopLogSnapshot").style.display = 'none'; + }; }()); From 765a680383301214ddf6fb8ca5410fb220822d6f Mon Sep 17 00:00:00 2001 From: Michael Bui Date: Thu, 27 Apr 2017 00:10:44 +0200 Subject: [PATCH 06/13] Log snapshot is directly downloaded instead of opened in a new tab + code styling --- .../log4j-loggers.get.html.ftl | 12 +++---- .../ootbee-support-tools/js/log-settings.js | 36 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index bf2ef467..fc306732 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -54,16 +54,16 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
-
+
<@button id="tailRepoLog" label=msg("log-settings.tail") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-tail');")/> <@button id="showLogFiles" label=msg("log-settings.logFiles") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-log-files');")/> <@button id="resetLogSettings" label=msg("log-settings.resetAll") onclick=("AdminLS.resetLogLevel();")/> <@button id="toggleView" label=msg(showUnconfiguredLoggers?string('log-settings.hideUnconfigured', 'log-settings.showUnconfigured')) onclick=("window.location.href = '" + url.serviceContext + "/ootbee/admin/log4j-loggers?showUnconfiguredLoggers="+ (showUnconfiguredLoggers!false)?string('false','true') + "';")/> -
-
- <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> - <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> -
+
+
+ <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> + <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> +
<#if statusMessage?? && statusMessage != "">
${.now?string("HH:mm:ss")} - ${statusMessage?html!""} [X]
diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index 5a6a2b40..5d774ec6 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -55,27 +55,27 @@ var AdminLS = AdminLS || {}; AdminLS.startLogSnapshot = function startLogSnapshot() { - Admin.request({ - url : serviceContext + '/ootbee/admin/log4j-snapshot-create', - method : 'GET', - fnSuccess : function startLogSnapshot_success(res) - { - if (res.responseText) - { - var json = JSON.parse(res.responseText); - json = res.responseJSON; - snapshotLogFile = json.snapshotLogFile; - document.getElementById("startLogSnapshot").style.display = 'none'; - document.getElementById("stopLogSnapshot").style.display = 'inline'; - } - } - }); + Admin.request({ + url : serviceContext + '/ootbee/admin/log4j-snapshot-create', + method : 'GET', + fnSuccess : function startLogSnapshot_success(res) + { + if (res.responseText) + { + var json = JSON.parse(res.responseText); + json = res.responseJSON; + snapshotLogFile = json.snapshotLogFile; + document.getElementById("startLogSnapshot").style.display = 'none'; + document.getElementById("stopLogSnapshot").style.display = 'inline'; + } + } + }); }; AdminLS.stopLogSnapshot = function stopLogSnapshot() { - window.open(serviceContext + '/ootbee/admin/log4j-snapshot-complete/'+snapshotLogFile,'_blank'); - document.getElementById("startLogSnapshot").style.display = 'inline'; - document.getElementById("stopLogSnapshot").style.display = 'none'; + window.open(serviceContext + '/ootbee/admin/log4j-snapshot-complete/'+snapshotLogFile+'?a=true','_blank'); + document.getElementById("startLogSnapshot").style.display = 'inline'; + document.getElementById("stopLogSnapshot").style.display = 'none'; }; }()); From c03b3fb5fd09a99471b8e44b1093d31f6b061286 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 15:36:34 -0600 Subject: [PATCH 07/13] Initial snapshot lap feature --- .../log4j-loggers.get.html.ftl | 2 ++ .../log4j-loggers.get.properties | 2 ++ .../log4j-snapshot-lap.post.desc.xml | 11 ++++++++ .../log4j-snapshot-lap.post.js | 27 ++++++++++++++++++ .../log4j-snapshot-lap.post.json.ftl | 26 +++++++++++++++++ .../admin/ootbee-support-tools/log4j.lib.js | 27 ++++++++++++++---- .../ootbee-support-tools/js/log-settings.js | 28 +++++++++++++++++-- 7 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.desc.xml create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js create mode 100644 repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index fc306732..3fe9a7d6 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -63,6 +63,8 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
<@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> + <@button id="lapLogSnapshot" style="display:none" label=msg("log-settings.lapLogSnapshot") onclick=("AdminLS.lapLogSnapshot();")/> +
<#if statusMessage?? && statusMessage != ""> diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties index 57895b0f..e6d46dad 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties @@ -10,6 +10,8 @@ log-settings.showUnconfigured=Show unconfigured Loggers log-settings.rootLogger=(Root Logger) log-settings.startLogSnapshot=Start log Snapshot log-settings.stopLogSnapshot=Stop log Snapshot +log-settings.lapLogSnapshot=Add log entry +log-settings.lapMessageLogSnapshot=If not set, lap number is logged log-settings.column.add=Add log-settings.column.addLogger=Add logger diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.desc.xml b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.desc.xml new file mode 100644 index 00000000..6871ece0 --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.desc.xml @@ -0,0 +1,11 @@ + + + Log4J Snapshot Lap + Log4J Snapshot Log Lap Message + /ootbee/admin/log4j-snapshot-lap?message={message} + + admin + internal + none + OOTBee Support Tools + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js new file mode 100644 index 00000000..b2f4d32b --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js @@ -0,0 +1,27 @@ + + +/** + * Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell + * Copyright (C) 2016 Order of the Bee + * + * This file is part of Community Support Tools + * + * Community Support Tools 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 3 of the License, or + * (at your option) any later version. + * + * Community Support Tools 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 Community Support Tools. If not, see . + */ +/* + * Linked to Alfresco + * Copyright (C) 2005-2016 Alfresco Software Limited. + */ + +logSnapshotLapMessage(args['message']); diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl new file mode 100644 index 00000000..333a1bcc --- /dev/null +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl @@ -0,0 +1,26 @@ +<#compress> +<#-- +Copyright (C) 2016 Axel Faust / Bindu Wavell +Copyright (C) 2016 Order of the Bee + +This file is part of Community Support Tools + +Community Support Tools 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 3 of the License, or +(at your option) any later version. + +Community Support Tools 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 Community Support Tools. If not, see . + +Linked to Alfresco +Copyright (C) 2005-2016 Alfresco Software Limited. + + --> +{} + \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 3962d8af..2c69bada 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -421,7 +421,8 @@ function buildLogFilesModel(useAllLoggerAppenders) model.locale = Packages.org.springframework.extensions.surf.util.I18NUtil.getLocale().toString(); } -function getLoggersToSnapshot() { +function getLoggersToSnapshot() +{ var logger, loggers, currentLoggers, loggerRepository; logger = Packages.org.apache.log4j.Logger.getRootLogger(); @@ -432,7 +433,8 @@ function getLoggersToSnapshot() { while (currentLoggers.hasMoreElements()) { logger = currentLoggers.nextElement(); - if (!logger.additivity) { + if (!logger.additivity) + { loggers.push(logger); } } @@ -440,7 +442,8 @@ function getLoggersToSnapshot() { } /* exported createSnapshot */ -function createSnapshot() { +function createSnapshot() +{ var snapshotLogFile, logLayout, snapshotAppender, loggers; snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", ".log"); @@ -448,8 +451,22 @@ function createSnapshot() { snapshotAppender = new Packages.org.apache.log4j.FileAppender(logLayout, snapshotLogFile); loggers = getLoggersToSnapshot(); loggers.forEach(function(logger) { - logger.addAppender(snapshotAppender); - }); + logger.addAppender(snapshotAppender); + } ); return snapshotLogFile; +} + +/* exported logSnapshotLapMessage */ +function logSnapshotLapMessage(message) { + var root, clazz, level, lapLogger; + + root = Packages.org.apache.log4j.Logger.getRootLogger(); + level = Packages.org.apache.log4j.Level.INFO; + // Fake logger that produces a good log message with the Alfresco default log format + clazz = 'org.orderofthebee.addons.supporttools.logsnapshot.Lap'; + lapLogger = root.getLogger(clazz); + lapLogger.setLevel(level); + + lapLogger.log(level, message); } \ No newline at end of file diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index 5d774ec6..50e57d63 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -34,6 +34,7 @@ var AdminLS = AdminLS || {}; { var serviceContext; var snapshotLogFile; + var snapshotLapNumber; AdminLS.setServiceContext = function setServiceContext(context) { @@ -62,11 +63,12 @@ var AdminLS = AdminLS || {}; { if (res.responseText) { - var json = JSON.parse(res.responseText); - json = res.responseJSON; - snapshotLogFile = json.snapshotLogFile; + snapshotLogFile = res.responseJSON.snapshotLogFile; document.getElementById("startLogSnapshot").style.display = 'none'; document.getElementById("stopLogSnapshot").style.display = 'inline'; + document.getElementById("lapLogSnapshot").style.display = 'inline'; + document.getElementById("lapMessageLogSnapshot").style.display = 'inline'; + snapshotLapNumber = 1; } } }); @@ -77,5 +79,25 @@ var AdminLS = AdminLS || {}; window.open(serviceContext + '/ootbee/admin/log4j-snapshot-complete/'+snapshotLogFile+'?a=true','_blank'); document.getElementById("startLogSnapshot").style.display = 'inline'; document.getElementById("stopLogSnapshot").style.display = 'none'; + document.getElementById("lapLogSnapshot").style.display = 'none'; + document.getElementById("lapMessageLogSnapshot").style.display = 'none'; + }; + + AdminLS.lapLogSnapshot = function lapLogSnapshot() + { + var inputEl = document.getElementById("lapMessageLogSnapshot"); + var message = inputEl.value; + if (!message) + { + message = snapshotLapNumber++; + } + Admin.request({ + url : serviceContext + '/ootbee/admin/log4j-snapshot-lap?message=' + message, + method : 'POST', + fnSuccess : function lapLogSnapshot_success() + { + inputEl.value = ''; + } + }); }; }()); From a83efd75e3e06e344fded9a68bf412682c71400f Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 15:52:51 -0600 Subject: [PATCH 08/13] Allow keyboard control of lap triggering --- .../ootbee-support-tools/log4j-loggers.get.html.ftl | 2 +- .../amp/web/ootbee-support-tools/js/log-settings.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index 3fe9a7d6..f1f3730b 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -64,7 +64,7 @@ Copyright (C) 2005-2016 Alfresco Software Limited. <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> <@button id="lapLogSnapshot" style="display:none" label=msg("log-settings.lapLogSnapshot") onclick=("AdminLS.lapLogSnapshot();")/> - + <#if statusMessage?? && statusMessage != ""> diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index 50e57d63..e93027bc 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -68,6 +68,7 @@ var AdminLS = AdminLS || {}; document.getElementById("stopLogSnapshot").style.display = 'inline'; document.getElementById("lapLogSnapshot").style.display = 'inline'; document.getElementById("lapMessageLogSnapshot").style.display = 'inline'; + document.getElementById("lapMessageLogSnapshot").focus(); snapshotLapNumber = 1; } } @@ -97,7 +98,18 @@ var AdminLS = AdminLS || {}; fnSuccess : function lapLogSnapshot_success() { inputEl.value = ''; + inputEl.focus(); } }); }; + + AdminLS.handleLogMessageLogSnapshotKeyUp = function handleLogMessageLogSnapshotKeyUp(event) + { + if (event.keyCode == 13) { + event.preventDefault(); + document.getElementById("lapLogSnapshot").click(); + return false; + } + return true; + } }()); From 294f8831effa58a6ec11a8870ea8cedefca38512 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 16:03:23 -0600 Subject: [PATCH 09/13] Escape in lap text box completes snapshot and triggers log download --- .../amp/web/ootbee-support-tools/js/log-settings.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index e93027bc..d1b15d28 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -32,6 +32,9 @@ var AdminLS = AdminLS || {}; (function() { + var KEYCODE_ENTER = 13; + var KEYCODE_ESC = 27; + var serviceContext; var snapshotLogFile; var snapshotLapNumber; @@ -105,11 +108,16 @@ var AdminLS = AdminLS || {}; AdminLS.handleLogMessageLogSnapshotKeyUp = function handleLogMessageLogSnapshotKeyUp(event) { - if (event.keyCode == 13) { + if (event.keyCode == KEYCODE_ENTER) { event.preventDefault(); document.getElementById("lapLogSnapshot").click(); return false; } + if (event.keyCode == KEYCODE_ESC) { + event.preventDefault(); + document.getElementById("stopLogSnapshot").click(); + return false; + } return true; } }()); From 864dc70653e927aad1385feee95dec23c3a293cc Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 16:33:20 -0600 Subject: [PATCH 10/13] Improved layout for text boxes on log settings tab --- .../admin/ootbee-support-tools/log4j-loggers.get.html.ftl | 4 ++-- .../src/main/amp/web/ootbee-support-tools/css/admin.css | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index f1f3730b..e9bbfab5 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -39,7 +39,7 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
${msg("log-settings.column.addLogger")}:
- + +
<#if statusMessage?? && statusMessage != ""> diff --git a/repository/src/main/amp/web/ootbee-support-tools/css/admin.css b/repository/src/main/amp/web/ootbee-support-tools/css/admin.css index 3a421216..afd9784f 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/css/admin.css +++ b/repository/src/main/amp/web/ootbee-support-tools/css/admin.css @@ -64,4 +64,11 @@ table.results.dataTable table.data td.numericalCellValue { text-align: right; +} + +input[type="text"] +{ + height: 24px; + padding-left: 5px; + padding-right: 5px; } \ No newline at end of file From 669b92fd53ae849a8f95ee84029a6eeb8ff2c9c0 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 19:25:58 -0600 Subject: [PATCH 11/13] Fix a jslint issue that missed previous commit --- .../main/amp/web/ootbee-support-tools/js/log-settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index d1b15d28..2b54a3c8 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -108,16 +108,16 @@ var AdminLS = AdminLS || {}; AdminLS.handleLogMessageLogSnapshotKeyUp = function handleLogMessageLogSnapshotKeyUp(event) { - if (event.keyCode == KEYCODE_ENTER) { + if (event.keyCode === KEYCODE_ENTER) { event.preventDefault(); document.getElementById("lapLogSnapshot").click(); return false; } - if (event.keyCode == KEYCODE_ESC) { + if (event.keyCode === KEYCODE_ESC) { event.preventDefault(); document.getElementById("stopLogSnapshot").click(); return false; } return true; - } + }; }()); From 84898d9ead17933f6dd198982aacd6a7af50614d Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 6 May 2017 19:26:25 -0600 Subject: [PATCH 12/13] TemporaryFileAppender lives for 20m or less We use this so snapshot logs don't get leaked. Also allow downloading of as much of a log as was captured even after it has been deregistered and closed. --- .../admin/ootbee-support-tools/log4j.lib.js | 4 +- .../tools/repo/TemporaryFileAppender.java | 97 +++++++++++++++++++ .../repo/web/scripts/LogSnapshotComplete.java | 82 ++++++++-------- 3 files changed, 142 insertions(+), 41 deletions(-) create mode 100644 repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 2c69bada..9de3be39 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -448,10 +448,10 @@ function createSnapshot() snapshotLogFile = Packages.org.alfresco.util.TempFileProvider.createTempFile("ootbee-support-tools-snapshot", ".log"); logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); - snapshotAppender = new Packages.org.apache.log4j.FileAppender(logLayout, snapshotLogFile); + snapshotAppender = new Packages.org.orderofthebee.addons.support.tools.repo.TemporaryFileAppender(logLayout, snapshotLogFile); loggers = getLoggersToSnapshot(); loggers.forEach(function(logger) { - logger.addAppender(snapshotAppender); + snapshotAppender.registerAsAppender(logger); } ); return snapshotLogFile; diff --git a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java new file mode 100644 index 00000000..30b9bf97 --- /dev/null +++ b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java @@ -0,0 +1,97 @@ +package org.orderofthebee.addons.support.tools.repo; + +import org.apache.log4j.FileAppender; +import org.apache.log4j.Layout; +import org.apache.log4j.Logger; +import org.apache.log4j.helpers.LogLog; +import org.apache.log4j.spi.LoggingEvent; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * A FileAppender that will auto-close and unregister itself after 20 minutes. + * + * @author Bindu Wavell bindu@ziaconsulting.com + */ +public class TemporaryFileAppender extends FileAppender +{ + // 20 minutes after logger is created, we assume the UI lost access and automatically deregister this appender + private static final long AUTO_DEREGISTRATION_TIMEOUT = 1000 * 60 * 20; + + protected final List appendedToLoggers = new ArrayList<>(); + + protected final Lock closingLock = new ReentrantLock(); + + protected final long creationTimestamp; + + public + TemporaryFileAppender(Layout layout, String filename) throws IOException { + super(layout, filename); + this.creationTimestamp = System.currentTimeMillis(); + } + + /** + *

Assuming we have not timed out, does the usual. If we have timed out then deregisters + * appender from previously registered loggers and closes the appender. If the appender is + * closed then the append is simply ignored (parent would log a warning.)

+ * + * {@inheritDoc} + */ + @Override + public void append(final LoggingEvent event) + { + final boolean active = !this.closed && (System.currentTimeMillis() - this.creationTimestamp) < AUTO_DEREGISTRATION_TIMEOUT; + if (active) + { + super.append(event); + } else { + if (!this.closed) { + if (closingLock.tryLock()) + { + try + { + LogLog.warn("Automatically deregistering " + this.fileName + " appender after timeout exceeded."); + this.removeAppenderFromLoggers(); + this.close(); + } finally { + closingLock.unlock(); + } + } + // If we can't grab the closing lock we can assume another thread is + // already closing stuff down and we can start ignoring append calls. + } + } + } + + /** + * Add this appender to a logger and then remember the logger so we can remove ourselves from + * all registered loggers when we are done. + */ + public void registerAsAppender(final Logger logger) + { + synchronized (this.appendedToLoggers) + { + logger.addAppender(this); + this.appendedToLoggers.add(logger); + } + } + + /** + * Makes sure appender is removed from all loggers where it was previously registered. + */ + public void removeAppenderFromLoggers() + { + synchronized (this.appendedToLoggers) + { + for (Logger logger : this.appendedToLoggers) + { + logger.removeAppender(this); + } + this.appendedToLoggers.clear(); + } + } +} diff --git a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java index 053cdc61..b30e401d 100644 --- a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java +++ b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java @@ -19,50 +19,51 @@ */ package org.orderofthebee.addons.support.tools.repo.web.scripts; +import org.alfresco.repo.web.scripts.content.ContentStreamer; +import org.apache.log4j.Appender; +import org.apache.log4j.Logger; +import org.orderofthebee.addons.support.tools.repo.TemporaryFileAppender; +import org.springframework.extensions.webscripts.*; + import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import org.alfresco.repo.web.scripts.content.ContentStreamer; -import org.apache.log4j.Appender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.springframework.extensions.webscripts.WebScriptResponse; - /** + * Given the path to a temporary log file created with the log4j-snapshot-create webscript, we + * attempt to locate an associated {@link TemporaryFileAppender}. If we find it, it is + * deregistered from all loggers it was added to and then closed. If the file at the provided + * path exists and is a valid log snapshot file, we stream the contents out otherwise we + * throw a WebScriptException. + * * @author Ana Gouveia + * @author Bindu Wavell bindu@ziaconsulting.com */ public class LogSnapshotComplete extends AbstractLogFileWebScript { protected ContentStreamer delegate; - /** - * @param delegate - * ContentStreamer - */ public void setDelegate(final ContentStreamer delegate) { this.delegate = delegate; } /** - * Gets the appender, removes it from all the loggers and streams the content back. + *

Gets the appender, removes it from all the loggers and streams the content back.

* * {@inheritDoc} */ @Override - @SuppressWarnings("rawtypes") public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { final String servicePath = req.getServicePath(); final String matchPath = req.getServiceMatch().getPath(); - final String fileAppenderPath = servicePath.substring(servicePath.indexOf(matchPath) + matchPath.length()); + final String fileAppenderPathStr = servicePath.substring(servicePath.indexOf(matchPath) + matchPath.length()); + final Path fileAppenderPath = Paths.get(fileAppenderPathStr); final Map model = new HashMap(); final Status status = new Status(); @@ -74,41 +75,44 @@ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOExcept final boolean attach = attachParam != null && Boolean.parseBoolean(attachParam); Enumeration appenders = Logger.getRootLogger().getAllAppenders(); - FileAppender snapshotAppender = null; + TemporaryFileAppender snapshotAppender = null; + // Find the TemporaryFileAppender that writes to this file while (appenders.hasMoreElements()) { Appender appender = (Appender) appenders.nextElement(); - if (appender instanceof FileAppender) + if (appender instanceof TemporaryFileAppender) { - FileAppender fileAppender = (FileAppender) appender; - if (fileAppender.getFile().equals(fileAppenderPath)) + TemporaryFileAppender fileAppender = (TemporaryFileAppender) appender; + if (fileAppender.getFile().equals(fileAppenderPathStr)) { snapshotAppender = fileAppender; } } } + + // If found, remove the appender from all loggers and close it if (snapshotAppender != null) { - final File file = this.validateFilePath(snapshotAppender.getFile()); - this.delegate.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model); - - Enumeration loggers = LogManager.getCurrentLoggers(); - while (loggers.hasMoreElements()) - { - Logger logger = (Logger) loggers.nextElement(); - Enumeration logAppenders = logger.getAllAppenders(); - while (logAppenders.hasMoreElements()) - { - Appender appender = (Appender) logAppenders.nextElement(); - if (appender instanceof FileAppender && ((FileAppender) appender).getFile().equals(fileAppenderPath)) - { - logger.removeAppender(appender); - } - } - } - Logger.getRootLogger().removeAppender(snapshotAppender); + snapshotAppender.removeAppenderFromLoggers(); + snapshotAppender.close(); } + + // In any event, if the file is valid we can stream it out (if not, a WebScriptException will be thrown.) + final String fileName = fileAppenderPath.getFileName().toString(); + if (!fileName.matches("^ootbee-support-tools-snapshot.*\\.log$")) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, + "The path " + fileAppenderPathStr + " is invalid for a snapshot log file."); + } + final File file = fileAppenderPath.toFile(); + if (!file.exists()) { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "There is no file at " + fileAppenderPathStr + "."); + } + // TODO(bwavell): Consider if we should create a temp file and validate the paths are the same. + + this.delegate.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model); } } From 3cc38bee8d0c1cdb0f7b3c13c694bcaa295dac85 Mon Sep 17 00:00:00 2001 From: Bindu Wavell Date: Sat, 13 May 2017 15:17:16 -0600 Subject: [PATCH 13/13] Address PR comments --- .../log4j-loggers.get.html.ftl | 28 +++++++++---------- .../log4j-loggers.get.properties | 1 + .../log4j-loggers.get_de.properties | 6 ++++ .../log4j-loggers.get_en.properties | 5 ++++ .../log4j-loggers.get_es.properties | 6 ++++ .../log4j-loggers.get_pt.properties | 6 ++++ .../log4j-snapshot-create.get.js | 6 ++-- .../log4j-snapshot-create.get.json.ftl | 6 ++-- .../log4j-snapshot-lap.post.js | 6 ++-- .../log4j-snapshot-lap.post.json.ftl | 6 ++-- .../admin/ootbee-support-tools/log4j.lib.js | 17 ++++++----- .../ootbee-support-tools/js/log-settings.js | 12 ++++---- .../tools/repo/TemporaryFileAppender.java | 26 +++++++++++++++-- .../repo/web/scripts/LogSnapshotComplete.java | 6 ++-- 14 files changed, 93 insertions(+), 44 deletions(-) diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl index e9bbfab5..6e489d94 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.html.ftl @@ -1,6 +1,6 @@ <#-- -Copyright (C) 2016 Axel Faust / Markus Joos -Copyright (C) 2016 Order of the Bee +Copyright (C) 2017 Axel Faust / Markus Joos / Michael Bui / Bindu Wavell +Copyright (C) 2017 Order of the Bee This file is part of Community Support Tools @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with Community Support Tools. If not, see . Linked to Alfresco -Copyright (C) 2005-2016 Alfresco Software Limited. +Copyright (C) 2005-2017 Alfresco Software Limited. --> @@ -55,17 +55,17 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
- <@button id="tailRepoLog" label=msg("log-settings.tail") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-tail');")/> - <@button id="showLogFiles" label=msg("log-settings.logFiles") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-log-files');")/> - <@button id="resetLogSettings" label=msg("log-settings.resetAll") onclick=("AdminLS.resetLogLevel();")/> - <@button id="toggleView" label=msg(showUnconfiguredLoggers?string('log-settings.hideUnconfigured', 'log-settings.showUnconfigured')) onclick=("window.location.href = '" + url.serviceContext + "/ootbee/admin/log4j-loggers?showUnconfiguredLoggers="+ (showUnconfiguredLoggers!false)?string('false','true') + "';")/> -
-
- <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> - <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> - <@button id="lapLogSnapshot" style="display:none" label=msg("log-settings.lapLogSnapshot") onclick=("AdminLS.lapLogSnapshot();")/> - -
+ <@button id="tailRepoLog" label=msg("log-settings.tail") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-tail');")/> + <@button id="showLogFiles" label=msg("log-settings.logFiles") onclick=("Admin.showDialog('" + url.serviceContext + "/ootbee/admin/log4j-log-files');")/> + <@button id="resetLogSettings" label=msg("log-settings.resetAll") onclick=("AdminLS.resetLogLevel();")/> + <@button id="toggleView" label=msg(showUnconfiguredLoggers?string('log-settings.hideUnconfigured', 'log-settings.showUnconfigured')) onclick=("window.location.href = '" + url.serviceContext + "/ootbee/admin/log4j-loggers?showUnconfiguredLoggers="+ (showUnconfiguredLoggers!false)?string('false','true') + "';")/> +
+
+ <@button id="startLogSnapshot" label=msg("log-settings.startLogSnapshot") onclick=("AdminLS.startLogSnapshot();")/> + <@button id="stopLogSnapshot" style="display:none" label=msg("log-settings.stopLogSnapshot") onclick=("AdminLS.stopLogSnapshot();")/> + <@button id="lapLogSnapshot" style="display:none" label=msg("log-settings.lapLogSnapshot") onclick=("AdminLS.lapLogSnapshot();")/> + +
<#if statusMessage?? && statusMessage != "">
${.now?string("HH:mm:ss")} - ${statusMessage?html!""} [X]
diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties index e6d46dad..f2c05d87 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get.properties @@ -8,6 +8,7 @@ log-settings.reset=Reset log-settings.hideUnconfigured=Hide unconfigured Loggers log-settings.showUnconfigured=Show unconfigured Loggers log-settings.rootLogger=(Root Logger) + log-settings.startLogSnapshot=Start log Snapshot log-settings.stopLogSnapshot=Stop log Snapshot log-settings.lapLogSnapshot=Add log entry diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_de.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_de.properties index 0d80391c..4944c5b0 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_de.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_de.properties @@ -9,6 +9,12 @@ log-settings.hideUnconfigured=Nicht konfigurierte Logger ausblenden log-settings.showUnconfigured=Nicht konfigurierte Logger anzeigen log-settings.rootLogger=(Root Logger) +# Requires translation +log-settings.startLogSnapshot=Start log Snapshot +log-settings.stopLogSnapshot=Stop log Snapshot +log-settings.lapLogSnapshot=Add log entry +log-settings.lapMessageLogSnapshot=If not set, lap number is logged + log-settings.column.add=Hinzuf\u00fcgen log-settings.column.addLogger=Logger hinzuf\u00fcgen log-settings.column.loggerName=Name des Loggers diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_en.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_en.properties index c74aa34c..7c972ed4 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_en.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_en.properties @@ -9,6 +9,11 @@ log-settings.hideUnconfigured=Hide unconfigured Loggers log-settings.showUnconfigured=Show unconfigured Loggers log-settings.rootLogger=(Root Logger) +log-settings.startLogSnapshot=Start log Snapshot +log-settings.stopLogSnapshot=Stop log Snapshot +log-settings.lapLogSnapshot=Add log entry +log-settings.lapMessageLogSnapshot=If not set, lap number is logged + log-settings.column.add=Add log-settings.column.addLogger=Add logger log-settings.column.loggerName=Logger name diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_es.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_es.properties index ef12aa5d..0c92bf90 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_es.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_es.properties @@ -9,6 +9,12 @@ log-settings.hideUnconfigured=Ocultar Loggers no configurados log-settings.showUnconfigured=Mostrar Loggers no configurados log-settings.rootLogger=(Root Logger) +# Requires translation +log-settings.startLogSnapshot=Start log Snapshot +log-settings.stopLogSnapshot=Stop log Snapshot +log-settings.lapLogSnapshot=Add log entry +log-settings.lapMessageLogSnapshot=If not set, lap number is logged + log-settings.column.add=A\u00f1adir log-settings.column.addLogger=A\u00f1adir logger log-settings.column.loggerName=Nombre del logger diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_pt.properties b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_pt.properties index 07c1db78..bda46725 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_pt.properties +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-loggers.get_pt.properties @@ -9,6 +9,12 @@ log-settings.hideUnconfigured=Ocultar Loggers n\u00e3o configurados log-settings.showUnconfigured=Exibir Loggers n\u00e3o configurados log-settings.rootLogger=(Logger Ra\u00edz) +# Requires translation +log-settings.startLogSnapshot=Start log Snapshot +log-settings.stopLogSnapshot=Stop log Snapshot +log-settings.lapLogSnapshot=Add log entry +log-settings.lapMessageLogSnapshot=If not set, lap number is logged + log-settings.column.add=Adicionar log-settings.column.addLogger=Adicionar logger log-settings.column.loggerName=Nome do logger diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js index 4e4bba31..615481ae 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.js @@ -1,8 +1,8 @@ /** - * Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell - * Copyright (C) 2016 Order of the Bee + * Copyright (C) 2017 Bindu Wavell + * Copyright (C) 2017 Order of the Bee * * This file is part of Community Support Tools * @@ -21,7 +21,7 @@ */ /* * Linked to Alfresco - * Copyright (C) 2005-2016 Alfresco Software Limited. + * Copyright (C) 2005-2017 Alfresco Software Limited. */ model.snapshotLogFile = createSnapshot(); \ No newline at end of file diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl index 746c95bc..03d121ad 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-create.get.json.ftl @@ -1,7 +1,7 @@ <#compress> <#-- -Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell -Copyright (C) 2016 Order of the Bee +Copyright (C) 2017 Bindu Wavell +Copyright (C) 2017 Order of the Bee This file is part of Community Support Tools @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with Community Support Tools. If not, see . Linked to Alfresco -Copyright (C) 2005-2016 Alfresco Software Limited. +Copyright (C) 2005-2017 Alfresco Software Limited. --> diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js index b2f4d32b..c2cb6647 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.js @@ -1,8 +1,8 @@ /** - * Copyright (C) 2016 Axel Faust / Markus Joos / Bindu Wavell - * Copyright (C) 2016 Order of the Bee + * Copyright (C) 2017 Bindu Wavell + * Copyright (C) 2017 Order of the Bee * * This file is part of Community Support Tools * @@ -21,7 +21,7 @@ */ /* * Linked to Alfresco - * Copyright (C) 2005-2016 Alfresco Software Limited. + * Copyright (C) 2005-2017 Alfresco Software Limited. */ logSnapshotLapMessage(args['message']); diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl index 333a1bcc..07fb5b5e 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j-snapshot-lap.post.json.ftl @@ -1,7 +1,7 @@ <#compress> <#-- -Copyright (C) 2016 Axel Faust / Bindu Wavell -Copyright (C) 2016 Order of the Bee +Copyright (C) 2017 Bindu Wavell +Copyright (C) 2017 Order of the Bee This file is part of Community Support Tools @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with Community Support Tools. If not, see . Linked to Alfresco -Copyright (C) 2005-2016 Alfresco Software Limited. +Copyright (C) 2005-2017 Alfresco Software Limited. --> {} diff --git a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js index 9de3be39..03601163 100644 --- a/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js +++ b/repository/src/main/amp/config/alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js @@ -1,6 +1,6 @@ /** - * Copyright (C) 2016 Axel Faust / Markus Joos - * Copyright (C) 2016 Order of the Bee + * Copyright (C) 2017 Axel Faust / Markus Joos / Bindu Wavell + * Copyright (C) 2017 Order of the Bee * * This file is part of Community Support Tools * @@ -19,7 +19,7 @@ */ /* * Linked to Alfresco - * Copyright (C) 2005-2016 Alfresco Software Limited. + * Copyright (C) 2005-2017 Alfresco Software Limited. */ /* global formdata: false, logSettingTracker: false */ @@ -450,9 +450,12 @@ function createSnapshot() logLayout = new Packages.org.apache.log4j.PatternLayout('%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n'); snapshotAppender = new Packages.org.orderofthebee.addons.support.tools.repo.TemporaryFileAppender(logLayout, snapshotLogFile); loggers = getLoggersToSnapshot(); - loggers.forEach(function(logger) { - snapshotAppender.registerAsAppender(logger); - } ); + loggers.forEach( + function createSnapshot_connectLoggerAndAppender(logger) + { + snapshotAppender.registerAsAppender(logger); + } + ); return snapshotLogFile; } @@ -464,7 +467,7 @@ function logSnapshotLapMessage(message) { root = Packages.org.apache.log4j.Logger.getRootLogger(); level = Packages.org.apache.log4j.Level.INFO; // Fake logger that produces a good log message with the Alfresco default log format - clazz = 'org.orderofthebee.addons.supporttools.logsnapshot.Lap'; + clazz = 'org.orderofthebee.addons.support.tools.repo.logSnapshotLap'; lapLogger = root.getLogger(clazz); lapLogger.setLevel(level); diff --git a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js index 2b54a3c8..aeb433d4 100644 --- a/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js +++ b/repository/src/main/amp/web/ootbee-support-tools/js/log-settings.js @@ -1,6 +1,6 @@ /** - * Copyright (C) 2016 Axel Faust / Markus Joos - * Copyright (C) 2016 Order of the Bee + * Copyright (C) 2017 Axel Faust / Markus Joos / Michael Bui / Bindu Wavell + * Copyright (C) 2017 Order of the Bee * * This file is part of Community Support Tools * @@ -20,7 +20,7 @@ */ /* * Linked to Alfresco Copyright - * (C) 2005-2016 Alfresco Software Limited. + * (C) 2005-2017 Alfresco Software Limited. */ /* global Admin: false */ @@ -35,9 +35,7 @@ var AdminLS = AdminLS || {}; var KEYCODE_ENTER = 13; var KEYCODE_ESC = 27; - var serviceContext; - var snapshotLogFile; - var snapshotLapNumber; + var serviceContext, snapshotLogFile, snapshotLapNumber; AdminLS.setServiceContext = function setServiceContext(context) { @@ -64,7 +62,7 @@ var AdminLS = AdminLS || {}; method : 'GET', fnSuccess : function startLogSnapshot_success(res) { - if (res.responseText) + if (res.responseJSON) { snapshotLogFile = res.responseJSON.snapshotLogFile; document.getElementById("startLogSnapshot").style.display = 'none'; diff --git a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java index 30b9bf97..685f5581 100644 --- a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java +++ b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/TemporaryFileAppender.java @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2017 Bindu Wavell + * Copyright (C) 2017 Order of the Bee + * + * This file is part of Community Support Tools + * + * Community Support Tools 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 3 of the License, + * or (at your option) any later version. + * + * Community Support Tools 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 Community Support Tools. If not, see + * . + */ package org.orderofthebee.addons.support.tools.repo; import org.apache.log4j.FileAppender; @@ -29,7 +49,8 @@ public class TemporaryFileAppender extends FileAppender protected final long creationTimestamp; public - TemporaryFileAppender(Layout layout, String filename) throws IOException { + TemporaryFileAppender(Layout layout, String filename) throws IOException + { super(layout, filename); this.creationTimestamp = System.currentTimeMillis(); } @@ -49,7 +70,8 @@ public void append(final LoggingEvent event) { super.append(event); } else { - if (!this.closed) { + if (!this.closed) + { if (closingLock.tryLock()) { try diff --git a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java index b30e401d..c108c6e9 100644 --- a/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java +++ b/repository/src/main/java/org/orderofthebee/addons/support/tools/repo/web/scripts/LogSnapshotComplete.java @@ -1,5 +1,6 @@ /** - * Copyright (C) 2016 Order of the Bee + * Copyright (C) 2017 Ana Gouveia / Bindu Wavell + * Copyright (C) 2017 Order of the Bee * * This file is part of Community Support Tools * @@ -107,7 +108,8 @@ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOExcept "The path " + fileAppenderPathStr + " is invalid for a snapshot log file."); } final File file = fileAppenderPath.toFile(); - if (!file.exists()) { + if (!file.exists()) + { throw new WebScriptException(Status.STATUS_NOT_FOUND, "There is no file at " + fileAppenderPathStr + "."); }