LOGGER::info is not consumed as s -> LOGGER.info(s)












2















I have defined a logger instance as follows:



private static final Logger LOGGER = Logger.getLogger(Main.class.getName());


I have an array of strings that I want to log, so I used the following:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(LOGGER::info);


However, nothing is printed into the log. But, if I change the reference method to an equivalent lambda form, it prints into the log:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(s -> LOGGER.info(s));


What am I missing here?



I tried the following approaches as well and they all behave the same:



Stream.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);
List.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);


Even Intellij IDE highlights s -> LOGGER.info(s) with yellow and suggests changing it to LOGGER::info.





I tried to define a custom class:



static class Consumer
{
void consume(String s)
{
LOGGER.info(s);
}
}


and use it in place of LOGGER::info:



Consumer consumer = new Consumer();
Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(consumer::consume);


It prints into the log!





The Logger class has two overloaded methods:



void info(String msg)


and



void info(Supplier<String> msgSupplier)


but only the first is assignable to void forEach(Consumer<? super T> action), I believe.










share|improve this question

























  • Interesting... it's working for me well. What version of java did you use?

    – Aleksandr Semyannikov
    Nov 14 '18 at 13:51











  • I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

    – Eng.Fouad
    Nov 14 '18 at 13:52













  • Works for me on java 8u191

    – Julio Daniel Reyes
    Nov 14 '18 at 13:54











  • Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

    – Alex Shesterov
    Nov 14 '18 at 13:54
















2















I have defined a logger instance as follows:



private static final Logger LOGGER = Logger.getLogger(Main.class.getName());


I have an array of strings that I want to log, so I used the following:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(LOGGER::info);


However, nothing is printed into the log. But, if I change the reference method to an equivalent lambda form, it prints into the log:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(s -> LOGGER.info(s));


What am I missing here?



I tried the following approaches as well and they all behave the same:



Stream.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);
List.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);


Even Intellij IDE highlights s -> LOGGER.info(s) with yellow and suggests changing it to LOGGER::info.





I tried to define a custom class:



static class Consumer
{
void consume(String s)
{
LOGGER.info(s);
}
}


and use it in place of LOGGER::info:



Consumer consumer = new Consumer();
Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(consumer::consume);


It prints into the log!





The Logger class has two overloaded methods:



void info(String msg)


and



void info(Supplier<String> msgSupplier)


but only the first is assignable to void forEach(Consumer<? super T> action), I believe.










share|improve this question

























  • Interesting... it's working for me well. What version of java did you use?

    – Aleksandr Semyannikov
    Nov 14 '18 at 13:51











  • I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

    – Eng.Fouad
    Nov 14 '18 at 13:52













  • Works for me on java 8u191

    – Julio Daniel Reyes
    Nov 14 '18 at 13:54











  • Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

    – Alex Shesterov
    Nov 14 '18 at 13:54














2












2








2








I have defined a logger instance as follows:



private static final Logger LOGGER = Logger.getLogger(Main.class.getName());


I have an array of strings that I want to log, so I used the following:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(LOGGER::info);


However, nothing is printed into the log. But, if I change the reference method to an equivalent lambda form, it prints into the log:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(s -> LOGGER.info(s));


What am I missing here?



I tried the following approaches as well and they all behave the same:



Stream.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);
List.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);


Even Intellij IDE highlights s -> LOGGER.info(s) with yellow and suggests changing it to LOGGER::info.





I tried to define a custom class:



static class Consumer
{
void consume(String s)
{
LOGGER.info(s);
}
}


and use it in place of LOGGER::info:



Consumer consumer = new Consumer();
Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(consumer::consume);


It prints into the log!





The Logger class has two overloaded methods:



void info(String msg)


and



void info(Supplier<String> msgSupplier)


but only the first is assignable to void forEach(Consumer<? super T> action), I believe.










share|improve this question
















I have defined a logger instance as follows:



private static final Logger LOGGER = Logger.getLogger(Main.class.getName());


I have an array of strings that I want to log, so I used the following:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(LOGGER::info);


However, nothing is printed into the log. But, if I change the reference method to an equivalent lambda form, it prints into the log:



Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(s -> LOGGER.info(s));


What am I missing here?



I tried the following approaches as well and they all behave the same:



Stream.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);
List.of("ABC", "DEF", "XYZ").forEach(LOGGER::info);


Even Intellij IDE highlights s -> LOGGER.info(s) with yellow and suggests changing it to LOGGER::info.





I tried to define a custom class:



static class Consumer
{
void consume(String s)
{
LOGGER.info(s);
}
}


and use it in place of LOGGER::info:



Consumer consumer = new Consumer();
Arrays.stream(new String{"ABC", "DEF", "XYZ"}).forEach(consumer::consume);


It prints into the log!





The Logger class has two overloaded methods:



void info(String msg)


and



void info(Supplier<String> msgSupplier)


but only the first is assignable to void forEach(Consumer<? super T> action), I believe.







java logging lambda java-stream method-reference






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 13:50







Eng.Fouad

















asked Nov 14 '18 at 13:39









Eng.FouadEng.Fouad

84.9k53248362




