Исходный код вики Show Logs
Версия 1.1 от Dmitriy Rybakov на 05.08.2025, 13:07
Скрыть последних авторов
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{groovy}} |
| 2 | if( System.getProperty('catalina.base') ) { | ||
| 3 | appserverpath = System.getProperty('catalina.base') | ||
| 4 | } else { | ||
| 5 | // CONFIG: try to set the path to ypur application server if not found | ||
| 6 | appserverpath = ".." | ||
| 7 | } | ||
| 8 | |||
| 9 | def tomcatLog = ["${appserverpath}/logs/catalina.out", "/usr/local/tomcat/logs/catalina.out", "/var/log/tomcat8/catalina.out", "/var/log/tomcat9/catalina.out", "/var/log/tomcat/catalina.out"] | ||
| 10 | |||
| 11 | def tomcatLogPath = "/usr/local/tomcat/logs/catalina.out" | ||
| 12 | for (path in tomcatLog) { | ||
| 13 | if ((new File(path)).exists()) { | ||
| 14 | tomcatLogPath = path | ||
| 15 | break; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | if (request.lines) { | ||
| 22 | lines = request.lines; | ||
| 23 | } else { | ||
| 24 | lines = 2000 | ||
| 25 | } | ||
| 26 | if (request.logfile) { | ||
| 27 | logfile = request.logfile; | ||
| 28 | } else { | ||
| 29 | logfile = tomcatLogPath | ||
| 30 | } | ||
| 31 | {{/groovy}} | ||
| 32 | |||
| 33 | {{info}}This script only works in a Linux environnent.{{/info}} | ||
| 34 | {{html clean="false" wiki="true"}} | ||
| 35 | <form action="" method="post"> | ||
| 36 | <table border="0"> | ||
| 37 | <tr> | ||
| 38 | <td>Logfile to read : </td><td><input type="text" name="logfile" size="40" value="/usr/local/tomcat/logs/catalina.out"/></td></tr> | ||
| 39 | <tr> | ||
| 40 | <td>Number of log lines to show : </td><td><input type="text" name="lines" size="40" value="2000" /></td> | ||
| 41 | <input type="hidden" name="showlog" value="1" /> | ||
| 42 | </tr> | ||
| 43 | </table> | ||
| 44 | <br/> | ||
| 45 | <input type="submit" name="Show" /> | ||
| 46 | </form> | ||
| 47 | {{/html}} | ||
| 48 | |||
| 49 | {{groovy}} | ||
| 50 | if(request.showlog == "1") { | ||
| 51 | print("= Result =") | ||
| 52 | line = "/usr/bin/tail -n " + lines + " " + logfile | ||
| 53 | print("{{code language='none'}}") | ||
| 54 | print(line.execute().getText()) | ||
| 55 | print("{{/code}}") | ||
| 56 | } | ||
| 57 | {{/groovy}} |