Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:56:29+00:00 2026-06-09T08:56:29+00:00

I usually use Scala with SLF4J through the Loggable wrapper in LiftWeb. This works

  • 0

I usually use Scala with SLF4J through the Loggable wrapper in LiftWeb. This works decently well with the exception of the quite common method made up only from 1 chain of expressions.

So if you want to add logging to such a method, the simply beautiful, no curly brackets

def method1():Z = a.doX(x).doY(y).doZ()

must become:

def method1():Z = {
  val v = a.doX(x).doY(y).doZ()
  logger.info("the value is %s".format(v))
  v
}

Not quite the same, is it? I gave it a try to solve it with this:

class ChainableLoggable[T](val v:T){
  def logInfo(logger:Logger, msg:String, other:Any*):T = {
    logger.info(msg.format(v, other))
    v
  }
}
implicit def anyToChainableLogger[T](v:T):ChainableLoggable[T] = new ChainableLoggable(v)

Now I can use a simpler form

 def method1():Z = a.doX(x).doY(y).doZ() logInfo(logger, "the value is %s") 

However 1 extra object instantiation and an implicit from Any starts to look like a code stink.

Does anyone know of any better solution? Or maybe I shouldn’t even bother with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:56:30+00:00Added an answer on June 9, 2026 at 8:56 am

    Scala 2.10 has just a solution for you – that’s a new feature Value Class which allows you to gain the same effect as the implicit wrappers provide but with no overhead coming from instantiation of those wrapper classes. To apply it you’ll have to rewrite your code like so:

    implicit class ChainableLoggable[T](val v : T) extends AnyVal {
      def logInfo(logger:Logger, msg:String, other:Any*) : T = {
        logger.info(msg.format(v, other))
        v
      }
    }
    

    Under the hood the compiler will transform the logInfo into an analogue of Java’s common “util” static method by prepending your v : T to it’s argument list and updating its usages accordingly – see, nothing gets instantiated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use a boolean 'firstTime' like this: in C++: bool firsTime = true;
I usually use this line to import file from out of the current folder
I usually use a TabControl and somehow hide the tabs and navigate through them.
I usually use like this $ find -name testname.c ./dir1/dir2/testname.c $ vi ./dir1/dir2/testname.c it's
I usually use .Net but now I'm playing Scala in IntelliJ 10.5.1. It's interesting
I usually use code like this: using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[MyConn].ConnectionString)) { var
To add a rectangle to my plot I usually use this code: ret=Rectangle((x_l[i]-dx,y_l[i]-dx),width=dx,height=dx,facecolor='red',linestyle='solid') ax=gca()
I usually use this code to add item from datebase to list view: public
I usually use this private void ensureDiscoverable() { if(D) Log.d(TAG, ensure discoverable); if (mBluetoothAdapter.getScanMode()
I usually use the Ruby on Rails framework but for this project I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.