Исходный код вики Show Logs
Версия 3.1 от Dmitriy Rybakov на 05.08.2025, 14:24
Скрыть последних авторов
| 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 | |||
| |
2.1 | 33 | {{info}} |
| 34 | This script only works in a Linux environnent. | ||
| 35 | {{/info}} | ||
| |
1.1 | 36 | |
| |
2.1 | 37 | (% border="0" %) |
| 38 | |Logfile to read : ((( | ||
| 39 | |||
| 40 | )))| | ||
| 41 | |Number of log lines to show :| | ||
| 42 | |||
| 43 | |||
| 44 | |||
| |
3.1 | 45 | |
| |
1.1 | 46 | {{groovy}} |
| 47 | if(request.showlog == "1") { | ||
| 48 | print("= Result =") | ||
| 49 | line = "/usr/bin/tail -n " + lines + " " + logfile | ||
| 50 | print("{{code language='none'}}") | ||
| 51 | print(line.execute().getText()) | ||
| 52 | print("{{/code}}") | ||
| 53 | } | ||
| 54 | {{/groovy}} |