Wed, 15 Dec 2021 19:56:05 +0100
remove log4j entirely
1.1 --- a/build.gradle.kts Sun Dec 12 18:16:46 2021 +0100 1.2 +++ b/build.gradle.kts Wed Dec 15 19:56:05 2021 +0100 1.3 @@ -7,8 +7,6 @@ 1.4 group = "de.uapcore" 1.5 version = "0.6-SNAPSHOT" 1.6 1.7 -val log4jVersion = "2.15.0" 1.8 -val slf4jVersion = "1.7.30" 1.9 val flexmarkVersion = "0.62.2" 1.10 1.11 repositories { 1.12 @@ -36,9 +34,6 @@ 1.13 dependencies { 1.14 compileOnly("javax.servlet:javax.servlet-api:3.1.0") 1.15 compileOnly("javax.servlet:jstl:1.2") 1.16 - implementation("org.slf4j:slf4j-api:${slf4jVersion}") 1.17 - implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}") 1.18 - implementation("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}") 1.19 implementation("com.vladsch.flexmark:flexmark:${flexmarkVersion}") 1.20 implementation("com.vladsch.flexmark:flexmark-util-data:${flexmarkVersion}") 1.21 implementation("com.vladsch.flexmark:flexmark-ext-tables:${flexmarkVersion}")
2.1 --- a/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt Sun Dec 12 18:16:46 2021 +0100 2.2 +++ b/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt Wed Dec 15 19:56:05 2021 +0100 2.3 @@ -34,7 +34,9 @@ 2.4 import javax.servlet.http.HttpServletRequest 2.5 import javax.servlet.http.HttpServletResponse 2.6 2.7 -abstract class AbstractServlet : LoggingTrait, HttpServlet() { 2.8 +abstract class AbstractServlet : HttpServlet() { 2.9 + 2.10 + protected val logger = MyLogger() 2.11 2.12 /** 2.13 * Contains the GET request mappings. 2.14 @@ -68,7 +70,7 @@ 2.15 Pair(PathPattern(requestPath), ::notFound) 2.16 } else { 2.17 if (candidates.size > 1) { 2.18 - logger().warn("Ambiguous mapping for request path '{}'", requestPath) 2.19 + logger.warn("Ambiguous mapping for request path '{0}'", requestPath) 2.20 } 2.21 candidates.entries.first().toPair() 2.22 } 2.23 @@ -82,7 +84,7 @@ 2.24 ) { 2.25 val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req)) 2.26 val method = mapping.second 2.27 - logger().trace("invoke {}", method) 2.28 + logger.trace("invoke {0}", method) 2.29 method(HttpRequest(req, resp, params), dao) 2.30 } 2.31 2.32 @@ -105,13 +107,13 @@ 2.33 val sessionLocale = if (availableLanguages.contains(reqLocale)) reqLocale else availableLanguages.first() 2.34 session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale) 2.35 resp.locale = sessionLocale 2.36 - logger().debug( 2.37 - "Setting language for new session {}: {}", session.id, sessionLocale.displayLanguage 2.38 + logger.debug( 2.39 + "Setting language for new session {0}: {1}", session.id, sessionLocale.displayLanguage 2.40 ) 2.41 } else { 2.42 val sessionLocale = session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) as Locale 2.43 resp.locale = sessionLocale 2.44 - logger().trace("Continuing session {} with language {}", session.id, sessionLocale) 2.45 + logger.trace("Continuing session {0} with language {1}", session.id, sessionLocale) 2.46 } 2.47 2.48 // set some internal request attributes 2.49 @@ -150,8 +152,8 @@ 2.50 invokeMapping(findMapping(mappings, req), req, resp, dao) 2.51 connection.commit() 2.52 } catch (ex: SQLException) { 2.53 - logger().warn("Database transaction failed (Code {}): {}", ex.errorCode, ex.message) 2.54 - logger().debug("Details: ", ex) 2.55 + logger.warn("Database transaction failed (Code {0}): {1}", ex.errorCode, ex.message) 2.56 + logger.debug("Details: ", ex) 2.57 resp.sendError( 2.58 HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 2.59 "Unhandled Transaction Error - Code: " + ex.errorCode 2.60 @@ -160,8 +162,8 @@ 2.61 } 2.62 } 2.63 } catch (ex: SQLException) { 2.64 - logger().error("Severe Database Exception (Code {}): {}", ex.errorCode, ex.message) 2.65 - logger().debug("Details: ", ex) 2.66 + logger.error("Severe Database Exception (Code {0}): {1}", ex.errorCode, ex.message) 2.67 + logger.debug("Details: ", ex) 2.68 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code: " + ex.errorCode) 2.69 } 2.70 }
3.1 --- a/src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt Sun Dec 12 18:16:46 2021 +0100 3.2 +++ b/src/main/kotlin/de/uapcore/lightpit/DataSourceProvider.kt Wed Dec 15 19:56:05 2021 +0100 3.3 @@ -38,7 +38,9 @@ 3.4 * Provides access to the database. 3.5 */ 3.6 @WebListener 3.7 -class DataSourceProvider : ServletContextListener, LoggingTrait { 3.8 +class DataSourceProvider : ServletContextListener { 3.9 + 3.10 + private val logger = MyLogger() 3.11 3.12 enum class Dialect { 3.13 Postgres 3.14 @@ -100,7 +102,7 @@ 3.15 ) 3.16 } 3.17 val metaData = conn.metaData 3.18 - logger().info( 3.19 + logger.info( 3.20 "Connections as {} to {}/{} ready to go.", 3.21 metaData.userName, 3.22 metaData.url, 3.23 @@ -108,18 +110,18 @@ 3.24 ) 3.25 } 3.26 } catch (ex: SQLException) { 3.27 - logger().error("Checking database connection failed", ex) 3.28 + logger.error("Checking database connection failed", ex) 3.29 } 3.30 } 3.31 3.32 private fun retrieveDataSource(ctx: Context): DataSource? { 3.33 return try { 3.34 val ret = ctx.lookup(DS_JNDI_NAME) as DataSource 3.35 - logger().info("Data source retrieved.") 3.36 + logger.info("Data source retrieved.") 3.37 ret 3.38 } catch (ex: NamingException) { 3.39 - logger().error("Data source {} not available.", DS_JNDI_NAME) 3.40 - logger().error("Reason for the missing data source: ", ex) 3.41 + logger.error("Data source {0} not available.", DS_JNDI_NAME) 3.42 + logger.error("Reason for the missing data source: ", ex) 3.43 null 3.44 } 3.45 } 3.46 @@ -132,8 +134,8 @@ 3.47 try { 3.48 dialect = Dialect.valueOf(dbDialect) 3.49 } catch (ex: IllegalArgumentException) { 3.50 - logger().error( 3.51 - "Unknown or unsupported database dialect {}. Defaulting to {}.", 3.52 + logger.error( 3.53 + "Unknown or unsupported database dialect {0}. Defaulting to {1}.", 3.54 dbDialect, 3.55 dialect 3.56 ) 3.57 @@ -141,22 +143,22 @@ 3.58 } 3.59 3.60 dataSource = try { 3.61 - logger().debug("Trying to access JNDI context ...") 3.62 + logger.debug("Trying to access JNDI context ...") 3.63 val initialCtx: Context = InitialContext() 3.64 val ctx = initialCtx.lookup("java:comp/env") as Context 3.65 retrieveDataSource(ctx) 3.66 } catch (ex: NamingException) { 3.67 - logger().error("Cannot access JNDI resources.", ex) 3.68 + logger.error("Cannot access JNDI resources.", ex) 3.69 null 3.70 } catch (ex: ClassCastException) { 3.71 - logger().error("Cannot access JNDI resources.", ex) 3.72 + logger.error("Cannot access JNDI resources.", ex) 3.73 null 3.74 } 3.75 3.76 dataSource?.let { checkConnection(it, dbSchema) } 3.77 3.78 sc.setAttribute(SC_ATTR_NAME, this) 3.79 - logger().info("Database facade injected into ServletContext.") 3.80 + logger.info("Database facade injected into ServletContext.") 3.81 } 3.82 3.83 override fun contextDestroyed(sce: ServletContextEvent?) {
4.1 --- a/src/main/kotlin/de/uapcore/lightpit/Logging.kt Sun Dec 12 18:16:46 2021 +0100 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,33 +0,0 @@ 4.4 -/* 4.5 - * Copyright 2021 Mike Becker. All rights reserved. 4.6 - * 4.7 - * Redistribution and use in source and binary forms, with or without 4.8 - * modification, are permitted provided that the following conditions are met: 4.9 - * 4.10 - * 1. Redistributions of source code must retain the above copyright 4.11 - * notice, this list of conditions and the following disclaimer. 4.12 - * 4.13 - * 2. Redistributions in binary form must reproduce the above copyright 4.14 - * notice, this list of conditions and the following disclaimer in the 4.15 - * documentation and/or other materials provided with the distribution. 4.16 - * 4.17 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 4.18 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4.19 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 4.20 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 4.21 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4.22 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 4.23 - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 4.24 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 4.25 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4.26 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4.27 - */ 4.28 - 4.29 -package de.uapcore.lightpit 4.30 - 4.31 -import org.slf4j.Logger 4.32 -import org.slf4j.LoggerFactory 4.33 - 4.34 -interface LoggingTrait 4.35 - 4.36 -inline fun <reified T : LoggingTrait> T.logger(): Logger = LoggerFactory.getLogger(T::class.java)
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/main/kotlin/de/uapcore/lightpit/MyLogger.kt Wed Dec 15 19:56:05 2021 +0100 5.3 @@ -0,0 +1,65 @@ 5.4 +/* 5.5 + * Copyright 2021 Mike Becker. All rights reserved. 5.6 + * 5.7 + * Redistribution and use in source and binary forms, with or without 5.8 + * modification, are permitted provided that the following conditions are met: 5.9 + * 5.10 + * 1. Redistributions of source code must retain the above copyright 5.11 + * notice, this list of conditions and the following disclaimer. 5.12 + * 5.13 + * 2. Redistributions in binary form must reproduce the above copyright 5.14 + * notice, this list of conditions and the following disclaimer in the 5.15 + * documentation and/or other materials provided with the distribution. 5.16 + * 5.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 5.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 5.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 5.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 5.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 5.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 5.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5.27 + */ 5.28 + 5.29 +package de.uapcore.lightpit 5.30 + 5.31 +import java.util.logging.Level 5.32 +import java.util.logging.Logger 5.33 + 5.34 +class MyLogger { 5.35 + private val logger: Logger = Logger.getLogger("de.uapcore.lightpit.Logger") 5.36 + 5.37 + fun info(fmt: String, vararg args: Any?) { 5.38 + logger.log(Level.INFO, fmt, args) 5.39 + } 5.40 + fun debug(fmt: String, vararg args: Any?) { 5.41 + logger.log(Level.FINE, fmt, args) 5.42 + } 5.43 + fun warn(fmt: String, vararg args: Any?) { 5.44 + logger.log(Level.WARNING, fmt, args) 5.45 + } 5.46 + fun error(fmt: String, vararg args: Any?) { 5.47 + logger.log(Level.SEVERE, fmt, args) 5.48 + } 5.49 + fun trace(fmt: String, vararg args: Any?) { 5.50 + logger.log(Level.FINEST, fmt, args) 5.51 + } 5.52 + 5.53 + fun info(msg: String, ex: Throwable) { 5.54 + logger.log(Level.INFO, msg, ex) 5.55 + } 5.56 + fun debug(msg: String, ex: Throwable) { 5.57 + logger.log(Level.FINE, msg, ex) 5.58 + } 5.59 + fun warn(msg: String, ex: Throwable) { 5.60 + logger.log(Level.WARNING, msg, ex) 5.61 + } 5.62 + fun error(msg: String, ex: Throwable) { 5.63 + logger.log(Level.SEVERE, msg, ex) 5.64 + } 5.65 + fun trace(msg: String, ex: Throwable) { 5.66 + logger.log(Level.FINEST, msg, ex) 5.67 + } 5.68 +}
6.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Sun Dec 12 18:16:46 2021 +0100 6.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Wed Dec 15 19:56:05 2021 +0100 6.3 @@ -25,8 +25,11 @@ 6.4 6.5 package de.uapcore.lightpit.servlet 6.6 6.7 -import de.uapcore.lightpit.* 6.8 +import de.uapcore.lightpit.AbstractServlet 6.9 +import de.uapcore.lightpit.HttpRequest 6.10 +import de.uapcore.lightpit.boolValidator 6.11 import de.uapcore.lightpit.dao.DataAccessObject 6.12 +import de.uapcore.lightpit.dateOptValidator 6.13 import de.uapcore.lightpit.entities.* 6.14 import de.uapcore.lightpit.types.IssueCategory 6.15 import de.uapcore.lightpit.types.IssueStatus 6.16 @@ -533,7 +536,7 @@ 6.17 dao.updateComment(comment) 6.18 dao.insertHistoryEvent(issue, comment) 6.19 } else { 6.20 - logger().debug("Not updating comment ${comment.id} because nothing changed.") 6.21 + logger.debug("Not updating comment ${comment.id} because nothing changed.") 6.22 } 6.23 } else { 6.24 http.response.sendError(403) 6.25 @@ -592,7 +595,7 @@ 6.26 dao.updateIssue(issue) 6.27 dao.insertHistoryEvent(issue) 6.28 } else { 6.29 - logger().debug("Not updating issue ${issue.id} because nothing changed.") 6.30 + logger.debug("Not updating issue ${issue.id} because nothing changed.") 6.31 } 6.32 6.33 val newComment = http.param("comment")
7.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/UsersServlet.kt Sun Dec 12 18:16:46 2021 +0100 7.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/UsersServlet.kt Wed Dec 15 19:56:05 2021 +0100 7.3 @@ -25,7 +25,10 @@ 7.4 7.5 package de.uapcore.lightpit.servlet 7.6 7.7 -import de.uapcore.lightpit.* 7.8 +import de.uapcore.lightpit.AbstractServlet 7.9 +import de.uapcore.lightpit.HttpRequest 7.10 +import de.uapcore.lightpit.ValidatedValue 7.11 +import de.uapcore.lightpit.ValidationError 7.12 import de.uapcore.lightpit.dao.DataAccessObject 7.13 import de.uapcore.lightpit.entities.User 7.14 import de.uapcore.lightpit.viewmodel.UserEditView 7.15 @@ -33,7 +36,7 @@ 7.16 import javax.servlet.annotation.WebServlet 7.17 7.18 @WebServlet(urlPatterns = ["/users/*"]) 7.19 -class UsersServlet : AbstractServlet(), LoggingTrait { 7.20 +class UsersServlet : AbstractServlet() { 7.21 7.22 init { 7.23 get("/", this::index) 7.24 @@ -91,7 +94,6 @@ 7.25 } 7.26 7.27 if (user.id > 0) { 7.28 - logger().info("Update user with id ${user.id}.") 7.29 dao.updateUser(user) 7.30 http.renderCommit("users/") 7.31 } else { 7.32 @@ -103,7 +105,6 @@ 7.33 }, "", errorMessages) 7.34 7.35 if (errorMessages.isEmpty()) { 7.36 - logger().info("Insert user ${user.username}.") 7.37 dao.insertUser(user) 7.38 http.renderCommit("users/") 7.39 } else {