0

I'm making a Maven-based java library which the logging used is this:

    import java.util.logging.Logger;
    private static final Logger LOG 
        = Logger.getLogger(MyLibraryClass.class.getName())

I have coded so many log in this library, that is very useful in debugging the flow of the library, specially during JUnit tests, however this app I created, I don't want it to show the logs to a client application (an application that will use this library). Since it is too verbose.

How do I control which gets logged into a client application's log view. Logs like INFO level from the library does not necessarily show up in the client/sample app?

Here is my ultimate goal:

  • To have a log as verbose as possible when running Unit test in the library project
  • But not show these "verbose" logs to the client application, without the need for the client application to deliberately configure/suppress the logs from the library

Client library - is the project that is used by a Java application; which is the project I am working on. Which generates logs that should not be displayed in the client application.

Client application - is the project/application that uses the Java library

Community
  • 1
  • 1
quarks
  • 33,478
  • 73
  • 290
  • 513
  • If you are using log4j, see http://stackoverflow.com/questions/24231773/specifying-a-custom-log4j-properties-file-for-all-of-junit-tests-run-from-eclips – Raedwald Jan 23 '15 at 20:02

4 Answers4

1

I am not sure if you are looking for this

 LOGGER.setLevel(Level.INFO); 
M Sach
  • 33,416
  • 76
  • 221
  • 314
1

The Client-App needs his own tests. I dont understand why the Client-lib shouldnt be released if there are problems in the Client-App anyway (just a dead-end-situation).

I see two maven-projects.

  • The Library (with Library-Tests)
  • The Client-App (with Client-App-Tests) with a dependency to the Library

So you have for the Library a noop-config-file in

/src/test/java/resources/logging.properties 

and in the Client-App a noop-config-file in

/src/main/java/resources/logging.properties

Such a noop-config looks like this:

handlers= java.util.logging.ConsoleHandler
level= SEVERE
Grim
  • 1,938
  • 10
  • 56
  • 123
0

Configure log level in log4j.properties or log4j.xml

Use separate log4j.properties for your Unit test.

In maven put a log4j.properties or log4j.xml file into src/test/resources

Or use CLI properties when running junit

-Dlog4j.configuration=<path to properties file>
qwazer
  • 7,174
  • 7
  • 44
  • 69
0

You are giving your log messages too high a priority. All INFO, WARN and ERROR messages should be messages you would expect your users to see. If a message is useful only to developers, it should be DEBUG or TRACE. Then configure your logging lubrary to display only INFO, WARN and ERROR messages.

Raedwald
  • 46,613
  • 43
  • 151
  • 237