Skip to content

Commit d36ea92

Browse files
committed
Remove unnecessary log level checks
The play.api.Logger API uses call by name parameters for the message arguments. They will be evaluated at each point they are used not at the point they are called. More information is available in http://eed3si9n.com/scala-and-evaluation-strategy and in http://www.scala-lang.org/docu/files/ScalaReference.pdf section 4.6.1 By-Name Parameters ( this document is for scala 2.9 but the call by name mechanism has not been changed significantly between the 2 versions)
1 parent 47b6006 commit d36ea92

9 files changed

+19
-47
lines changed

module-code/app/securesocial/controllers/LoginPage.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ object LoginPage extends Controller
4444
val to = ProviderController.landingUrl
4545
if ( SecureSocial.currentUser.isDefined ) {
4646
// if the user is already logged in just redirect to the app
47-
if ( logger.isDebugEnabled ) {
48-
logger.debug("User already logged in, skipping login page. Redirecting to %s".format(to))
49-
}
47+
logger.debug("User already logged in, skipping login page. Redirecting to %s".format(to))
5048
Redirect( to )
5149
} else {
5250
import com.typesafe.plugin._

module-code/app/securesocial/controllers/ProviderController.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ object ProviderController extends Controller with SecureSocial
117117
request.user match {
118118
case Some(currentUser) =>
119119
UserService.link(currentUser, user)
120-
if ( logger.isDebugEnabled ) {
121-
logger.debug(s"[securesocial] linked $currentUser to $user")
122-
}
120+
logger.debug(s"[securesocial] linked $currentUser to $user")
123121
// improve this, I'm duplicating part of the code in completeAuthentication
124122
Redirect(toUrl(modifiedSession)).withSession(modifiedSession-
125123
SecureSocial.OriginalUrlKey -

module-code/app/securesocial/controllers/Registration.scala

+2-6
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ object Registration extends Controller {
191191
*/
192192
def signUp(token: String) = Action { implicit request =>
193193
if (registrationEnabled) {
194-
if ( logger.isDebugEnabled ) {
195-
logger.debug("[securesocial] trying sign up with token %s".format(token))
196-
}
194+
logger.debug("[securesocial] trying sign up with token %s".format(token))
197195
executeForToken(token, true, { _ =>
198196
Ok(use[TemplatesPlugin].getSignUpPage(form, token))
199197
})
@@ -221,9 +219,7 @@ object Registration extends Controller {
221219
executeForToken(token, true, { t =>
222220
form.bindFromRequest.fold (
223221
errors => {
224-
if ( logger.isDebugEnabled ) {
225-
logger.debug("[securesocial] errors " + errors)
226-
}
222+
logger.debug("[securesocial] errors " + errors)
227223
BadRequest(use[TemplatesPlugin].getSignUpPage(errors, t.uuid))
228224
},
229225
info => {

module-code/app/securesocial/core/OAuth1Provider.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ abstract class OAuth1Provider(application: Application) extends IdentityProvider
8888
// the oauth_verifier field is not in the request, this is the 1st step in the auth flow.
8989
// we need to get the request tokens
9090
val callbackUrl = RoutesHelper.authenticate(id).absoluteURL(IdentityProvider.sslEnabled)
91-
if ( logger.isDebugEnabled ) {
92-
logger.debug("[securesocial] callback url = " + callbackUrl)
93-
}
91+
logger.debug("[securesocial] callback url = " + callbackUrl)
9492
service.retrieveRequestToken(callbackUrl) match {
9593
case Right(accessToken) =>
9694
val cacheKey = UUID.randomUUID().toString

module-code/app/securesocial/core/OAuth2Provider.scala

+5-10
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ abstract class OAuth2Provider(application: Application, jsonResponse: Boolean =
8383

8484
protected def buildInfo(response: Response): OAuth2Info = {
8585
val json = response.json
86-
if ( logger.isDebugEnabled ) {
87-
logger.debug("[securesocial] got json back [" + json + "]")
88-
}
86+
logger.debug("[securesocial] got json back [" + json + "]")
8987
OAuth2Info(
9088
(json \ OAuth2Constants.AccessToken).as[String],
9189
(json \ OAuth2Constants.TokenType).asOpt[String],
@@ -121,9 +119,7 @@ abstract class OAuth2Provider(application: Application, jsonResponse: Boolean =
121119
)
122120
SocialUser(IdentityId("", id), "", "", "", None, None, authMethod, oAuth2Info = oauth2Info)
123121
}
124-
if ( logger.isDebugEnabled ) {
125-
logger.debug("[securesocial] user = " + user)
126-
}
122+
logger.debug("[securesocial] user = " + user)
127123
user match {
128124
case Some(u) => Right(u)
129125
case _ => throw new AuthenticationException()
@@ -142,10 +138,9 @@ abstract class OAuth2Provider(application: Application, jsonResponse: Boolean =
142138
settings.authorizationUrlParams.foreach( e => { params = e :: params })
143139
val url = settings.authorizationUrl +
144140
params.map( p => URLEncoder.encode(p._1, "UTF-8") + "=" + URLEncoder.encode(p._2, "UTF-8")).mkString("?", "&", "")
145-
if ( logger.isDebugEnabled ) {
146-
logger.debug("[securesocial] authorizationUrl = %s".format(settings.authorizationUrl))
147-
logger.debug("[securesocial] redirecting to: [%s]".format(url))
148-
}
141+
logger.debug("[securesocial] authorizationUrl = %s".format(settings.authorizationUrl))
142+
logger.debug("[securesocial] redirecting to: [%s]".format(url))
143+
149144
Left(Results.Redirect( url ).withSession(request.session + (IdentityProvider.SessionId, sessionId)))
150145
}
151146
}

module-code/app/securesocial/core/SecureSocial.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ trait SecureSocial extends Controller {
128128
}
129129

130130
result.getOrElse({
131-
if ( logger.isDebugEnabled ) {
132-
logger.debug("[securesocial] anonymous user trying to access : '%s'".format(request.uri))
133-
}
131+
logger.debug("[securesocial] anonymous user trying to access : '%s'".format(request.uri))
134132
val response = if ( ajaxCall ) {
135133
ajaxCallNotAuthenticated(request)
136134
} else {

module-code/app/securesocial/core/UserService.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ abstract class UserServicePlugin(application: Application) extends Plugin with U
137137
cancellable = if ( UsernamePasswordProvider.enableTokenJob ) {
138138
Some(
139139
Akka.system.scheduler.schedule(0.seconds, i.minutes) {
140-
if ( logger.isDebugEnabled ) {
141-
logger.debug("[securesocial] calling deleteExpiredTokens()")
142-
}
140+
logger.debug("[securesocial] calling deleteExpiredTokens()")
143141
deleteExpiredTokens()
144142
}
145143
)

module-code/app/securesocial/core/providers/utils/Mailer.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ object Mailer {
7878
import scala.concurrent.duration._
7979
import play.api.libs.concurrent.Execution.Implicits._
8080

81-
if ( Logger.isDebugEnabled ) {
82-
logger.debug("[securesocial] sending email to %s".format(recipient))
83-
logger.debug("[securesocial] mail = [%s]".format(body))
84-
}
81+
logger.debug("[securesocial] sending email to %s".format(recipient))
82+
logger.debug("[securesocial] mail = [%s]".format(body))
83+
8584

8685
Akka.system.scheduler.scheduleOnce(1.seconds) {
8786
val mail = use[MailerPlugin].email

module-code/app/securesocial/core/providers/utils/RoutesHelper.scala

+4-12
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ object RoutesHelper {
8585

8686
lazy val assets = {
8787
val clazz = conf.getString("securesocial.assetsController").getOrElse("controllers.ReverseAssets")
88-
if ( logger.isDebugEnabled ) {
89-
logger.debug("[securesocial] assets controller = %s".format(clazz))
90-
}
88+
logger.debug("[securesocial] assets controller = %s".format(clazz))
9189
Play.application().classloader().loadClass(clazz)
9290
}
9391

@@ -118,9 +116,7 @@ object RoutesHelper {
118116
*/
119117
val bootstrapCssPath = {
120118
val bsPath = conf.getString("securesocial.bootstrapCssPath").getOrElse(defaultBootstrapCssPath)
121-
if ( logger.isDebugEnabled ) {
122-
logger.debug("[securesocial] bootstrap path = %s".format(bsPath))
123-
}
119+
logger.debug("[securesocial] bootstrap path = %s".format(bsPath))
124120
at(bsPath)
125121
}
126122

@@ -131,9 +127,7 @@ object RoutesHelper {
131127
*/
132128
val faviconPath = {
133129
val favPath = conf.getString("securesocial.faviconPath").getOrElse(defaultFaviconPath)
134-
if ( logger.isDebugEnabled ) {
135-
logger.debug("[securesocial] favicon path = %s".format(favPath))
136-
}
130+
logger.debug("[securesocial] favicon path = %s".format(favPath))
137131
at(favPath)
138132
}
139133

@@ -144,9 +138,7 @@ object RoutesHelper {
144138
*/
145139
val jqueryPath = {
146140
val jqueryPath = conf.getString("securesocial.jqueryPath").getOrElse(defaultJqueryPath)
147-
if ( logger.isDebugEnabled ) {
148-
logger.debug("[securesocial] Jquery path = %s".format(jqueryPath))
149-
}
141+
logger.debug("[securesocial] Jquery path = %s".format(jqueryPath))
150142
at(jqueryPath)
151143
}
152144

0 commit comments

Comments
 (0)