0

I am writing API that I need to pass to the next developer as a jar file that he/she will use in his program. What is the nice way to write debugg code inside API that will be controlled by the code that is using it.

Thanks a lot.

3 Answers 3

2
  1. Log at different levels: debug level for the nitty-gritty details, info for useful stuff, warn for bad things.
  2. Provide means of testing by exposing your API via interfaces to allow easy mocking. This allows a variety of scenarios to be testing both inside your API, and in the code that's using it.
  3. Provide extension points (using the same interfaces) to allow unforeseen needs to be met as much as possible. (You won't get them all, but that's the way it goes.)
  4. Provide code samples and/or unit tests that exercise the bulk of the API's functionality.
  5. Provide written documentation that explains why things work the way they do. The code explains how it works.
Sign up to request clarification or add additional context in comments.

Comments

0

I think you are talking about debugging log? use log4j:

if (log.isDebugEnabled()) {
    log.debug("xxxxxxxxxxxxxxxxxxxxxxx");
}

UPDATE: log4j can configure the log level for a specific class: put the following in log4j.properties

log4j.logger.com.test.Test=DEBUG

1 Comment

My queston is actually how my logging is going to agree with "outside" logging. THey have their logging level already in the app. And they want to set diferent logging for API calls.
0

If you just ship a JAR, it would be so nice to not depend on log4j in the first place, but let users of your plug in their own "LoggerFactory". All the "Loggers" you obtain in your code are obtained through that factory the same way as you would retrieve them from log4j (e.g. by passing the class name), and should have similar levels.

That way customers who want to use log4j still can, and customers who use another logger can plug it in in a jiffy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.