You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Aristedes Maniatis <am...@apache.org> on 2014/08/24 10:31:57 UTC

new catching syntax

Congratulations on the version 2 release. It looks great. A question though about the recommended way to use the new 'catching syntax. We used to do this:

    catch (Exception e ) {
      logger.warn("Failed to import report: " + path, e);

But now the new lifecycle syntax has some advantages. We can do this:

    catch (Exception e ) {
      logger.catching(e);

But it would be useful for me to log the path which ultimately caused the exception. Except that I cannot do this:

    catch (Exception e ) {
      logger.catching("Failed to import report: {}", path, e);


What is the recommended approach here? Avoid the lifecycle style syntax? Call the logger twice, once with my message and variable and once with the exception?


Thanks
Ari


-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: new catching syntax

Posted by Ralph Goers <ra...@dslextreme.com>.
Note that a call to catching(e) results in 

logMessage(FQCN, Level.ERROR, CATCHING_MARKER, catchingMsg(t), t);

Notice that the message is already filled in with the string “catching”, so specifying another message string wouldn’t make any sense. As Matt said, if you want more than just the single work “catching” as the message then do:

logger.error(AbstractLogger.CATCHING_MARKER, “Failed to import report. {}”, path, e);

Ralph

On Aug 24, 2014, at 9:40 AM, Matt Sicker <bo...@gmail.com> wrote:

> Use of catching/throwing is primarily for use in catching/throwing
> exceptions without any additional information that can't be obtained from
> the logger call. Basically, there are no calls like logger.error(e) for
> when you want to log just the exception, so instead you could use
> logger.catching(e). If you want to add more information, you should use the
> error/warn/etc. methods instead as you thought.
> 
> 
> On 24 August 2014 03:31, Aristedes Maniatis <am...@apache.org> wrote:
> 
>> Congratulations on the version 2 release. It looks great. A question
>> though about the recommended way to use the new 'catching syntax. We used
>> to do this:
>> 
>>    catch (Exception e ) {
>>      logger.warn("Failed to import report: " + path, e);
>> 
>> But now the new lifecycle syntax has some advantages. We can do this:
>> 
>>    catch (Exception e ) {
>>      logger.catching(e);
>> 
>> But it would be useful for me to log the path which ultimately caused the
>> exception. Except that I cannot do this:
>> 
>>    catch (Exception e ) {
>>      logger.catching("Failed to import report: {}", path, e);
>> 
>> 
>> What is the recommended approach here? Avoid the lifecycle style syntax?
>> Call the logger twice, once with my message and variable and once with the
>> exception?
>> 
>> 
>> Thanks
>> Ari
>> 
>> 
>> --
>> -------------------------->
>> Aristedes Maniatis
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: new catching syntax

Posted by Matt Sicker <bo...@gmail.com>.
Use of catching/throwing is primarily for use in catching/throwing
exceptions without any additional information that can't be obtained from
the logger call. Basically, there are no calls like logger.error(e) for
when you want to log just the exception, so instead you could use
logger.catching(e). If you want to add more information, you should use the
error/warn/etc. methods instead as you thought.


On 24 August 2014 03:31, Aristedes Maniatis <am...@apache.org> wrote:

> Congratulations on the version 2 release. It looks great. A question
> though about the recommended way to use the new 'catching syntax. We used
> to do this:
>
>     catch (Exception e ) {
>       logger.warn("Failed to import report: " + path, e);
>
> But now the new lifecycle syntax has some advantages. We can do this:
>
>     catch (Exception e ) {
>       logger.catching(e);
>
> But it would be useful for me to log the path which ultimately caused the
> exception. Except that I cannot do this:
>
>     catch (Exception e ) {
>       logger.catching("Failed to import report: {}", path, e);
>
>
> What is the recommended approach here? Avoid the lifecycle style syntax?
> Call the logger twice, once with my message and variable and once with the
> exception?
>
>
> Thanks
> Ari
>
>
> --
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>