New logging support to TestNG

834 views
Skip to first unread message

Claude Quezel

unread,
Jun 5, 2006, 11:54:50 PM6/5/06
to testn...@googlegroups.com
TestNG now support logging via a custom logging framework similar to Log4j (http://logging.apache.org/log4j). To enable logging, add a file named "log4testng.properties" to your classpath. The logging levels are TRACE, DEBUG, INFO, WARN, ERROR and FATAL. The property file contains lines in the following format:

# log4testng will log
log4testng.debug=true

# All Logger will log DEBUG level and above
log4testng.rootLogger=DEBUG

# All Logger in packages below org.testng will log WARN level and above
log4testng.logger.org.testng=WARN

In your source files you will typically instantiate and use loggers this ways:

import org.testng.log4testng.Logger;

class ThisClass {
private static final Logger LOGGER = Logger.getLogger(ThisClass.class);

…
LOGGER.debug("entering myMethod()");
…
LOGGER.warn("unknown file: " + filename);
….

Claude
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=33472&messageID=64935#64935

Hani Suleiman

unread,
Jun 5, 2006, 11:58:14 PM6/5/06
to testn...@googlegroups.com
I have to ask (sorry if I've missed emails discussing this) but
what's the reason for having this? Doesn't the world have enough
logging frameworks?

On Jun 5, 2006, at 11:54 PM, Claude Quezel wrote:

>
> TestNG now support logging via a custom logging framework similar
> to Log4j (http://logging.apache.org/log4j). To enable logging, add
> a file named "log4testng.properties" to your classpath. The logging
> levels are TRACE, DEBUG, INFO, WARN, ERROR and FATAL. The property
> file contains lines in the following format:
>
> # log4testng will log
> log4testng.debug=true
>
> # All Logger will log DEBUG level and above
> log4testng.rootLogger=DEBUG
>
> # All Logger in packages below org.testng will log WARN level and
> above
> log4testng.logger.org.testng=WARN
>
> In your source files you will typically instantiate and use loggers
> this ways:
>
> import org.testng.log4testng.Logger;
>
> class ThisClass {
> private static final Logger LOGGER = Logger.getLogger
> (ThisClass.class);
>

> …
> LOGGER.debug("entering myMethod()");
> …


> LOGGER.warn("unknown file: " + filename);

> ….

Claude Quézel

unread,
Jun 6, 2006, 12:06:16 AM6/6/06
to testng-dev
Hani Suleiman wrote:
> I have to ask (sorry if I've missed emails discussing this) but
> what's the reason for having this? Doesn't the world have enough
> logging frameworks?

I agree but one of the goals of TestNG (from what I read) is to have a
stand-alone JAR file. The API is designed to be replaced by log4j. I
don't think packaging one of the most common JAR file (log4j) with
testng is a wise choice. So I opted for the other solution. I would
gladly replace it if design goal are changed.

Claude

Brett Porter

unread,
Jun 6, 2006, 12:08:12 AM6/6/06
to testn...@googlegroups.com
Given that TestNG requires JDK 1.4, is JDK logging not suitable?

Cheers,
Brett


--
Apache Maven - http://maven.apache.org
"Better Builds with Maven" book - http://library.mergere.com/

Hani Suleiman

unread,
Jun 6, 2006, 12:10:39 AM6/6/06
to testn...@googlegroups.com
I'd say the verbosity setting was good enough, really. Most users
should never need to see a single message from testng, the only
usefulness of that is to show bugs, which should get fewer and fewer
over time!

Claude Quézel

unread,
Jun 6, 2006, 12:32:10 AM6/6/06
to testng-dev
Hani Suleiman wrote:
> I'd say the verbosity setting was good enough, really.

The verbosity setting is an all or nothing setting (not very useful in
some/most situation). For example, TestNG now generates a warning when
parsing fails when scanning for JavaDoc annotations in files that
contain JDK5+ features. What can I do to silence it^

Hani Suleiman wrote:
> Most users should never need to see a single message from testng,

Hani Suleiman wrote:

Typically logging is rarely for users. It is for developpers (sometimes
helping users) to help locate bugs and identify problems.

> the only usefulness of that is to show bugs, which should get fewer and fewer
> over time!

I slightly disagree here. Logging is usefull for many things (tracing
to help debugging, profilling (using timestamp, ...). Logging is barely
used in testng (maybe because of unflexible support). Most logging
statement are commented out (see all those ppp) maybe because there was
no way to do it dynamically!

Claude

Jesse Kuhnert

unread,
Jun 6, 2006, 12:33:00 AM6/6/06
to testn...@googlegroups.com
I've never supported a product with as large a user base as testng (not one that I created myself at least), but on the rare occurrence when ~something~ is going wrong and you don't have a dev env handy logging can sometimes be useful. (though I agree that if for some reason it is deemed good to incorporate a logging api the jre bundled version would be preferrable )

My design opinions shouldn't be taken too seriously though as a testing api doesn't seem to be your every day sort of "framework" to throw everything at library wise. Ie should be small efficient and do it's job well?

Open source based consulting work centered around dojo/tapestry/tacos/hivemind.

Claude Quézel

unread,
Jun 6, 2006, 12:35:49 AM6/6/06
to testng-dev

Brett Porter wrote:
> Given that TestNG requires JDK 1.4, is JDK logging not suitable?
>
> Cheers,
> Brett
Agreed

Claude

Cédric Beust ♔

unread,
Jun 6, 2006, 2:26:35 AM6/6/06
to testn...@googlegroups.com
Hi Claude,

I'm perplexed.  Did we ever discuss this?  I share Hani's doubts on the necessity of this in a testing framework, especially if it ties us to another external package.

Also, I didn't see any check-in, did I miss them?

I'd like to be convinced it's really a win for TestNG users to have TestNG offer its own logging package, even if it's log4j (what if they want to use their own version of log4j?  I don't want to see the Velocity nightmare happen to TestNG).

--
Cedric




On 6/5/06, Claude Quezel <testn...@opensymphony.com> wrote:

TestNG now support logging via a custom logging framework similar to Log4j ( http://logging.apache.org/log4j). To enable logging, add a file named "log4testng.properties" to your classpath. The logging levels are TRACE, DEBUG, INFO, WARN, ERROR and FATAL. The property file contains lines in the following format:

Alexandru Popescu

unread,
Jun 6, 2006, 2:26:40 AM6/6/06
to testn...@googlegroups.com
#: Claude Quezel changed the world a bit at a time by saying (astral date: 6/6/2006 6:54 AM) :#

I am a little confused by why this would be needed. If we would need such thing, most probably we
would have used the logging from 1.4 which is the minimal version TestNG supports.

br,

./alex
--
.w( the_mindstorm )p.


Cédric Beust ♔

unread,
Jun 6, 2006, 2:32:20 AM6/6/06
to testn...@googlegroups.com
Ok, I just took a look at the check-in.  I'm glad to see it's only one class that mimicks log4j's functionality.  Good.

I am still very skeptical that this is useful at all, but well, it's a fairly limited change, so we can leave it in...

Next time, please let's discuss such ideas on this mailing-list so that everybody can voice their opinion.  If we had, I'm not sure you would have proceeded further in front of the general skepticism I have seen expressed so far...

--
Cedric
--
Cédric

Claude Quézel

unread,
Jun 6, 2006, 8:15:05 AM6/6/06
to testng-dev

Cédric Beust ♔ wrote:
> I am still very skeptical that this is useful at all, but well, it's a
> fairly limited change, so we can leave it in...

Cedric, I'm a bit confused here. You say you are skeptical that this is
useful yet there are 163 definitions of the static ppp method (which is
a logging method) in testng. For example:

public static void ppp(String s) {
System.out.println("[SuiteRunner] " + s);
}

private static void ppp(String s) {
if (false) {
System.out.println("[ThreadPoolSizeTest] " + s);
}

There are 387 occurence of ppp (most of them in tests though).

// for (Method m : result) {
// ppp(" METHOD FOUND: " + m);
// }

Some of them commented out. So basically, I think logging is already in
used and usefull in testngl.

Claude

Claude Quézel

unread,
Jun 6, 2006, 8:25:14 AM6/6/06
to testng-dev

Cédric Beust ♔ wrote:
> Hi Claude,
>
> I'm perplexed. Did we ever discuss this? I share Hani's doubts on the
> necessity of this in a testing framework, especially if it ties us to
> another external package.
> I'd like to be convinced it's really a win for TestNG users to have TestNG
> offer its own logging package, even if it's log4j (what if they want to use
> their own version of log4j? I don't want to see the Velocity nightmare
> happen to TestNG).
>
> --
> Cedric

As you noticed, and to make it clear to others, there is no external
library. This is just one very simple class (see
org.testng.logfortestng.Logger) to provide an alternative to all these
ppp calls. Again the target audience for logging is for developpers.
Logging statements typically display class names and method names that
are unknown to users.

Claude

Hani Suleiman

unread,
Jun 6, 2006, 10:23:39 AM6/6/06
to testn...@googlegroups.com
On Jun 6, 2006, at 8:15 AM, Claude Quézel wrote:

>
>
> Cédric Beust ♔ wrote:
>> I am still very skeptical that this is useful at all, but well,
>> it's a
>> fairly limited change, so we can leave it in...
>
> Cedric, I'm a bit confused here. You say you are skeptical that
> this is
> useful yet there are 163 definitions of the static ppp method
> (which is
> a logging method) in testng. For example:
>

If you're a developer, then you can add your own private logging for
a particular class just to help you debug (though of course, cedric
is being lazy and should use a debugger without silly printlns)

The point being that there's no real reason for a framework like this
to log. If you're a developer, you can add in your own mechanism to
the particular bit of code you're working on (hell, you can even use
log4j, then comment out all the log.debugs!)

Claude Quézel

unread,
Jun 6, 2006, 11:03:10 AM6/6/06
to testng-dev

Hani Suleiman wrote:
> If you're a developer, then you can add your own private logging for
> a particular class just to help you debug (though of course, cedric
> is being lazy and should use a debugger without silly printlns)

Hani,

I'm running testng 4.7 on my company's main projet. TestNG never
returns. Can you help me?

Claude

Hani Suleiman

unread,
Jun 6, 2006, 11:04:58 AM6/6/06
to testn...@googlegroups.com

hah, enable debug!

Oh wait...

Funnily enough in this case debug wouldn't be as useful as a thread
dump, if it's not returning ;)

Claude Quézel

unread,
Jun 6, 2006, 11:28:36 AM6/6/06
to testng-dev

Hani Suleiman wrote:
> If you're a developer, then you can add your own private logging for
> a particular class just to help you debug (though of course, cedric
> is being lazy and should use a debugger without silly printlns)
>
> The point being that there's no real reason for a framework like this
> to log. If you're a developer, you can add in your own mechanism to
> the particular bit of code you're working on (hell, you can even use
> log4j, then comment out all the log.debugs!)

Hani,
I'm sure Cedic knows the difference between logging and debugging and
uses a debugger like all developers do when he feels it is the right
tool. He uses logging when he feels that is the right tool.

some people (log4j users) find logging usefull. If you don't like using
logging, nothing forces you. For those who do, then there is a
re-usable way to do it in testng configurable without having to modify
code. I don't think TestNG is difefrent from any other software
products when it come to logging.

Claude

Cédric Beust ♔

unread,
Jun 6, 2006, 11:38:47 AM6/6/06
to testn...@googlegroups.com
Claude is making a good point with the numerous ppp() methods I use everywhere for my own private traces.  We all have our dirty little habits, this is mine and it's output that is never supposed to be seen by anyone but me.

The reason why I'm using them instead of logging (being log4j or java.util.logging) is because I don't want to add a dependency unless I really need to (especially a big one like log4j) and because I think java.util is pretty crappy (very bad defaults...  the default handlers output two lines of logs for every trace...  is this a joke?).

From that perspective, Claude's Log class makes sense:  it's a good compromise between what I do, which is fairly silly, and what more powerful logging packages offer but without the extra weight.

So thanks, Claude, I'll try to use your Log class instead of ppp in the future.

--
Cedric
--
Cédric
Reply all
Reply to author
Forward
0 new messages