I am starting out with ReactiveMongo, and while log level is set to debug
I see the following print to the log:
application - ReactiveMongoApi starting...
reactivemongo.api.MongoDriver - No mongo-async-driver configuration found
application - ReactiveMongoApi successfully configured with DB 'mydb'! Servers:
[mongodb:27017]
The question is: Do I have anything to be concerened about with that no async driver found? and why is it beeing printed.
The ReactiveMongo package is looking for some configuration. it doesn't mean that the driver operation will not be async because no configuration was found.
To get rid of the error, you can add configuration in the application.conf
Example:
mongo-async-driver {
akka {
loggers = [ "akka.event.slf4j.Slf4jLogger" ]
loglevel = DEBUG
}
}
Related
When I run tests in Play 2.6.x that are using the WsTestClient like:
WsTestClient.withClient { client => ...
I see in the logs:
[info] p.a.t.WsTestClient$SingletonWSClient - createNewClient: name = ws-test-client-1
Which I believe is coming from this line
Why is it logging as Info if it's set at log-level warn? Can I silence the noise somehow?
I have a class with a custom logger. Here's a trivial example:
package models
import play.Logger
object AModel {
val log = Logger.of("amodel")
def aMethod() {
if (! log.isInfoEnabled) log.error("Can't log info...")
log.info("Logging aMethod in AModel")
}
}
and then we'll enable this logger in application.conf:
logger.amodel=DEBUG
and in development (Play console, use run) this logger does indeed log. But in production, once we hit the message
[info] play - Application started (Prod)
loggers defined like the above logger fail to log any further and instead we go through the error branch. It seems their log level has been changed to ERROR.
Is there anyway to correct this undesirable state of affairs? Is there special configuration for production logs?
edit
Play's handling of logs in production is a source of difficulty to more than a few people... https://github.com/playframework/playframework/issues/1186
For some reason it ships its own logger.xml which overrides application.conf.
I am implementing a file storage service, which is taking a file and saving it into gridFS with special metadata. Of course, I want to be sure everything's working in integration -- files are really stored in database and then retrieved from it.
I use Play Framework 2.1.3 Scala and ReactiveMongo 0.9.
My test cases looks like the following:
"show empty uploaded size on init" in {
running(FakeApplication()) {
Await.result(FileStorage.getFilesSize(profileId), duration) must beNone
}
}
I have tried to wrap every case with running, or all cases, or even Thread.sleep. But database is always up after test fails.
[error] There is no started application
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$.current(Play.scala:51)
[error] content.FileStorage$.db$lzycompute(FileStorage.scala:32)
...
[info] Total for specification FileStorageSpec
[info] Finished in 21 ms
[info] 5 examples, 1 failure, 4 errors
[info]
[info] application - ReactiveMongoPlugin starting...
[info] application - ReactiveMongoPlugin successfully started with db 'test'! Servers:
[localhost:27017]
[info] play - Starting application default Akka system.
[info] play - Shutdown application default Akka system.
What am I doing wrong? How do you test ReactiveMongo applications?
In the FileStorage object you have these lines:
lazy val db = ReactiveMongoPlugin.db
val gridFS = GridFS(db, "file")
val collection = db.collection[JSONCollection]("file.files")
collection.indexesManager.ensure(Index(Seq("metadata.profileId" -> IndexType.Ascending)))
When the object is instantiated, the above lines of code are executed. Since you have no control of object instantiation you can not be sure when that happens.
It will probably help to change the lines into this:
def db = ReactiveMongoPlugin.db
def gridFS = GridFS(db, "file")
def collection = {
val collection = db.collection[JSONCollection]("file.files")
collection.indexesManager.ensure(Index(Seq("metadata.profileId" -> IndexType.Ascending)))
collection
}
I have a Play 2.1 application which does not start when I have the wrong database url. The problem is, the error message isn't that great.
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sleeping for 0ms and trying again. A ttempts left: 0. Exception: null
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:74)
at play.api.Configuration.reportError(Configuration.scala:552)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:248)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:239)
....
I'd like the server to dump the database url it's trying to use in this case. Does Play 2.1 provide any hooks to execute code when there is an exception during startup?
In Play Framework 2, you can override certain phases of the lifecycle by extending GlobalSettings. Specifically, onLoadConfig get called before the config is parsed and the DB connection is established.
Here's a (hacky) example of intercepting errors. You can create a fake instance of Application, then pass it the Configuration object. Then you can use it to create an instance of BoneCPPlugin and try creating a connection. In case when the DB is not reachable, you'll be able to intercept that in the catch block.
import java.io.File
import play.api._
import play.api.db.BoneCPPlugin
import scala.util.control.NonFatal
object Global extends GlobalSettings {
override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode) = {
val app = new DefaultApplication(path, classloader, None, mode){
override lazy val configuration = config
}
try {
new BoneCPPlugin(app).onStart()
} catch {
case e: PlayException =>
// handle
case _ => // other types of errors that we don't care about here
}
super.onLoadConfig(config, path, classloader, mode)
}
}
During generic save action of morphia model using CRUD interface I recieve following error:
Oops: NullPointerException An unexpected error occured caused by
exception NullPointerException: null
play.exceptions.UnexpectedException: Unexpected Error at
play.modules.morphia.Model.edit(Model.java:219) at
play.modules.morphia.MorphiaPlugin.bind(MorphiaPlugin.java:607)
...
I've found that similiar error was in version 1.2.4a and was fixed in 1.2.4b.
I downoladed the latest version of morphia. On app start I recieve followind log:
12:18:59,036 INFO ~ Module morphia is available (C:\play-1.2.4\samples-and-tests\test1\modules\ morphia-1.2.4b )
12:18:59,037 INFO ~ Module secure is available (C:\play-1.2.4\modules\secure)
12:18:59,978 WARN ~ You're running Play! in DEV mode
12:19:00,110 INFO ~ Listening for HTTP on port 9000 (Waiting a first request to start) ...
12:19:11,680 INFO ~ Connected to jdbc:mysql://localhost/test1?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci
12:19:14,869 INFO ~ MorphiaPlugin-1.2.4a> initialized
So, now I can't understad what version of morphia I actually use and can't understand how to fix the error.
Please, advice me something about my issue.
I got the problem, in this day morphia doesn't work with play 1.2.4 crud module. You have to rollback to 1.2.3.