Skip to content

Commit

Permalink
Navigator: Print important messages to stderr (digital-asset#522)
Browse files Browse the repository at this point in the history
* Navigator: Print important messages to stderr

All messages that users need to act on are now printed to
stderr, in addition to the log file.

Otherwise, it is confusing to users why they have to start
Navigator twice.

Fixes digital-asset#112
  • Loading branch information
rautenrieth-da authored Apr 16, 2019
1 parent ae89a0d commit 8655a79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion navigator/backend/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
<appender-ref ref="FILE"/>
</appender>

<!-- Some important messages are written to stderr -->
<logger name="user-facing-logs" level="INFO" additivity="true">
<appender-ref ref="STDERR"/>
</logger>

<!-- All log messages are written asynchronously to a file -->
<root level="INFO">
<!-- <appender-ref ref="STDERR"/> -->
<appender-ref ref="ASYNC"/>
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.digitalasset.navigator.model.{Ledger, PackageRegistry}
import com.digitalasset.navigator.store.Store.Subscribe
import com.digitalasset.navigator.store.platform.PlatformStore
import com.typesafe.scalalogging.LazyLogging
import org.slf4j.LoggerFactory
import pureconfig.error.ConfigReaderException
import sangria.schema._
import spray.json._
Expand All @@ -50,6 +51,8 @@ abstract class UIBackend extends LazyLogging with ApplicationInfoJsonSupport {
def applicationInfo: ApplicationInfo
def banner: Option[String] = None

private[this] def userFacingLogger = LoggerFactory.getLogger("user-facing-logs")

/** Allow subclasses to customize config file name, but don't require it
* (supply a default)
*/
Expand Down Expand Up @@ -283,9 +286,9 @@ abstract class UIBackend extends LazyLogging with ApplicationInfoJsonSupport {
case DumpGraphQLSchema =>
dumpGraphQLSchema()
case RunServer if !Files.exists(configFile) =>
logger.error(
s"No configuration file found! A a configuration template file will be created at " +
s"${configFile}, please edit it and restart the UI backend")
val message = "No configuration file found! A configuration template file will be created at " +
s"$configFile, please edit it and restart ${applicationInfo.name}"
userFacingLogger.error(message)
Config.writeTemplateToPath(configFile, args.useDatabase)
case RunServer =>
Config.load(configFile, args.useDatabase) match {
Expand All @@ -295,7 +298,7 @@ abstract class UIBackend extends LazyLogging with ApplicationInfoJsonSupport {
throw exception
case Right(config) if config.users.isEmpty =>
logger.error("No users found in the configuration file!")
throw new RuntimeException("No users found in the configuration file!")
sys.error("No users found in the configuration file!")
case Right(config) =>
runServer(args, config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.digitalasset.navigator.ApplicationInfo
import io.grpc.netty.{GrpcSslContexts, NettyChannelBuilder}
import io.grpc.{ManagedChannel, Status}
import io.netty.handler.ssl.SslContext
import org.slf4j.LoggerFactory

import scala.util.{Failure, Random, Success, Try}
import scala.concurrent.Future
Expand Down Expand Up @@ -97,6 +98,8 @@ class PlatformStore(
.nextLong()
.toHexString

private[this] def userFacingLogger = LoggerFactory.getLogger("user-facing-logs")

import PlatformStore._

// ----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -125,7 +128,9 @@ class PlatformStore(

case Connected(Failure(e)) =>
// Connection failed even after several retries - not sure how to recover from this
log.error("Giving up. Please fix any issues and restart this application.")
val message = s"Permanently failed to connect to the ledger at $platformHost:$platformPort. " +
"Please fix any issues and restart this application."
userFacingLogger.error(message)
context.become(failed(StateFailed(e)))

case GetApplicationStateInfo =>
Expand Down

0 comments on commit 8655a79

Please sign in to comment.