Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

57 log snapshot #81

Merged
merged 14 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
<property name="delegate" ref="webscript.content.streamer" />
</bean>

<bean id="webscript.org.orderofthebee.support-tools.admin.ootbee-support-tools.log4j-snapshot-complete.get" class="org.orderofthebee.addons.support.tools.repo.web.scripts.LogSnapshotComplete"
parent="webscript" >
<property name="delegate" ref="webscript.content.streamer" />
</bean>

</beans>
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 <http://www.gnu.org/licenses/>.

Linked to Alfresco
Copyright (C) 2005-2016 Alfresco Software Limited.
Copyright (C) 2005-2017 Alfresco Software Limited.

-->

Expand All @@ -39,7 +39,7 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
<div class="column-full">
<div>${msg("log-settings.column.addLogger")}:
<form id="addPackageForm" action="${url.service}" method="POST" enctype="multipart/form-data" accept-charset="utf-8">
<input name="logger" size="35" placeholder="logger-name"></input>
<input type="text" name="logger" size="35" placeholder="logger-name"></input>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some CSS so that inputs that explicitly have type="text" will be slightly taller than default (to match surrounding buttons) and will have a little left and right padding.

<input type="hidden" name="showUnconfiguredLoggers" value="${(showUnconfiguredLoggers!false)?string}" />
<select name="level">
<option value="UNSET">${msg("log-settings.level.UNSET")?html}</option>
Expand All @@ -54,10 +54,18 @@ Copyright (C) 2005-2016 Alfresco Software Limited.
<input type="submit" value="${msg("log-settings.column.add")}" style="margin-right:1em;" />
</form>
<div class="buttons">
<@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') + "';")/>
<div class="column-left">
<@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') + "';")/>
</div>
<div class="column-right">
<@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();")/>
<input id="lapMessageLogSnapshot" type="text" size="35" style="display:none" placeholder="${msg("log-settings.lapMessageLogSnapshot")}" onkeyup="return AdminLS.handleLogMessageLogSnapshotKeyUp(event);"></input>
</div>
</div>
<#if statusMessage?? && statusMessage != "">
<div id="statusmessage" class="message ${messageStatus!""}">${.now?string("HH:mm:ss")} - ${statusMessage?html!""} <a href="#" onclick="this.parentElement.style.display='none';" title="${msg("admin-console.close")}">[X]</a></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<webscript>
<shortname>Log4J Snapshot</shortname>
<description>Finish log snapshot and shows it</description>
<url>/ootbee/admin/log4j-snapshot-complete/{path}</url>
<authentication>admin</authentication>
<lifecycle>internal</lifecycle>
<transaction>none</transaction>
<family>OOTBee Support Tools</family>
</webscript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<webscript>
<shortname>Log4J Settings - Log File - Create Snapshot</shortname>
<description>Accesses a specific Log4J log file</description>
<url>/ootbee/admin/log4j-snapshot-create</url>
<authentication>admin</authentication>
<format default="json"/>
<lifecycle>internal</lifecycle>
<transaction>none</transaction>
<family>OOTBee Support Tools</family>
</webscript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<import resource="classpath:alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js">

/**
* 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 <http://www.gnu.org/licenses/>.
*/
/*
* Linked to Alfresco
* Copyright (C) 2005-2017 Alfresco Software Limited.
*/

model.snapshotLogFile = createSnapshot();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<#compress>
<#--
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 <http://www.gnu.org/licenses/>.

Linked to Alfresco
Copyright (C) 2005-2017 Alfresco Software Limited.

-->

{
"snapshotLogFile": "${snapshotLogFile}"
}
</#compress>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<webscript>
<shortname>Log4J Snapshot Lap</shortname>
<description>Log4J Snapshot Log Lap Message</description>
<url>/ootbee/admin/log4j-snapshot-lap?message={message}</url>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could allow an optional log level to be specified here, but as that doesn't seem necessary for the current use case, I left it out and figured it could be added without breaking anything later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An optional log level only makes sense if someone would re-configure the log level of the snapshot lap logger. And currently you are always resetting that to INFO anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code could auto-configure the log level based on what is passed in. I don't see this as particularly useful for the UI. However, if folks start using these webscripts for sysadmin activities it might be helpful. In any case I'm not planning to do anything here 😄

<format default="json" />
<authentication>admin</authentication>
<lifecycle>internal</lifecycle>
<transaction>none</transaction>
<family>OOTBee Support Tools</family>
</webscript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<import resource="classpath:alfresco/templates/webscripts/org/orderofthebee/support-tools/admin/ootbee-support-tools/log4j.lib.js">

/**
* 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 <http://www.gnu.org/licenses/>.
*/
/*
* Linked to Alfresco
* Copyright (C) 2005-2017 Alfresco Software Limited.
*/

logSnapshotLapMessage(args['message']);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<#compress>
<#--
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 <http://www.gnu.org/licenses/>.

Linked to Alfresco
Copyright (C) 2005-2017 Alfresco Software Limited.

-->
{}
</#compress>
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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 */
Expand Down Expand Up @@ -420,3 +420,56 @@ 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the log pattern should be configurable. Might not be in this iteration but for future improvement. E.g. I might want to check components that use MDC data and need to include the specific keys in the pattern. This is irrelevant for default Alfresco which unfortunately does not use MDC, but might be relevant for custom solutions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm not sure how you'd want to pass this configuration in, I'm going to leave it fixed like this. Happy to work on another issue if you write up how you'd like to have that done (although I expect writing it up would take more time than doing it yourself ;) ... of course if you have another CL showing the approach you'd like to use you could just reference that...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #82 to track the idea of a configurable log pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Axel!

snapshotAppender = new Packages.org.orderofthebee.addons.support.tools.repo.TemporaryFileAppender(logLayout, snapshotLogFile);
loggers = getLoggersToSnapshot();
loggers.forEach(
function createSnapshot_connectLoggerAndAppender(logger)
{
snapshotAppender.registerAsAppender(logger);
}
);

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console logger just shows the last 3 segments of the logger class "supporttools.logsnapshot.Lap" which is why I removed some periods. Since this is a fake logger I hope that is acceptable. The snapshot appender itself includes the fully qualified class name so we can make this more accurate if folks would prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer using our base Java package name for consistent logger names (in this case ´org.orderofthebee.addons.support.tools.repo´ so we end up with e.g. ´org.orderofthebee.addons.support.tools.repo.logSnapshotLap'). I feel we should not worry about how a specific, pre-defined appender will output the package name - it is more important that the last segment (which should always be present) is sufficiently meaningful. E.g. I may re-route Log4J via SLF4J to Logback and this will only include the initial character of each package level, e.g. `o.o.a.s.t.repo.logSnapshotLap'
We could (should?) include the default INFO level in our log4j.properties.
Why are we not using the explicit info() log method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the suggested change to the fake logger.

Since I want to make sure this logger has the right log level I need the level variable. Given that I figured I'd use the generic log() method. That way we could change the level reference and the code would continue to work. Otherwise if the level is changed to say error, if we used the info() method our log statements would not show up.

I don't feel super strongly about this, but have not made a change given the above justification. If you have a strong feeling about this let me know and I'll change it.

clazz = 'org.orderofthebee.addons.support.tools.repo.logSnapshotLap';
lapLogger = root.getLogger(clazz);
lapLogger.setLevel(level);

lapLogger.log(level, message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading