Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Log4jKettleLayout and log messages arguments substitution

  1. #1
    Join Date
    Jun 2008
    Posts
    21

    Default Log4jKettleLayout and log messages arguments substitution

    Hello,

    I have a logging issue when my log message has arguments: if I log

    log.logBasic("my log message {0}", "my parameter");

    with a Log4jFileAppender, I'll get

    my log message {0}

    instead of

    my log message my parameter

    With the ConsoleAppender, I'll get the correct log.

    I compared the 'Layout' classes that are used in both cases, it seems that the Log4jKettleLayout calls LogMessage.getMessage in order to build the log message (which doesn't substitute the parameters) whereas the layout used with ConsoleAppender calls LogMessage.toString() (which substitutes the parameters correctly).
    Is this a bug in Log4jKettleLayout?? If not, how do I get arguments substitution when using Log4jKettleLayout?

    Furthermore, I noticed that the logging api has changed in PDI 4.xxx: no need to specify the subject when logging something. But in the code, I can still find calls to logging api like:

    log.logDebug(toString(), BaseMessages.getString(PKG, "GPG.RunningCommand", command));

    How can the substitution work provided that what used to be the subject (=toString()) is now the main message and doesn't contain the {0},{1}...

    Thanks,

    Regards,
    Nicolas

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    log.logBasic("my log message {0}", "my parameter");
    I'm not sure what would be the point of this substitution since you could simply do it in Java. What's the usecase?
    Normally folks would do it for i18n but Kettle has it's own system for that. (including a UI to translate)

    log.logDebug(toString(), BaseMessages.getString(PKG, "GPG.RunningCommand", command));
    If you find any more of those feel free to let us know so we can fix them.

    I don't think there's a bug in the Kettle Log4J layout class but that being said I can't wait to get rid of the Log4J dependency ;-)

  3. #3
    Join Date
    Jun 2008
    Posts
    21

    Default

    Hi,

    Thanks for your answer.
    My example was a bit stupid because the argument is a constant but the idea behind using the varargs when logging is to avoid string concatenation when you don't log: if you do
    Code:
    log.logBasic("the message " + argument1)
    you'll always concatenate the string to be loggued, which can be costly and useless in case the log level is not appropriate. The only way to avoid concatenation is to add an
    Code:
    if (log.isBasic())
    before, which makes the code dirty.
    By using the api with varargs:
    Code:
    log.logBasic("the message {0}", argument1)
    you avoid concatenation in case of inappropriate log level. This is why this api should be used I think.
    But it seems to me that Log4jKettleLayout doesn't do the substitution.

    Regards,
    Nicolas


    Quote Originally Posted by MattCasters View Post
    I'm not sure what would be the point of this substitution since you could simply do it in Java. What's the usecase?
    Normally folks would do it for i18n but Kettle has it's own system for that. (including a UI to translate)



    If you find any more of those feel free to let us know so we can fix them.

    I don't think there's a bug in the Kettle Log4J layout class but that being said I can't wait to get rid of the Log4J dependency ;-)

  4. #4
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    The substitution is actually a lot more costly than a simple concatenation so putting the if (log.isDetailed()) in front of the line is very important (just like it is with log4j or the other logging frameworks).

    Anyway, you either work with it or fight the system :-)

    Here is some information on i18n to allow you to properly translate your plugins:

    http://wiki.pentaho.com/display/EAI/...ationalization

    A complete Kettle plugin SDK is underway, should be released shortly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.