Announcement Announcement Module
Collapse
No announcement yet.
injecting a logger Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • injecting a logger

    Dear members,

    In my service classes currently I've got the following:

    protected final Logger logger = Logger.getLogger(getClass());

    How to replace this with injection instead of doing the static lookup as it is done currently? Is it a good idea to do this?

    Thanks!

  • #2
    I would not inject my loggers but use the 'classic' approach. So:
    static Logger log = LogMananger.getLogger(Foo.class);

    What would be the added value of injecting them?

    Comment


    • #3
      I don't know, that's why I'm asking You.

      Maybe one advantage could be that during testing, the presence of log messages could be testable.

      Comment


      • #4
        Originally posted by surfk View Post
        I don't know, that's why I'm asking You.

        Maybe one advantage could be that during testing, the presence of log messages could be testable.
        There is some stuff you want to test, and there is also stuff you really really don't want to test. I'm currently working on a project where logging is tested (because the logging isn't just used for development/operational purposes) and I'm not to happy with it. Especially with mocking you keep recording and recording stuff, so you get way too long test methods that don't express their intent. Eventually you just keep adding crap to tests to make them shut up (this is not the way you should test).. *a frustrated guy*
        Last edited by Alarmnummer; Aug 26th, 2007, 01:20 PM.

        Comment


        • #5
          good point, thanks!

          Comment

          Working...
          X