84.9k53248362













  • Interesting... it's working for me well. What version of java did you use?

    – Aleksandr Semyannikov
    Nov 14 '18 at 13:51











  • I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

    – Eng.Fouad
    Nov 14 '18 at 13:52













  • Works for me on java 8u191

    – Julio Daniel Reyes
    Nov 14 '18 at 13:54











  • Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

    – Alex Shesterov
    Nov 14 '18 at 13:54



















  • Interesting... it's working for me well. What version of java did you use?

    – Aleksandr Semyannikov
    Nov 14 '18 at 13:51











  • I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

    – Eng.Fouad
    Nov 14 '18 at 13:52













  • Works for me on java 8u191

    – Julio Daniel Reyes
    Nov 14 '18 at 13:54











  • Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

    – Alex Shesterov
    Nov 14 '18 at 13:54

















Interesting... it's working for me well. What version of java did you use?

– Aleksandr Semyannikov
Nov 14 '18 at 13:51





Interesting... it's working for me well. What version of java did you use?

– Aleksandr Semyannikov
Nov 14 '18 at 13:51













I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

– Eng.Fouad
Nov 14 '18 at 13:52







I tried it on both Java 8 and Java 11. Currently, I am using Oracle JDK 11.0.1.

– Eng.Fouad
Nov 14 '18 at 13:52















Works for me on java 8u191

– Julio Daniel Reyes
Nov 14 '18 at 13:54





Works for me on java 8u191

– Julio Daniel Reyes
Nov 14 '18 at 13:54













Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

– Alex Shesterov
Nov 14 '18 at 13:54





Arrays.stream(new String { "ABC", "DEF", "XYZ" }).forEach(LOGGER::info); works fine for me (Java 8), LOGGER being a java.util.logging.Logger.

– Alex Shesterov
Nov 14 '18 at 13:54












1 Answer
1






active

oldest

votes


















3














Consider that code:



Arrays.stream(new String{"ABC"}).forEach(LOGGER::info);
Arrays.stream(new String{"ABC"}).forEach(s -> LOGGER.info(s));


The difference is in the first case source of message is:



java.util.Spliterators$ArraySpliterator


in the second:



Main


Probably your logger has some filter that does not let logging events from java.util.Spliterators$ArraySpliterator class.



Try to check result of LOGGER.getFilter()






share|improve this answer


























  • You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

    – Eng.Fouad
    Nov 14 '18 at 14:13











  • @Eng.Fouad glad to help!

    – Aleksandr Semyannikov
    Nov 14 '18 at 14:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301594%2floggerinfo-is-not-consumed-as-s-logger-infos%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Consider that code:



Arrays.stream(new String{"ABC"}).forEach(LOGGER::info);
Arrays.stream(new String{"ABC"}).forEach(s -> LOGGER.info(s));


The difference is in the first case source of message is:



java.util.Spliterators$ArraySpliterator


in the second:



Main


Probably your logger has some filter that does not let logging events from java.util.Spliterators$ArraySpliterator class.



Try to check result of LOGGER.getFilter()






share|improve this answer


























  • You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

    – Eng.Fouad
    Nov 14 '18 at 14:13











  • @Eng.Fouad glad to help!

    – Aleksandr Semyannikov
    Nov 14 '18 at 14:14
















3














Consider that code:



Arrays.stream(new String{"ABC"}).forEach(LOGGER::info);
Arrays.stream(new String{"ABC"}).forEach(s -> LOGGER.info(s));


The difference is in the first case source of message is:



java.util.Spliterators$ArraySpliterator


in the second:



Main


Probably your logger has some filter that does not let logging events from java.util.Spliterators$ArraySpliterator class.



Try to check result of LOGGER.getFilter()






share|improve this answer


























  • You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

    – Eng.Fouad
    Nov 14 '18 at 14:13











  • @Eng.Fouad glad to help!

    – Aleksandr Semyannikov
    Nov 14 '18 at 14:14














3












3








3







Consider that code:



Arrays.stream(new String{"ABC"}).forEach(LOGGER::info);
Arrays.stream(new String{"ABC"}).forEach(s -> LOGGER.info(s));


The difference is in the first case source of message is:



java.util.Spliterators$ArraySpliterator


in the second:



Main


Probably your logger has some filter that does not let logging events from java.util.Spliterators$ArraySpliterator class.



Try to check result of LOGGER.getFilter()






share|improve this answer















Consider that code:



Arrays.stream(new String{"ABC"}).forEach(LOGGER::info);
Arrays.stream(new String{"ABC"}).forEach(s -> LOGGER.info(s));


The difference is in the first case source of message is:



java.util.Spliterators$ArraySpliterator


in the second:



Main


Probably your logger has some filter that does not let logging events from java.util.Spliterators$ArraySpliterator class.



Try to check result of LOGGER.getFilter()







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 '18 at 18:21

























answered Nov 14 '18 at 14:09









Aleksandr SemyannikovAleksandr Semyannikov

591216




591216













  • You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

    – Eng.Fouad
    Nov 14 '18 at 14:13











  • @Eng.Fouad glad to help!

    – Aleksandr Semyannikov
    Nov 14 '18 at 14:14



















  • You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

    – Eng.Fouad
    Nov 14 '18 at 14:13











  • @Eng.Fouad glad to help!

    – Aleksandr Semyannikov
    Nov 14 '18 at 14:14

















You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

– Eng.Fouad
Nov 14 '18 at 14:13





You got it right. I have a filter that prevents any logging other than from my own packages. Thanks.

– Eng.Fouad
Nov 14 '18 at 14:13













@Eng.Fouad glad to help!

– Aleksandr Semyannikov
Nov 14 '18 at 14:14





@Eng.Fouad glad to help!

– Aleksandr Semyannikov
Nov 14 '18 at 14:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301594%2floggerinfo-is-not-consumed-as-s-logger-infos%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly