Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to disable the logger? #60

Closed
AObuchow opened this issue Mar 30, 2020 · 19 comments
Closed

Is there a way to disable the logger? #60

AObuchow opened this issue Mar 30, 2020 · 19 comments

Comments

@AObuchow
Copy link
Contributor

First off, I just wanted to say this library is perfect for my needs - it's a really awesome project!

I'm using it to build a music player which has a command line interface, and have an issue where the logger from com.goxr3plus.streamplayer.stream.StreamPlayer is outputting to stdout, which is cluttering the UI.

Is there a way to disable logging? Or redirect it to a file perhaps?

I tried disabling it from my code which uses java-strean-player but was unsuccesful.

I would also be willing to submit a PR if required for this :)

Thank you!

@goxr3plus
Copy link
Owner

Hm , can you send me a screenshot , like what it outputs , it's been a long time an i forgot the code :)

@goxr3plus
Copy link
Owner

I had a look on the code

private static final Logger logger = Logger.getLogger(StreamPlayer.class.getName());

Try searching on web how to disable specific logger , or completely from the application the loggers if you don't need .

I am not sure if i have the most right Logging architecture for this project , i was Junior Developer when i wrote this :)

@AObuchow
Copy link
Contributor Author

Thanks for the quick reply @goxr3plus :)
I was able to disable the logging by adding a log filter.

However, com.goxr3plus.streamplayer.stream.StreamPlayerEventLauncher isin't getting filtered as its using system.out. I can see that this was fixed, as mentioned in #23, however it seems that the latest version (9.0.4) of java-stream-player available on https://jitpack.io/#goxr3plus/java-stream-player doesn't have this fix.

Would you kindly deploy the latest version of java-stream-player to jitpack.io? :) That should fix my issue!

@goxr3plus
Copy link
Owner

Hm you are right, since then @HelgeStenstrom did a ton of updates and we need a new release along with a small guide with examples on how to use .

@AObuchow
Copy link
Contributor Author

Glad we found the source of the problem! I'm sure the new updates will be greatly appreciated by users of the library :)

Do you think you would be able to release it before adding the guides/examples on how to use? (Perhaps hold off on updating the artifact version used in the README until the guides are ready, but do a silent release?)

@goxr3plus
Copy link
Owner

goxr3plus commented Mar 30, 2020 via email

@AObuchow
Copy link
Contributor Author

I can definetly wait till tomorrow (or even longer, as I understand we all have our own lives/priorities and you're already doing me a big favour :) ).
And for sure, I'll let you know if I encounter further bugs along the way :)

@goxr3plus
Copy link
Owner

goxr3plus commented Mar 30, 2020 via email

@goxr3plus
Copy link
Owner

@AObuchow I just released version 10.0.0 , would you like to be a contributor on this project ? I will send you now invitation link . You can modify stuff around and send me a pull request , i think you are a senior developer based on your github profile :)

@goxr3plus
Copy link
Owner

I send you collaborator link , please be careful what you modifying :) , get the latest release from jitpack => https://jitpack.io/private#goxr3plus/java-stream-player/10.0.0

@AObuchow
Copy link
Contributor Author

@AObuchow I just released version 10.0.0 , would you like to be a contributor on this project ? I will send you now invitation link . You can modify stuff around and send me a pull request , i think you are a senior developer based on your github profile :)

Thank you so much @goxr3plus for releasing version 10.0.0 (and also, congrats on the release 🎉!).
Being a contributor will help if I find any bugs or potential improvements, so thank you! And in all honesty, I'm still a junior developer myself but I'm familiar with contributor guidelines (eg. I wouldn't think about merging something without approal) :)

@AObuchow
Copy link
Contributor Author

I send you collaborator link , please be careful what you modifying :) , get the latest release from jitpack => https://jitpack.io/private#goxr3plus/java-stream-player/10.0.0

Thank you! :)

@goxr3plus
Copy link
Owner

goxr3plus commented Mar 31, 2020

@AObuchow Don't worry when i started this library i was even more junior , i din't knew what static means in Java :) ahahah

@AObuchow
Copy link
Contributor Author

@AObuchow Don't worry when i started this library i was even more junior , i din't knew what static means in Java :) ahahah

Hahah okay :) We all have to start somewhere! :)

@HelgeStenstrom
Copy link
Collaborator

HelgeStenstrom commented Mar 31, 2020

I haven't read the whole thread, but the start of it.
You can disable logging by the StreamPlayer class, by using the constructor

public StreamPlayer(Logger logger) {
this(logger,
Executors.newSingleThreadExecutor(new ThreadFactoryWithNamePrefix("StreamPlayer")),
Executors.newSingleThreadExecutor(new ThreadFactoryWithNamePrefix("StreamPlayerEvent")));
}

and call it with a logger that doesn't log. I've done that for testing purposes; an example can be found in

@BeforeEach
void setup() {
final Logger logger = mock(Logger.class);
player = new StreamPlayer(logger);
audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
}

You can use any class that extends Logger.

@AObuchow
Copy link
Contributor Author

AObuchow commented Apr 1, 2020

@HelgeStenstrom Thank you so much for the tip! This seems to be a nicer solution than adding a log filter, I'll give it a try tonight :)

@AObuchow
Copy link
Contributor Author

AObuchow commented Apr 1, 2020

@goxr3plus BTW, I just started using version 10.0.0 and it's working as expected 🎉

@AObuchow
Copy link
Contributor Author

AObuchow commented Apr 1, 2020

@HelgeStenstrom passing a logger that doesn't log in the StreamPlayer constructor works perfectly! Thanks for the advice.

@lockieluke
Copy link

This is written in Kotlin but this is how you can remove the loggers with DeclaredField:

val disableStreamPlayerLogger = {
    val loggerField = StreamPlayer::class.java.getDeclaredField("logger")
    loggerField.isAccessible = true
    val logger: Logger = loggerField.get(streamPlayer) as Logger
    logger.useParentHandlers = false
}

val disableOutletLogger = {
    val loggerField = Outlet::class.java.getDeclaredField("logger")
    loggerField.isAccessible = true
    val logger: Logger = loggerField.get(streamPlayer.outlet) as Logger
    logger.useParentHandlers = false
}

disableOutletLogger()
disableStreamPlayerLogger()

Java version(converted using ChatGPT):

public static void disableStreamPlayerLogger() throws NoSuchFieldException, IllegalAccessException {
    Field loggerField = StreamPlayer.class.getDeclaredField("logger");
    loggerField.setAccessible(true);
    Logger logger = (Logger) loggerField.get(streamPlayer);
    logger.setUseParentHandlers(false);
}

public static void disableOutletLogger() throws NoSuchFieldException, IllegalAccessException {
    Field loggerField = Outlet.class.getDeclaredField("logger");
    loggerField.setAccessible(true);
    Logger logger = (Logger) loggerField.get(streamPlayer.outlet);
    logger.setUseParentHandlers(false);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants