java.util.logging.Level Scala Examples
The following examples show how to use java.util.logging.Level.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: TestUtils.scala From iodb with Creative Commons Zero v1.0 Universal | 5 votes |
package io.iohk.iodb import java.io.File import java.nio.ByteBuffer import java.util.concurrent.{ExecutorService, TimeUnit} import java.util.logging.Level import scala.util.Random def runningTime[A](computation: => A): (Long, A) = { val s = System.currentTimeMillis() val res = computation (System.currentTimeMillis() - s, res) } def fromLong(id: Long): ByteArrayWrapper = { val b = ByteBuffer.allocate(8) b.putLong(0, id) ByteArrayWrapper(b.array()) } def runnable(f: => Unit): Runnable = return () => { try { f } catch { case e: Throwable => { Utils.LOG.log(Level.SEVERE, "Background task failed", e) } } } def waitForFinish(exec: ExecutorService): Unit = { exec.shutdown() exec.awaitTermination(400, TimeUnit.DAYS) } def withTempDir(ff: (File) => Unit) { val iFile = TestUtils.tempDir() try { ff(iFile) } finally { TestUtils.deleteRecur(iFile) } } }
Example 2
Source File: LogRecordTest.scala From scala-js-java-logging with BSD 3-Clause "New" or "Revised" License | 5 votes |
package org.scalajs.testsuite.javalib.util.logging import java.util.logging.{Level, LogRecord} import org.junit.Test import org.junit.Assert._ class LogRecordTest { @Test def test_constructor(): Unit = { val record = new LogRecord(Level.INFO, "msg") assertEquals(Level.INFO, record.getLevel) record.setLevel(Level.FINE) assertEquals(Level.FINE, record.getLevel) assertTrue(record.getSequenceNumber >= 0) record.setSequenceNumber(256L) assertEquals(256L, record.getSequenceNumber) assertNull(record.getLoggerName) record.setLoggerName("logger") assertEquals("logger", record.getLoggerName) record.setLoggerName(null) assertNull(record.getLoggerName) assertNull(record.getSourceClassName) record.setSourceClassName("MyClass") assertEquals("MyClass", record.getSourceClassName) record.setSourceClassName(null) assertNull(record.getSourceClassName) assertNull(record.getSourceMethodName) record.setSourceMethodName("method") assertEquals("method", record.getSourceMethodName) record.setSourceMethodName(null) assertNull(record.getSourceMethodName) assertEquals("msg", record.getMessage) record.setMessage("newmsg") assertEquals("newmsg", record.getMessage) record.setMessage(null) assertNull(record.getMessage) assertNull(record.getParameters) record.setParameters(Array[AnyRef]("value")) assertArrayEquals(Array[AnyRef]("value"), record.getParameters) record.setParameters(null) assertNull(record.getParameters) assertEquals(Thread.currentThread().getId, record.getThreadID.toLong) record.setThreadID(5) assertEquals(5L, record.getThreadID.toLong) assertTrue(record.getMillis <= System.currentTimeMillis()) record.setMillis(1) assertEquals(1L, record.getMillis) assertNull(record.getThrown) record.setThrown(new RuntimeException("testmsg")) assertEquals("testmsg", record.getThrown.getMessage) record.setThrown(null) assertNull(record.getThrown) } @Test def test_parameter_reference(): Unit = { val params = Array[AnyRef]("abc", "cde") val record = new LogRecord(Level.INFO, "msg") record.setParameters(params) // Change the params reference params(0) = "101" assertEquals("101", record.getParameters()(0)) } }
Example 3
Source File: SimpleFormatterTest.scala From scala-js-java-logging with BSD 3-Clause "New" or "Revised" License | 5 votes |
package org.scalajs.testsuite.javalib.util.logging import java.util.logging.{Level, LogRecord, SimpleFormatter} import org.junit.{Before, Test} import org.junit.Assert._ import org.scalajs.testsuite.utils.Platform class SimpleFormatterTest { @Before def clearProperties():Unit = { System.clearProperty("java.util.logging.SimpleFormatter.format") } @Test def test_default_format(): Unit = { val f = new SimpleFormatter() val r = new LogRecord(Level.INFO, "message") r.setLoggerName("logger") assertTrue(f.format(r).contains("message")) assertTrue(f.format(r).contains("logger")) } @Test def test_format_with_params(): Unit = { val f = new SimpleFormatter() val msg = "message with params {0} {1}" val r = new LogRecord(Level.INFO, msg) assertTrue(f.format(r).contains(msg)) val r1 = new LogRecord(Level.INFO, msg) r1.setParameters(Array("param1")) assertTrue(f.format(r1).contains("message with params param1 {1}")) val r2 = new LogRecord(Level.INFO, msg) r2.setParameters(Array("param1", new java.lang.Integer(20))) assertTrue(f.format(r2).contains("message with params param1 20")) // Bogus cases val r3 = new LogRecord(Level.INFO, "message with params {0} {abc}") r3.setParameters(Array("param1", "test")) assertTrue(f.format(r3).contains("message with params {0} {abc}")) val r4 = new LogRecord(Level.INFO, "message with params {0} {{1}}") r4.setParameters(Array("param1", "test")) assertTrue(f.format(r4).contains("message with params {0} {{1}}")) val r5 = new LogRecord(Level.INFO, "message with params {0} {{1}") r5.setParameters(Array("param1", "test")) assertTrue(f.format(r5).contains("message with params {0} {{1}")) val r6 = new LogRecord(Level.INFO, "message with params {0} {-1}") r6.setParameters(Array("param1", "test")) assertTrue(f.format(r6).contains("message with params {0} {-1}")) val r7 = new LogRecord(Level.INFO, "message with params {0} {1") r7.setParameters(Array("param1", "test")) assertTrue(f.format(r7).contains("message with params {0} {1")) } @Test def test_format_property(): Unit = { System.setProperty("java.util.logging.SimpleFormatter.format", "%3$s - %5$s") val f = new SimpleFormatter() val r = new LogRecord(Level.INFO, "message") r.setLoggerName("logger") // The JVM has a different logic for formatting though the javadocs // indicate that the property above should be used if (!Platform.executingInJVM) assertEquals("logger - message", f.format(r)) } }
Example 4
Source File: LevelTest.scala From scala-js-java-logging with BSD 3-Clause "New" or "Revised" License | 5 votes |
package org.scalajs.testsuite.javalib.util.logging import java.util.logging.Level import org.junit.Assert._ import org.junit.Test class LevelTest { @Test def test_static(): Unit = { assertEquals("OFF", Level.OFF.getName) assertEquals(Int.MaxValue, Level.OFF.intValue()) assertEquals("SEVERE", Level.SEVERE.getName) assertEquals(1000, Level.SEVERE.intValue()) assertEquals("WARNING", Level.WARNING.getName) assertEquals(900, Level.WARNING.intValue()) assertEquals("INFO", Level.INFO.getName) assertEquals(800, Level.INFO.intValue()) assertEquals("CONFIG", Level.CONFIG.getName) assertEquals(700, Level.CONFIG.intValue()) assertEquals("FINE", Level.FINE.getName) assertEquals(500, Level.FINE.intValue()) assertEquals("FINER", Level.FINER.getName) assertEquals(400, Level.FINER.intValue()) assertEquals("FINEST", Level.FINEST.getName) assertEquals(300, Level.FINEST.intValue()) assertEquals("ALL", Level.ALL.getName) assertEquals(Int.MinValue, Level.ALL.intValue()) } @Test def test_equals_hash_code(): Unit = { assertEquals(Level.SEVERE, Level.SEVERE) assertSame(Level.SEVERE, Level.SEVERE) assertFalse(Level.SEVERE == Level.WARNING) assertNotSame(Level.SEVERE, Level.WARNING) assertEquals(Level.SEVERE.hashCode(), Level.SEVERE.hashCode()) } }
Example 5
Source File: Logging.scala From wookiee with Apache License 2.0 | 5 votes |
package com.webtrends.harness.logging import java.util.logging.Level import java.util.logging.Level._ import akka.actor.Actor import scala.util.Try trait LoggingAdapter { @transient protected lazy val log: Logger = Logger(getClass) // Will log the error if the input function throws one and return a Try def tryAndLogError[A](f: => A, messageOnFail: Option[String] = None, level: Level = WARNING): Try[A] = { val tried = Try(f) if (tried.isFailure) { val ex = tried.failed.get val message = messageOnFail.getOrElse(ex.getMessage) level match { case SEVERE => log.error(message, ex) case INFO => log.info(message, ex) case FINE => log.info(message, ex) case CONFIG => log.debug(message, ex) case FINER => log.debug(message, ex) case FINEST => log.trace(message, ex) case WARNING => log.warn(message, ex) case _ => log.warn(message, ex) } } tried } }
Example 6
Source File: TokenAbstractAutorizingInInterceptor.scala From meteorite-core with Apache License 2.0 | 5 votes |
package bi.meteorite.core.security.authorization import java.lang.reflect.Method import java.util import java.util.logging.Level import org.apache.cxf.common.logging.LogUtils import org.apache.cxf.interceptor.security.{AbstractAuthorizingInInterceptor, AccessDeniedException} import org.apache.cxf.message.Message //remove if not needed import scala.collection.JavaConversions._ object TokenAbstractAutorizingInInterceptor { private val LOG = LogUtils.getL7dLogger(classOf[TokenAbstractAutorizingInInterceptor]) private val ALL_ROLES = "*" } abstract class TokenAbstractAutorizingInInterceptor(uniqueId: Boolean) extends AbstractAuthorizingInInterceptor(uniqueId) { def this() { this(true) } override def handleMessage(message: Message) { val method = getTargetMethod(message) val sc = message.get(classOf[javax.ws.rs.core.SecurityContext]) if (sc == null) { val sc2 = message.get(classOf[org.apache.cxf.security.SecurityContext]) if (authorize(sc2, method)) { return } } else if (sc.getUserPrincipal != null) { if (authorize(sc, method)) { return } } else if (!isMethodProtected(method) && isAllowAnonymousUsers) { return } throw new AccessDeniedException("Unauthorized") } protected def authorize(sc: javax.ws.rs.core.SecurityContext, method: Method): Boolean = { val expectedRoles = getExpectedRoles(method) if (expectedRoles.isEmpty) { val denyRoles = getDenyRoles(method) return denyRoles.isEmpty || isUserInRole(sc, denyRoles, deny = true) } if (isUserInRole(sc, expectedRoles, deny = false)) { return true } if (TokenAbstractAutorizingInInterceptor.LOG.isLoggable(Level.FINE)) { TokenAbstractAutorizingInInterceptor.LOG.fine(sc.getUserPrincipal.getName + " is not authorized") } false } protected def isUserInRole(sc: javax.ws.rs.core.SecurityContext, roles: util.List[String], deny: Boolean): Boolean = { if (roles.size == 1 && TokenAbstractAutorizingInInterceptor.ALL_ROLES == roles.get(0)) { return !deny } for (role <- roles if sc.isUserInRole(role)) { return !deny } deny } }
Example 7
Source File: LogLevel.scala From airframe with Apache License 2.0 | 5 votes |
package wvlet.log import java.util.logging.Level object LogLevel { case object OFF extends LogLevel(0, Level.OFF, "off") case object ERROR extends LogLevel(1, Level.SEVERE, "error") case object WARN extends LogLevel(2, Level.WARNING, "warn") case object INFO extends LogLevel(3, Level.INFO, "info") case object DEBUG extends LogLevel(4, Level.FINE, "debug") case object TRACE extends LogLevel(5, Level.FINER, "trace") case object ALL extends LogLevel(6, Level.ALL, "all") val values = IndexedSeq(OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL) private lazy val index = values.map { l => l.name.toLowerCase -> l }.toMap private lazy val jlLevelIndex = values.map { l => l.jlLevel -> l }.toMap def apply(name: String): LogLevel = { val n = name.toLowerCase() val lv = values.find(n == _.name) if (lv.isEmpty) { Console.err.println(s"Unknown log level [${name}] Use info log level instead.") INFO } else lv.get } def apply(jlLevel: Level): LogLevel = { jlLevelIndex.get(jlLevel) match { case Some(l) => l case None => jlLevel match { case Level.CONFIG => INFO case Level.FINEST => TRACE } } } def unapply(name: String): Option[LogLevel] = index.get(name.toLowerCase) implicit object LogOrdering extends Ordering[LogLevel] { override def compare(x: LogLevel, y: LogLevel): Int = x.order - y.order } } sealed abstract class LogLevel(val order: Int, val jlLevel: Level, val name: String) extends Ordered[LogLevel] with Serializable { def compare(other: LogLevel) = this.order - other.order }
Example 8
Source File: HttpAccessLogWriter.scala From airframe with Apache License 2.0 | 5 votes |
package wvlet.airframe.http.finagle.filter import java.util.logging.Level import wvlet.airframe.codec.MessageCodec import wvlet.log.{AsyncHandler, LogFormatter, LogRecord, LogRotationHandler} case class HttpAccessLogConfig( fileName: String = "log/http_access.json", maxFiles: Int = 100, maxSize: Long = 100 * 1024 * 1024 ) class InMemoryAccessLogWriter extends HttpAccessLogWriter { private var logs = Seq.newBuilder[Map[String, Any]] def getLogs: Seq[Map[String, Any]] = logs.result() def clear(): Unit = { logs.clear() } override def write(log: Map[String, Any]): Unit = { synchronized { logs += log } } } }
Example 9
Source File: BatchTokenizeTweets.scala From open-korean-text with Apache License 2.0 | 5 votes |
package org.openkoreantext.processor.qa import java.util.logging.{Level, Logger} import org.openkoreantext.processor.OpenKoreanTextProcessor import org.openkoreantext.processor.tokenizer.KoreanTokenizer.KoreanToken import org.openkoreantext.processor.util.KoreanPos import scala.io.Source object BatchTokenizeTweets { case class ParseTime(time: Long, chunk: String) private val LOG = Logger.getLogger(getClass.getSimpleName) private val VERBOSE = true private val NON_NOUNS = Set(KoreanPos.Adjective, KoreanPos.Adverb, KoreanPos.Verb) def main(args: Array[String]) { if (args.length != 1) { println("The first arg should be an input file of Korean tweets.") return } val parseTimesAll = Source.fromFile(args(0)).getLines().foldLeft(List[ParseTime]()) { case (l: List[ParseTime], line: String) => val t0 = System.currentTimeMillis() val parsed = OpenKoreanTextProcessor.tokenize(line) val t1 = System.currentTimeMillis() if (VERBOSE) { println(parsed.map(t => t.text + "/" + t.pos).mkString(" ")) } ParseTime(t1 - t0, line.trim) :: l } val loadingTime = parseTimesAll.last LOG.log(Level.INFO, "The first one \"%s\" took %d ms including the loading time.".format(loadingTime.chunk, loadingTime.time)) val parseTimes = parseTimesAll.init val averageTweetLength = parseTimes.map(_.chunk.length).sum.toDouble / parseTimes.size val averageTime = parseTimes.map(_.time).sum.toDouble / parseTimes.size val maxItem = parseTimes.maxBy(_.time) LOG.log(Level.INFO, ("Parsed %d items. \n" + " Total time: %d s \n" + " Average tweet length: %.2f chars \n" + " Average time per tweet: %.2f ms \n" + " Max time: %d ms, %s\n" + " Parsed: %s" ).format( parseTimes.size, parseTimes.map(_.time).sum / 1000, averageTweetLength, averageTime, maxItem.time, maxItem.chunk, OpenKoreanTextProcessor.tokenize(maxItem.chunk).map { case t if t.unknown => t.text.toString + t.pos + "*" case t => t.text + t.pos.toString }.mkString(" ") )) } private def parseToString(parsed: Seq[KoreanToken]): String = { parsed.map { case t if t.unknown => t.text.toString + t.pos + "*" case t => t.text + t.pos.toString }.mkString(" ") } }
Example 10
Source File: TestBase.scala From open-korean-text with Apache License 2.0 | 5 votes |
package org.openkoreantext.processor import java.util.logging.{Level, Logger} import org.junit.runner.RunWith import org.openkoreantext.processor.util.KoreanDictionaryProvider._ import org.scalatest.FunSuite import org.scalatest.junit.JUnitRunner object TestBase { case class ParseTime(time: Long, chunk: String) def time[R](block: => R): Long = { val t0 = System.currentTimeMillis() block val t1 = System.currentTimeMillis() t1 - t0 } def assertExamples(exampleFiles: String, log: Logger, f: (String => String)) { assert({ val input = readFileByLineFromResources(exampleFiles) val (parseTimes, hasErrors) = input.foldLeft((List[ParseTime](), true)) { case ((l: List[ParseTime], output: Boolean), line: String) => val s = line.split("\t") val (chunk, parse) = (s(0), if (s.length == 2) s(1) else "") val oldTokens = parse val t0 = System.currentTimeMillis() val newTokens = f(chunk) val t1 = System.currentTimeMillis() val oldParseMatches = oldTokens == newTokens if (!oldParseMatches) { System.err.println("Example set match error: %s \n - EXPECTED: %s\n - ACTUAL : %s".format( chunk, oldTokens, newTokens)) } (ParseTime(t1 - t0, chunk) :: l, output && oldParseMatches) } val averageTime = parseTimes.map(_.time).sum.toDouble / parseTimes.size val maxItem = parseTimes.maxBy(_.time) log.log(Level.INFO, ("Parsed %d chunks. \n" + " Total time: %d ms \n" + " Average time: %.2f ms \n" + " Max time: %d ms, %s").format( parseTimes.size, parseTimes.map(_.time).sum, averageTime, maxItem.time, maxItem.chunk )) hasErrors }, "Some parses did not match the example set.") } } @RunWith(classOf[JUnitRunner]) abstract class TestBase extends FunSuite
Example 11
Source File: LogPlugin.scala From AppCrawler with Apache License 2.0 | 5 votes |
package com.testerhome.appcrawler.plugin import java.util.logging.Level import com.testerhome.appcrawler.driver.AppiumClient import com.testerhome.appcrawler.{Plugin, URIElement} import scala.collection.mutable.ListBuffer import scala.reflect.io.File class LogPlugin extends Plugin { private var logs = ListBuffer[String]() val driver = getCrawler().driver.asInstanceOf[AppiumClient].driver override def afterElementAction(element: URIElement): Unit = { //第一次先试验可用的log 后续就可以跳过从而加速 if (logs.isEmpty) { driver.manage().logs().getAvailableLogTypes.toArray().foreach(logName => { log.info(s"read log=${logName.toString}") try { saveLog(logName.toString) logs += logName.toString } catch { case ex: Exception => log.warn(s"log=${logName.toString} not exist") } }) } if(getCrawler().getElementAction()!="skip") { logs.foreach(log => { saveLog(log) }) } } def saveLog(logName:String): Unit ={ log.info(s"read log=${logName.toString}") val logMessage = driver.manage().logs.get(logName.toString).filter(Level.ALL).toArray() log.info(s"log=${logName} size=${logMessage.size}") if (logMessage.size > 0) { val fileName = getCrawler().getBasePathName()+".log" log.info(s"save ${logName} to $fileName") File(fileName).writeAll(logMessage.mkString("\n")) log.info(s"save ${logName} end") } } override def afterUrlRefresh(url: String): Unit = { } override def stop(): Unit ={ logs.foreach(log => { saveLog(log) }) } }
Example 12
Source File: DynamoDBEmbeddedSpecSupport.scala From reactive-aws-clients with MIT License | 5 votes |
package com.github.j5ik2o.reactive.aws.dynamodb import java.io.File import java.util.logging.{ Level, Logger } import com.amazonaws.auth.{ AWSStaticCredentialsProvider, BasicAWSCredentials } import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration import com.amazonaws.regions.Regions import com.amazonaws.services.dynamodbv2.local.server.{ DynamoDBProxyServer, LocalDynamoDBRequestHandler, LocalDynamoDBServerHandler } import com.amazonaws.services.dynamodbv2.{ AmazonDynamoDB, AmazonDynamoDBClientBuilder } import com.github.j5ik2o.reactive.aws.test.RandomPortSupport import org.scalatest.{ BeforeAndAfterAll, Suite } import org.seasar.util.io.ResourceUtil import scala.concurrent.duration._ @SuppressWarnings(Array("org.wartremover.warts.Null", "org.wartremover.warts.Var", "org.wartremover.warts.While")) trait DynamoDBEmbeddedSpecSupport extends BeforeAndAfterAll with RandomPortSupport { this: Suite => protected val waitIntervalForDynamoDBLocal: FiniteDuration = 500 milliseconds protected def sqlite4javaLibraryPath: File = new File(ResourceUtil.getBuildDir(getClass), "/../../../native-libs") protected val region: Regions = Regions.AP_NORTHEAST_1 protected lazy val accessKeyId: String = "x" protected lazy val secretAccessKey: String = "x" protected lazy val dynamoDBPort: Int = temporaryServerPort() protected lazy val dynamoDBEndpoint: String = s"http://127.0.0.1:$dynamoDBPort" protected lazy val dynamoDBProxyServer: DynamoDBProxyServer = { System.setProperty("sqlite4java.library.path", sqlite4javaLibraryPath.toString) val inMemory = true // scalastyle:off val dbPath = null val sharedDb = false val corsParams = null // scalastyle:on new DynamoDBProxyServer( dynamoDBPort, new LocalDynamoDBServerHandler( new LocalDynamoDBRequestHandler(0, inMemory, dbPath, sharedDb, false), corsParams ) ) } protected lazy val dynamoDBClient: AmazonDynamoDB = { AmazonDynamoDBClientBuilder .standard().withCredentials( new AWSStaticCredentialsProvider( new BasicAWSCredentials(accessKeyId, secretAccessKey) ) ) .withEndpointConfiguration( new EndpointConfiguration(dynamoDBEndpoint, region.getName) ).build() } protected def waitDynamoDBLocal(): Unit = { var isWaken: Boolean = false while (!isWaken) { try { dynamoDBClient.listTables() isWaken = true } catch { case _: Exception => Thread.sleep(waitIntervalForDynamoDBLocal.toMillis) } } } protected def startDynamoDBLocal(): Unit = { Logger.getLogger("com.almworks.sqlite4java").setLevel(Level.OFF) dynamoDBProxyServer.start() } protected def shutdownDynamoDBLocal(): Unit = { dynamoDBProxyServer.stop() } override protected def beforeAll(): Unit = { super.beforeAll() startDynamoDBLocal() waitDynamoDBLocal() } override protected def afterAll(): Unit = { shutdownDynamoDBLocal() super.afterAll() } }
Example 13
Source File: Logging.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.app import com.twitter.app.App import com.twitter.finagle.http.filter.LoggingFilter import java.util.logging.Level import java.util.logging.LogManager import org.slf4j.bridge.SLF4JBridgeHandler trait Logging { self: App => init { // Turn off Java util logging so that slf4j can configure it LogManager.getLogManager.getLogger("").getHandlers.toList.foreach { l => l.setLevel(Level.OFF) } org.slf4j.LoggerFactory.getLogger("slf4j-logging").debug("Installing SLF4JLogging") SLF4JBridgeHandler.install() // Override Logger config to use the parent handler LoggingFilter.log.setUseParentHandlers(true) } onExit { org.slf4j.LoggerFactory.getLogger("slf4j-logging").debug("Uninstalling SLF4JLogging") SLF4JBridgeHandler.uninstall() } }
Example 14
Source File: TestCapabilities.scala From scala-js-env-selenium with BSD 3-Clause "New" or "Revised" License | 5 votes |
package org.scalajs.jsenv.selenium import org.openqa.selenium.Capabilities import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxDriverLogLevel} import org.openqa.selenium.chrome.ChromeOptions import java.util.logging.{Logger, Level} object TestCapabilities { // Lower the logging level for Selenium to avoid spam. Logger.getLogger("org.openqa.selenium").setLevel(Level.WARNING) def fromEnv: Capabilities = nameFromEnv match { case "firefox" => new FirefoxOptions() .setHeadless(true) .setLogLevel(FirefoxDriverLogLevel.ERROR) case "chrome" => new ChromeOptions() .setHeadless(true) case name => throw new IllegalArgumentException(s"Unknown browser $name") } def nameFromEnv: String = sys.env.getOrElse("SJS_TEST_BROWSER", "firefox") }
Example 15
Source File: HelloWorldClient.scala From grpc-scala-sample with BSD 3-Clause "New" or "Revised" License | 5 votes |
package io.grpc.examples.helloworld import java.util.concurrent.TimeUnit import java.util.logging.{Level, Logger} import io.grpc.examples.helloworld.helloworld.{HelloRequest, GreeterGrpc} import io.grpc.examples.helloworld.helloworld.GreeterGrpc.GreeterBlockingStub import io.grpc.{StatusRuntimeException, ManagedChannelBuilder, ManagedChannel} def greet(name: String): Unit = { logger.info("Will try to greet " + name + " ...") val request = HelloRequest(name = name) try { val response = blockingStub.sayHello(request) logger.info("Greeting: " + response.message) } catch { case e: StatusRuntimeException => logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus) } } }