From a210c1ec3b0aa462f2427ac0587e86d19bf8c117 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Mon, 11 Jan 2021 16:48:49 -0600 Subject: [PATCH] 2021 01 09 issue 2496 (#2500) * WIP: Get something working that isn't network specific Start putting things back in place Add comment Revert logback file Remove BitcoinSLogger object * fix unit test * Network specific log location Co-authored-by: benthecarman --- .../server/routes/BitcoinSRunner.scala | 30 ++++++++++++++----- .../bitcoins/server/BitcoinSServerMain.scala | 4 +-- .../scala/org/bitcoins/db/AppConfig.scala | 4 +-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/server-routes/src/main/scala/org/bitcoins/server/routes/BitcoinSRunner.scala b/app/server-routes/src/main/scala/org/bitcoins/server/routes/BitcoinSRunner.scala index ed0440b225..0e2c637a83 100644 --- a/app/server-routes/src/main/scala/org/bitcoins/server/routes/BitcoinSRunner.scala +++ b/app/server-routes/src/main/scala/org/bitcoins/server/routes/BitcoinSRunner.scala @@ -62,7 +62,7 @@ trait BitcoinSRunner extends BitcoinSLogger { argsWithIndex.find(_._1.toLowerCase == "--conf").map(_._2) } - val datadirConfig: Config = + lazy val datadirConfig: Config = ConfigFactory.parseString( s"bitcoin-s.datadir = ${safePathToString(datadirPath)}") @@ -97,9 +97,21 @@ trait BitcoinSRunner extends BitcoinSLogger { val networkDatadir: Path = { val networkStr: String = baseConfig.getString("bitcoin-s.network") - val network: BitcoinNetwork = - BitcoinNetworks.fromString(networkStr) - lazy val lastDirname = network match { + + val network: BitcoinNetwork = networkStr.toLowerCase match { + case "mainnet" => MainNet + case "main" => MainNet + case "testnet3" => TestNet3 + case "testnet" => TestNet3 + case "test" => TestNet3 + case "regtest" => RegTest + case "signet" => SigNet + case "sig" => SigNet + case _: String => + throw new IllegalArgumentException(s"Invalid network $networkStr") + } + + val lastDirname = network match { case MainNet => "mainnet" case TestNet3 => "testnet3" case RegTest => "regtest" @@ -108,12 +120,16 @@ trait BitcoinSRunner extends BitcoinSLogger { datadir.resolve(lastDirname) } - logger.info(s"version=${EnvUtil.getVersion}") - - // Properly set log location + //We need to set the system property before any logger instances + //are in instantiated. If we don't do this, we will not log to + //the correct location + //see: https://github.com/bitcoin-s/bitcoin-s/issues/2496 System.setProperty("bitcoins.log.location", networkDatadir.toAbsolutePath.toString) + logger.info(s"version=${EnvUtil.getVersion}") + + logger.info(s"networkDatadir=${networkDatadir.toAbsolutePath.toString}") val runner = startup runner.failed.foreach { err => logger.error(s"Failed to startup server!", err) diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala index f1cf6bed63..9ddb6f4212 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala @@ -3,7 +3,6 @@ package org.bitcoins.server import akka.actor.ActorSystem import akka.dispatch.Dispatchers import akka.http.scaladsl.Http -import grizzled.slf4j.Logging import org.bitcoins.chain.blockchain.ChainHandler import org.bitcoins.chain.config.ChainAppConfig import org.bitcoins.chain.models._ @@ -26,8 +25,7 @@ import org.bitcoins.wallet.config.WalletAppConfig import scala.concurrent.{ExecutionContext, Future, Promise} class BitcoinSServerMain(override val args: Array[String]) - extends BitcoinSRunner - with Logging { + extends BitcoinSRunner { override val actorSystemName = "bitcoin-s-server" diff --git a/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala b/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala index 3d49460b72..d012c7d698 100644 --- a/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala +++ b/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala @@ -122,8 +122,8 @@ abstract class AppConfig extends StartStopAsync[Unit] with BitcoinSLogger { protected lazy val config: Config = { val finalConfig = AppConfig.getBaseConfig(baseDatadir, configOverrides) - logger.debug(s"Resolved bitcoin-s config:") - logger.debug(finalConfig.asReadableJson) + logger.trace(s"Resolved bitcoin-s config:") + logger.trace(finalConfig.asReadableJson) val resolved = { ConfigFactory