-
Notifications
You must be signed in to change notification settings - Fork 38
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
57 log snapshot #81
Changes from all commits
b416c3b
0d25c38
56b14bb
25a6013
738d044
765a680
c03b3fb
a83efd7
294f883
864dc70
669b92f
84898d9
bf6f777
3cc38be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
* | ||
|
@@ -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 */ | ||
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created #82 to track the idea of a configurable log pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} |
There was a problem hiding this comment.
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.