Fixed logging to log file for webserver at startup. Removed more redundant config.

This commit is contained in:
Clinton Alexander 2017-03-30 16:59:07 +01:00
parent 5d8217bbc7
commit e3872c1469
5 changed files with 17 additions and 14 deletions

View File

@ -43,6 +43,10 @@ dependencies {
compile "org.jolokia:jolokia-agent-war:$jolokia_version"
compile "commons-fileupload:commons-fileupload:$fileupload_version"
// Log4J: logging framework (with SLF4J bindings)
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
compile "org.apache.logging.log4j:log4j-core:$log4j_version"
// JOpt: for command line flags.
compile "net.sf.jopt-simple:jopt-simple:$jopt_simple_version"

View File

@ -67,7 +67,7 @@ data class CmdLineOptions(val baseDirectory: Path,
allowMissingConfig: Boolean = false,
configOverrides: Map<String, Any?> = emptyMap()): Config {
val parseOptions = ConfigParseOptions.defaults()
val defaultConfig = ConfigFactory.parseResources("reference.conf", parseOptions.setAllowMissing(false))
val defaultConfig = ConfigFactory.parseResources("web-reference.conf", parseOptions.setAllowMissing(false))
val appConfig = ConfigFactory.parseFile(configFile.toFile(), parseOptions.setAllowMissing(allowMissingConfig))
val overrideConfig = ConfigFactory.parseMap(configOverrides + mapOf(
// Add substitution values here

View File

@ -16,19 +16,8 @@ class WebServerConfig(val baseDirectory: Path, val config: Config) : SSLConfigur
override val certificatesDirectory: Path get() = baseDirectory / "certificates"
override val keyStorePassword: String by config
override val trustStorePassword: String by config
val myLegalName: String by config
val exportJMXto: String get() = "http"
val rpcUsers: List<User> = config
.getListOrElse<Config>("rpcUsers") { emptyList() }
.map {
val username = it.getString("user")
require(username.matches("\\w+".toRegex())) { "Username $username contains invalid characters" }
val password = it.getString("password")
val permissions = it.getListOrElse<String>("permissions") { emptyList() }.toSet()
User(username, password, permissions)
}
val useHTTPS: Boolean by config
val p2pAddress: HostAndPort by config
val rpcAddress: HostAndPort? by config
val p2pAddress: HostAndPort by config // TODO: Use RPC port instead of P2P port (RPC requires authentication, P2P does not)
val webAddress: HostAndPort by config
}

View File

@ -21,6 +21,7 @@ import org.eclipse.jetty.webapp.WebAppContext
import org.glassfish.jersey.server.ResourceConfig
import org.glassfish.jersey.server.ServerProperties
import org.glassfish.jersey.servlet.ServletContainer
import org.slf4j.LoggerFactory
import java.lang.reflect.InvocationTargetException
import java.util.*
@ -31,10 +32,11 @@ class NodeWebServer(val config: WebServerConfig) {
}
val address = config.webAddress
private var renderBasicInfoToConsole = true
private lateinit var server: Server
fun start() {
println("Starting as webserver: ${config.webAddress}")
logAndMaybePrint("Starting as webserver: ${config.webAddress}")
server = initWebServer(retryConnectLocalRpc())
}
@ -174,4 +176,11 @@ class NodeWebServer(val config: WebServerConfig) {
val pluginRegistries: List<CordaPluginRegistry> by lazy {
ServiceLoader.load(CordaPluginRegistry::class.java).toList()
}
/** Used for useful info that we always want to show, even when not logging to the console */
fun logAndMaybePrint(description: String, info: String? = null) {
val msg = if (info == null) description else "${description.padEnd(40)}: $info"
val loggerName = if (renderBasicInfoToConsole) "BasicInfo" else "Main"
LoggerFactory.getLogger(loggerName).info(msg)
}
}

View File

@ -0,0 +1 @@
useHTTPS = false