Bug 47207 - removing printf / logging changes. Sticking in big toe. r=valeski,sr=waterson

git-svn-id: svn://10.0.0.236/trunk@81858 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
warren%netscape.com
2000-10-27 06:18:39 +00:00
parent 1c2efa89e9
commit 0605461450
8 changed files with 270 additions and 635 deletions

View File

@@ -31,6 +31,7 @@ XPIDL_MODULE = xpcom_base
LIBRARY_NAME = xpcombase_s
CPPSRCS = \
nsLogging.cpp \
nsAllocator.cpp \
nsMemoryImpl.cpp \
nsErrorService.cpp \
@@ -67,6 +68,7 @@ EXPORTS = \
nsWeakReference.h \
nsWeakPtr.h \
nscore.h \
nslog.h \
$(NULL)
ifdef NS_TRACE_MALLOC
@@ -81,6 +83,7 @@ endif
XPIDLSRCS = \
nsrootidl.idl \
nsILoggingService.idl \
nsISupports.idl \
nsIMemory.idl \
nsIErrorService.idl \

View File

@@ -45,11 +45,13 @@ EXPORTS = \
nsWeakPtr.h \
nscore.h \
pure.h \
nslog.h \
$(NULL)
XPIDL_MODULE = xpcom_base
XPIDLSRCS = \
.\nsILoggingService.idl \
.\nsrootidl.idl \
.\nsIErrorService.idl \
.\nsIMemory.idl \
@@ -85,6 +87,7 @@ LCFLAGS = $(LCFLAGS) -DGC_LEAK_DETECTOR
CPP_OBJS = \
.\$(OBJDIR)\nsLogging.obj \
.\$(OBJDIR)\nsErrorService.obj \
.\$(OBJDIR)\nsDebug.obj \
.\$(OBJDIR)\nsAllocator.obj \

View File

@@ -23,125 +23,18 @@
/**
* LOGGING SERVICE
*
* We all know and love PR_LOG, but let's face it, it has some deficiencies:
* - can't direct output for different logs to different places,
* - isn't scriptable,
* - can't control printing format, including indentation,
* - no facilities for interval timing.
* We've solved these problems with NS_LOG, the new modern equivalent. Here's
* how you use it:
*
* // First declare a new log:
* NS_DECL_LOG(Foo);
*
* void main() {
* nsresult rv;
*
* // Initialize the log somewhere in your startup code:
* NS_INIT_LOG(Foo, &rv);
*
* // Then use it like this:
* NS_LOG(Foo, OUT, ("hello world"));
* }
*
* The above log statement will print something like this:
*
* a33e50 Foo hello world
*
* The hex number at the beginning of the line indicates the ID of the thread
* executing the NS_LOG statement. The name of the log appears next. And if
* the constant ERROR, WARN, or DBG had appeared instead of OUT in the NS_LOG
* statement, the character 'E', 'W' or 'D' would have appeared before the
* message to indicate the type of log statement. The level displayed can
* be controlled by calling SetLevel on the log.
*
* // You can also cause it to indent its output to help you log recursive execution:
* int fact(int n) {
* NS_LOG_WITH_INDENT(Foo, "fact");
* NS_LOG(Main, ERROR, ("calling fact of %d\n", n));
* if (n == 0) return 1;
* int result = n * fact(n - 1);
* NS_LOG(Foo, DBG, ("fact of %d is %d\n", n, result));
* return result;
* }
*
* Calling fact(3) will produce a log that looks like this:
*
* a33e50 Foo D | calling fact of 3
* a33e50 Foo D | | calling fact of 2
* a33e50 Foo D | | | calling fact of 1
* a33e50 Foo D | | | | calling fact of 0
* a33e50 Foo D | | | fact of 1 is 1
* a33e50 Foo D | | fact of 2 is 2
* a33e50 Foo D | fact of 3 is 6
*
* You can compute elapsed time for a series of runs, and then ask the log for
* statistical information on them:
*
* void TestTiming() {
* for (int i = 0; i < 100; i++) {
* NS_LOG_BEGIN_TIMING(Foo);
* CallTestToTime();
* PRIntervalTime elapsed;
* NS_LOG_END_TIMING(Foo, &elapsed);
* NS_LOG(Foo, OUT, ("time for this run: %f\n", elapsed));
* }
* #ifdef NS_ENABLE_LOGGING
* PRUint32 samples;
* double mean, stdDev;
* Foo->GetTimingStats(&samples, &mean, &stdDev);
* printf("samples: %d, mean: %f, standard deviation: %f\n",
* samples, mean, stdDev);
* #endif
* }
*
* You can control where the output of the log goes by setting its
* log event sink to an appropriate nsILogEventSink. By default the
* standard log event sink does the following:
* - outputs to stderr
* - outputs to the platform's debug output for errors
* New log event sinks can be instantiated via the component manager:
*
* nsComponentManager::CreateInstance(kStandardLogEventSinkCID,
* nsnull, NS_GET_IID(nsIStandardLogEventSink),
* &logEventSink);
* logEventSink->Init(stdout, // stdout instead of stderr
* nsILog::LEVEL_WARN); // level to log to debug output
* Foo->SetLogEventSink(logEventSink);
*
* or the application can implement its own nsILogEventSink.
* See notes at the top of nslog.h for C++ usage.
*/
////////////////////////////////////////////////////////////////////////////////
#include "nsISupports.idl"
%{C++
#include "prlog.h" // include prlog.h because we're going to override it's ancient macros
#include "prprf.h"
#include "prinrval.h"
#include "nsDebug.h"
#include "nsIServiceManager.h"
#include <stdio.h>
#if (defined(DEBUG) || defined(NS_DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16)
// enable logging by default
#define NS_ENABLE_LOGGING
#endif
#ifdef NS_DISABLE_LOGGING
// override, if you want DEBUG, but *not* logging (for some reason)
#undef NS_ENABLE_LOGGING
#endif
#ifdef NS_ENABLE_LOGGING
class nsLogEvent;
%}
[ref] native nsLogEvent(nsLogEvent);
#include "nsISupports.idl"
typedef unsigned long PRIntervalTime;
@@ -152,29 +45,26 @@ interface nsILog;
[scriptable, uuid(28efb190-b114-11d3-93b6-00104ba0fd40)]
interface nsILogEventSink : nsISupports
{
[noscript] void printEvent(in nsLogEvent event);
void flush();
readonly attribute string destinationName;
void print(in nsILog log, in string msg);
void flush(in nsILog log);
};
[ptr] native FILE(FILE);
interface nsIStandardLogEventSink : nsILogEventSink
interface nsIFileLogEventSink : nsILogEventSink
{
/**
* @param filePath - a native path to a log file,
* or if "1", stdout,
* or if "2", stderr.
*/
void init(in string filePath,
in unsigned long levelForDebugOutput);
[noscript] void initFromFILE(in string name,
in FILE filePtr,
in unsigned long levelForDebugOutput);
void init(in string filePath);
[noscript] void initFromFILE(in string name, in FILE filePtr);
};
%{C++
#define NS_STANDARDLOGEVENTSINK_CID \
#define NS_FILELOGEVENTSINK_CID \
{ /* 0ebdebe0-b14a-11d3-93b6-00104ba0fd40 */ \
0x0ebdebe0, \
0xb14a, \
@@ -182,8 +72,8 @@ interface nsIStandardLogEventSink : nsILogEventSink
{0x93, 0xb6, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
#define NS_STANDARDLOGEVENTSINK_CONTRACTID "@mozilla.org/standard-log-event-sink;1"
#define NS_STANDARDLOGEVENTSINK_CLASSNAME "Standard Log Event Sink"
#define NS_FILELOGEVENTSINK_CONTRACTID "@mozilla.org/file-log-event-sink;1"
#define NS_FILELOGEVENTSINK_CLASSNAME "File Log Event Sink"
%}
////////////////////////////////////////////////////////////////////////////////
@@ -195,7 +85,6 @@ interface nsILoggingService : nsISupports
attribute unsigned long defaultControlFlags;
attribute nsILogEventSink defaultLogEventSink;
void describeLogs(in nsILog output);
void describeTimings(in nsILog output);
};
%{C++
@@ -207,7 +96,7 @@ interface nsILoggingService : nsISupports
{0x93, 0xb6, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
#define NS_LOGGINGSERVICE_CONTRACTID "@mozilla.org/logging-service;1"
#define NS_LOGGINGSERVICE_CONTRACTID "@mozilla.org/logging-service;1"
#define NS_LOGGINGSERVICE_CLASSNAME "Logging Service"
%}
@@ -218,54 +107,26 @@ interface nsILog : nsISupports
{
readonly attribute string name;
const unsigned long LEVEL_NEVER = 0;
const unsigned long LEVEL_ERROR = 1;
const unsigned long LEVEL_WARN = 2;
const unsigned long LEVEL_STDOUT = 3;
const unsigned long LEVEL_DBG = 4;
attribute unsigned long level;
// Backward compatibility with PR_LOG -- don't use explicitly!
const unsigned long LEVEL_PR_LOG_NONE = LEVEL_NEVER;
const unsigned long LEVEL_PR_LOG_ERROR = LEVEL_ERROR;
const unsigned long LEVEL_PR_LOG_WARNING = LEVEL_WARN;
const unsigned long LEVEL_PR_LOG_ALWAYS = LEVEL_STDOUT;
const unsigned long LEVEL_PR_LOG_DEBUG = LEVEL_DBG;
////////////////////////////////////////////////////////////////////////////
// Printing Routines
boolean enabled(in unsigned long level);
void print(in unsigned long level, in wstring message);
boolean enabled();
void print(in wstring message);
void flush();
[noscript] void printEvent(in nsLogEvent event);
void increaseIndent();
void decreaseIndent();
readonly attribute unsigned long indentLevel;
void describe(in nsILog outLog);
////////////////////////////////////////////////////////////////////////////
// Timing Routines
void beginTiming();
PRIntervalTime endTiming();
void getTimingStats(out unsigned long sampleSize,
out double meanTime,
out double stdDevTime);
void describeTiming(in nsILog outLog, in string msg);
void resetTiming();
////////////////////////////////////////////////////////////////////////////
// Control Routines
const unsigned long PRINT_THREAD_ID = 1 << 0;
const unsigned long PRINT_LOG_NAME = 1 << 1;
const unsigned long PRINT_LEVEL = 1 << 2;
const unsigned long TIMING_PER_THREAD = 1 << 3;
const unsigned long DEFAULT_DISABLED = 0 << 0;
const unsigned long DEFAULT_ENABLED = 1 << 1;
const unsigned long PRINT_THREAD_ID = 1 << 2;
const unsigned long PRINT_LOG_NAME = 1 << 3;
attribute unsigned long controlFlags;
@@ -281,160 +142,12 @@ interface nsILog : nsISupports
// implementation to implement this part.)
%{C++
public:
PRBool Test(PRUint32 level) { return mEnabledLevel >= level; }
inline PRBool Test() { return mControlFlags & DEFAULT_ENABLED; }
NS_IMETHOD Printf(const char* format, ...) = 0;
NS_IMETHOD Vprintf(const char* format, va_list args) = 0;
protected:
PRUint32 mEnabledLevel;
PRUint32 mControlFlags;
%}
};
////////////////////////////////////////////////////////////////////////////////
%{C++
/**
* nsLogEvent: This little closure class is used to capture the log
* level so that the NS_LOG macro is more manageable.
*/
class NS_COM nsLogEvent
{
public:
nsLogEvent(nsILog* log, PRUint32 level)
: mLog(log), mLevel(level), mMessage(nsnull) {
}
~nsLogEvent() {
if (mMessage) PR_smprintf_free(mMessage);
}
nsresult Printf(const char* format, ...);
nsresult Vprintf(const char* format, va_list args);
nsILog* GetLog() { return mLog; }
PRUint32 GetLevel() { return mLevel; }
const char* GetMsg() { return mMessage; }
protected:
nsILog* mLog;
PRUint32 mLevel;
char* mMessage;
};
/**
* nsLogIndent: This class allows indentation to occur in a block scope. The
* automatic destructor takes care of resetting the indentation. Use the
* NS_LOG_WITH_INDENT macro.
*/
class NS_COM nsLogIndent
{
public:
nsLogIndent(nsILog* log, const char* msg) : mLog(log), mMsg(msg) {
nsLogEvent(mLog, nsILog::LEVEL_STDOUT).Printf("[ Begin %s", mMsg);
mLog->IncreaseIndent();
}
~nsLogIndent() {
mLog->DecreaseIndent();
nsLogEvent(mLog, nsILog::LEVEL_STDOUT).Printf("] End %s", mMsg);
}
protected:
nsILog* mLog;
const char* mMsg;
};
/**
* nsLogTiming: This class allows timing to occur in a block scope. The
* automatic destructor takes care of stopping the timing. Use the
* NS_LOG_WITH_TIMING macro.
*/
class NS_COM nsLogTiming
{
public:
nsLogTiming(nsILog* log) : mLog(log) {
mLog->BeginTiming();
}
~nsLogTiming() {
PRIntervalTime elapsed;
mLog->EndTiming(&elapsed);
}
protected:
nsILog* mLog;
};
////////////////////////////////////////////////////////////////////////////////
#define NS_DECL_LOG(_log) \
nsILog* _log
#define NS_INIT_LOG(_log) \
PR_BEGIN_MACRO \
if (_log == nsnull) { \
nsresult _rv; \
static NS_DEFINE_CID(kLoggingServiceCID, NS_LOGGINGSERVICE_CID); \
NS_WITH_SERVICE(nsILoggingService, _serv, kLoggingServiceCID, &_rv); \
if (NS_SUCCEEDED(_rv)) { \
_rv = _serv->GetLog(#_log, &_log); \
PR_ASSERT(NS_SUCCEEDED(_rv)); \
} \
} \
PR_END_MACRO
#define NS_LOG_TEST(_log, _level) \
((_log)->Test(nsILog::LEVEL_##_level))
#define NS_LOG(_log, _level, _printfArgs) \
PR_BEGIN_MACRO \
if (NS_LOG_TEST(_log, _level)) { \
nsLogEvent(_log, nsILog::LEVEL_##_level) \
.Printf _printfArgs; \
} \
PR_END_MACRO
#define NS_DEFINE_LOG(_log, _level) \
(!NS_LOG_TEST(_log, _level)) \
? NS_OK \
: nsLogEvent(_log, nsILog::LEVEL_##_level).Printf
#define NS_LOG_FLUSH(_log) ((_log)->Flush())
#define NS_LOG_WITH_INDENT(_log, _msg) nsLogIndent _indent_##_log(_log, _msg)
#define NS_LOG_BEGIN_INDENT(_log) ((_log)->IncreaseIndent())
#define NS_LOG_END_INDENT(_log) ((_log)->DecreaseIndent())
#define NS_LOG_WITH_TIMING(_log) nsLogTiming _timing_##_log(_log)
#define NS_LOG_BEGIN_TIMING(_log) ((_log)->BeginTiming())
#define NS_LOG_END_TIMING(_log, _elapsed) ((_log)->EndTiming(_elapsed))
#define NS_LOG_DESCRIBE_TIMING(_log,_msg) ((_log)->DescribeTiming(_msg))
#define NS_LOG_RESET_TIMING(_log) ((_log)->ResetTiming())
#else // !NS_ENABLE_LOGGING
#define NS_DECL_LOG(_log) void _not_used() // something that can be used with extern
#define NS_INIT_LOG(_log) ((void)0)
#define NS_LOG_TEST(_module, _level) 0
#define NS_LOG(_module, _level, _args) ((void)0)
#define NS_DEFINE_LOG(_log, _level) NS_OK
#define NS_LOG_FLUSH(_log) NS_OK
#define NS_LOG_WITH_INDENT(_log, _msg) ((void)0)
#define NS_LOG_BEGIN_INDENT(_log) ((void)0)
#define NS_LOG_END_INDENT(_log) ((void)0)
#define NS_LOG_WITH_TIMING(_log) ((void)0)
#define NS_LOG_BEGIN_TIMING(_log) ((void)0)
#define NS_LOG_END_TIMING(_log, _elapsed) (*(_elapsed) = 0)
#define NS_LOG_DESCRIBE_TIMING(_log,_msg) NS_OK
#define NS_LOG_RESET_TIMING(_log) NS_OK
#endif // !NS_ENABLE_LOGGING
// Redefine NSPR's logging system:
#undef PR_LOG_TEST
#define PR_LOG_TEST NS_LOG_TEST
#undef PR_LOG
#define PR_LOG NS_LOG
#define PRLogModuleInfo #error use_NS_DECL_LOG_instead
#define PR_NewLogModule #error use_NS_INIT_LOG_instead
#undef PR_ASSERT
#define PR_ASSERT(x) NS_ASSERTION(x, #x)
#define printf use_NS_DECL_LOG_instead
#define fprintf use_NS_DECL_LOG_instead
%}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -30,7 +30,6 @@
#include "nsISupportsArray.h"
#include "nsIServiceManager.h"
#include "nsSpecialSystemDirectory.h"
#include <math.h>
#ifdef XP_PC
#include <windows.h>
#endif
@@ -41,31 +40,52 @@
static PRMonitor* gLogMonitor = nsnull;
static nsObjectHashtable* gSettings = nsnull;
NS_DECL_LOG(LogInfo);
NS_IMPL_LOG_ENABLED(LogInfo)
#define PRINTF NS_LOG_PRINTF(LogInfo)
#define FLUSH NS_LOG_FLUSH(LogInfo)
NS_DEFINE_CID(kLoggingServiceCID, NS_LOGGINGSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
// nsLoggingService
static nsLoggingService* gLoggingService = nsnull;
nsLoggingService::nsLoggingService()
: mDefaultControlFlags(nsILog::PRINT_THREAD_ID |
nsILog::PRINT_LOG_NAME |
nsILog::PRINT_LEVEL |
nsILog::TIMING_PER_THREAD),
mLogs(16)
: mLogs(16),
mDefaultControlFlags(nsILog::DEFAULT_DISABLED |
nsILog::PRINT_THREAD_ID |
nsILog::PRINT_LOG_NAME)
{
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
}
nsLoggingService::~nsLoggingService()
{
NS_INIT_LOG(LogInfo);
DescribeLogs(LogInfo);
DescribeTimings(LogInfo);
}
NS_IMPL_ISUPPORTS1(nsLoggingService, nsILoggingService)
NS_IMPL_QUERY_INTERFACE1(nsLoggingService, nsILoggingService)
NS_IMPL_ADDREF(nsLoggingService)
NS_IMETHODIMP_(nsrefcnt)
nsLoggingService::Release(void)
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
NS_ASSERT_OWNINGTHREAD(nsLoggingService);
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsLoggingService");
if (mRefCnt == 0) {
mRefCnt = 1; /* stabilize */
NS_DELETEXPCOM(this);
// special action -- null out global
gLoggingService = nsnull;
return 0;
}
return mRefCnt;
}
static void*
levelClone(nsHashKey *aKey, void *aData, void* closure)
@@ -83,35 +103,35 @@ levelDestroy(nsHashKey *aKey, void *aData, void* closure)
static void
RecordSetting(const char* name, const char* value)
{
PRUint32 level = nsILog::LEVEL_ERROR;
PRUint32 level = 2;
if (nsCRT::strcasecmp(value, "ERROR") == 0 ||
nsCRT::strcasecmp(value, "2") == 0) {
level = nsILog::LEVEL_ERROR;
fprintf(stderr, "### NS_LOG: %s = ERROR\n", name);
level = 2;
PRINTF("### NS_LOG: %s = ERROR\n", name);
}
else if (nsCRT::strcasecmp(value, "WARN") == 0 ||
nsCRT::strcasecmp(value, "WARNING") == 0 ||
nsCRT::strcasecmp(value, "3") == 0) {
level = nsILog::LEVEL_WARN;
fprintf(stderr, "### NS_LOG: %s = WARN\n", name);
level = 3;
PRINTF("### NS_LOG: %s = WARN\n", name);
}
else if (nsCRT::strcasecmp(value, "STDOUT") == 0 ||
nsCRT::strcasecmp(value, "OUT") == 0 ||
nsCRT::strcasecmp(value, "4") == 0) {
level = nsILog::LEVEL_STDOUT;
fprintf(stderr, "### NS_LOG: %s = STDOUT\n", name);
level = 4;
PRINTF("### NS_LOG: %s = STDOUT\n", name);
}
else if (nsCRT::strcasecmp(value, "DBG") == 0 ||
nsCRT::strcasecmp(value, "DEBUG") == 0 ||
nsCRT::strcasecmp(value, "5") == 0) {
level = nsILog::LEVEL_DBG;
fprintf(stderr, "### NS_LOG: %s = DBG\n", name);
level = 5;
PRINTF("### NS_LOG: %s = DBG\n", name);
}
else {
fprintf(stderr, "### NS_LOG error: %s = %s (bad level)\n", name, value);
PRINTF("### NS_LOG error: %s = %s (bad level)\n", name, value);
}
nsStringKey key(name);
nsCStringKey key(name);
gSettings->Put(&key, (void*)level);
}
@@ -119,7 +139,7 @@ nsresult
nsLoggingService::Init()
{
nsresult rv;
nsStandardLogEventSink* defaultSink = nsnull;
nsFileLogEventSink* defaultSink = nsnull;
const char* outputPath = nsnull;
if (gLogMonitor == nsnull) {
@@ -142,7 +162,7 @@ nsLoggingService::Init()
{
const char* nspr_log_modules = getenv("NSPR_LOG_MODULES");
if (nspr_log_modules) {
fprintf(stderr, "### NS_LOG: using NSPR_LOG_MODULES (instead of .nslog)\n");
PRINTF("### NS_LOG: using NSPR_LOG_MODULES (instead of .nslog)\n");
char* head = nsCRT::strdup(nspr_log_modules);
char* rest = nsCRT::strdup(nspr_log_modules);
while (1) {
@@ -156,7 +176,7 @@ nsLoggingService::Init()
}
const char* nspr_log_file = getenv("NSPR_LOG_FILE");
if (nspr_log_file) {
fprintf(stderr, "### NS_LOG: using NSPR_LOG_FILE (instead of .nslog) -- logging to %s\n",
PRINTF("### NS_LOG: using NSPR_LOG_FILE (instead of .nslog) -- logging to %s\n",
nspr_log_file);
outputPath = nspr_log_file;
}
@@ -183,7 +203,7 @@ nsLoggingService::Init()
}
}
defaultSink = new nsStandardLogEventSink();
defaultSink = new nsFileLogEventSink();
if (defaultSink == nsnull) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto error;
@@ -191,13 +211,17 @@ nsLoggingService::Init()
NS_ADDREF(defaultSink);
if (outputPath)
rv = defaultSink->Init(outputPath, nsILog::LEVEL_ERROR);
rv = defaultSink->Init(outputPath);
else
rv = defaultSink->InitFromFILE("stderr", stderr, nsILog::LEVEL_ERROR);
rv = defaultSink->InitFromFILE("stderr", stderr);
if (NS_FAILED(rv)) goto error;
mDefaultSink = defaultSink;
NS_RELEASE(defaultSink);
#ifdef DEBUG
DescribeLogs(LogInfo);
#endif
return NS_OK;
error:
@@ -209,6 +233,28 @@ nsLoggingService::Init()
return rv;
}
static nsresult
EnsureLoggingService()
{
nsresult rv;
if (gLoggingService == nsnull) {
gLoggingService = new nsLoggingService();
if (gLoggingService == NULL)
return NS_ERROR_OUT_OF_MEMORY;
rv = gLoggingService->Init();
if (NS_FAILED(rv)) {
delete gLoggingService;
return rv;
}
// Note that there's no AddRef here. That's because when the service manager
// gets around to calling Create (below) sometime later, we'll AddRef it then
// and the service manager will be the sole owner. This allows us to use it
// before xpcom has started up.
}
return NS_OK;
}
NS_METHOD
nsLoggingService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
@@ -216,22 +262,12 @@ nsLoggingService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstance
if (outer)
return NS_ERROR_NO_AGGREGATION;
nsLoggingService* it = new nsLoggingService();
if (it == NULL)
return NS_ERROR_OUT_OF_MEMORY;
rv = it->Init();
if (NS_FAILED(rv)) {
delete it;
return rv;
if (gLoggingService == nsnull) {
rv = EnsureLoggingService();
if (NS_FAILED(rv)) return rv;
}
rv = it->QueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete it;
return rv;
}
return rv;
return gLoggingService->QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
@@ -239,7 +275,7 @@ nsLoggingService::GetLog(const char* name, nsILog* *result)
{
nsAutoMonitor monitor(gLogMonitor);
nsStringKey key(name);
nsCStringKey key(name);
nsILog* log = (nsILog*)mLogs.Get(&key);
if (log) {
*result = log;
@@ -254,12 +290,35 @@ nsLoggingService::GetLog(const char* name, nsILog* *result)
delete newLog;
return rv;
}
NS_ADDREF(newLog);
mLogs.Put(&key, newLog);
*result = newLog;
NS_ADDREF(newLog);
return NS_OK;
}
PR_IMPLEMENT(nsILog*)
NS_GetLog(const char* name, PRUint32 controlFlags)
{
nsresult rv;
if (gLoggingService == nsnull) {
rv = EnsureLoggingService();
if (NS_FAILED(rv)) return nsnull;
}
nsILog* log;
rv = gLoggingService->GetLog(name, &log);
if (NS_FAILED(rv)) return nsnull;
// add in additional flags:
PRUint32 flags;
log->GetControlFlags(&flags);
flags |= controlFlags;
log->SetControlFlags(flags);
return log;
}
static PRBool
DescribeLog(nsHashKey *aKey, void *aData, void* closure)
{
@@ -272,34 +331,11 @@ DescribeLog(nsHashKey *aKey, void *aData, void* closure)
NS_IMETHODIMP
nsLoggingService::DescribeLogs(nsILog* out)
{
NS_LOG(out, STDOUT, ("%-20.20s %-8.8s %s\n", "LOG NAME", "ENABLED", "DESTINATION"));
NS_LOG_PRINTF(out)("%-20.20s %-8.8s %s\n", "LOG NAME", "ENABLED", "DESTINATION");
mLogs.Enumerate(DescribeLog, out);
return NS_OK;
}
static PRBool
DescribeTiming(nsHashKey *aKey, void *aData, void* closure)
{
nsILog* log = (nsILog*)aData;
nsILog* out = (nsILog*)closure;
nsresult rv;
PRUint32 sampleSize;
double meanTime;
double stdDevTime;
rv = log->GetTimingStats(&sampleSize, &meanTime, &stdDevTime);
if (NS_SUCCEEDED(rv) && sampleSize > 0)
(void)log->DescribeTiming(out, "TOTAL TIME");
return PR_TRUE;
}
NS_IMETHODIMP
nsLoggingService::DescribeTimings(nsILog* out)
{
NS_LOG(out, STDOUT, (" %-20.20s %-8.8s %s\n", "LOG NAME", "ENABLED", "DESTINATION"));
mLogs.Enumerate(DescribeTiming, out);
return NS_OK;
}
NS_IMETHODIMP
nsLoggingService::GetDefaultControlFlags(PRUint32 *controlFlags)
{
@@ -334,11 +370,9 @@ nsLoggingService::SetDefaultLogEventSink(nsILogEventSink* sink)
nsLog::nsLog()
: mName(nsnull),
mControlFlags(0),
mIndentLevel(0)
{
mEnabledLevel = LEVEL_ERROR;
NS_INIT_REFCNT();
NS_INIT_ISUPPORTS();
}
nsLog::~nsLog()
@@ -348,13 +382,6 @@ nsLog::~nsLog()
NS_IMPL_ISUPPORTS1(nsLog, nsILog)
static void PR_CALLBACK
DeleteTimingData(void *priv)
{
nsTimingData* data = (nsTimingData*)priv;
delete data;
}
nsresult
nsLog::Init(const char* name, PRUint32 controlFlags, nsILogEventSink* sink)
{
@@ -364,15 +391,11 @@ nsLog::Init(const char* name, PRUint32 controlFlags, nsILogEventSink* sink)
mControlFlags = controlFlags;
mSink = sink;
nsStringKey key(name);
nsCStringKey key(name);
PRUint32 level = (PRUint32)gSettings->Get(&key);
if (level != LEVEL_NEVER) {
mEnabledLevel = level;
if (level != 0) {
mControlFlags |= nsILog::DEFAULT_ENABLED;
}
PRStatus status = PR_NewThreadPrivateIndex(&mThreadTimingDataIndex,
DeleteTimingData);
if (status != PR_SUCCESS)
return NS_ERROR_FAILURE;
return NS_OK;
}
@@ -384,36 +407,19 @@ nsLog::GetName(char* *aName)
}
NS_IMETHODIMP
nsLog::GetLevel(PRUint32 *aLevel)
nsLog::Enabled(PRBool *result)
{
*aLevel = mEnabledLevel;
*result = Test();
return NS_OK;
}
NS_IMETHODIMP
nsLog::SetLevel(PRUint32 aLevel)
{
mEnabledLevel = aLevel;
return NS_OK;
}
NS_IMETHODIMP
nsLog::Enabled(PRUint32 level, PRBool *result)
{
*result = Test(level);
return NS_OK;
}
NS_IMETHODIMP
nsLog::Print(PRUint32 level, const PRUnichar *message)
nsLog::Print(const PRUnichar *message)
{
nsAutoMonitor monitor(gLogMonitor);
nsCString str(message);
char* msg = str.ToNewCString();
nsLogEvent event(this, level);
nsresult rv = event.Printf(msg);
nsCRT::free(msg);
nsCString str; str.AssignWithConversion(message);
nsresult rv = Printf(str.GetBuffer());
return rv;
}
@@ -422,15 +428,7 @@ nsLog::Flush(void)
{
nsAutoMonitor monitor(gLogMonitor);
return mSink->Flush();
}
NS_IMETHODIMP
nsLog::PrintEvent(nsLogEvent& event)
{
nsAutoMonitor monitor(gLogMonitor);
return mSink->PrintEvent(event);
return mSink->Flush(this);
}
NS_IMETHODIMP
@@ -447,7 +445,7 @@ nsLog::DecreaseIndent()
{
nsAutoMonitor monitor(gLogMonitor);
// PR_ASSERT(mIndentLevel > 0); // XXX layout is having trouble
PR_ASSERT(mIndentLevel > 0);
if (mIndentLevel == 0)
return NS_ERROR_FAILURE;
mIndentLevel--;
@@ -465,6 +463,7 @@ NS_IMETHODIMP
nsLog::Describe(nsILog* out)
{
nsresult rv;
#if 0
const char* levelName;
switch (mEnabledLevel) {
case nsILog::LEVEL_NEVER: levelName = "NEVER"; break;
@@ -474,129 +473,20 @@ nsLog::Describe(nsILog* out)
case nsILog::LEVEL_DBG: levelName = "DBG"; break;
default: levelName = "<unknown>"; break;
}
#endif
char* dest = nsnull;
rv = mSink->GetDestinationName(&dest);
if (NS_FAILED(rv)) {
dest = nsCRT::strdup("<unknown>");
}
NS_LOG(out, STDOUT, (" %-20.20s %-8.8s %s\n", mName, levelName, dest));
// NS_LOG(out, (" %-20.20s %-8.8s %s\n", mName, levelName, dest));
PRBool enabled = mControlFlags & nsILog::DEFAULT_ENABLED;
NS_LOG_PRINTF(out)("%-20.20s %-8.8s %s\n",
mName, (enabled ? "yes" : "no"), dest);
if (dest) nsCRT::free(dest);
return NS_OK;
}
NS_IMETHODIMP
nsLog::BeginTiming(void)
{
nsTimingData* data;
if (mControlFlags & TIMING_PER_THREAD) {
data = (nsTimingData*)PR_GetThreadPrivate(mThreadTimingDataIndex);
if (data == nsnull) {
data = new nsTimingData;
if (data == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
PRStatus status = PR_SetThreadPrivate(mThreadTimingDataIndex, data);
if (status != PR_SUCCESS)
return NS_ERROR_FAILURE;
}
}
else {
data = &mTimingData;
}
PR_ASSERT(data->mStartTime == 0);
if (data->mStartTime != 0)
return NS_ERROR_FAILURE;
data->mStartTime = PR_IntervalNow();
return NS_OK;
}
NS_IMETHODIMP
nsLog::EndTiming(PRIntervalTime *elapsedTime)
{
nsTimingData* data;
if (mControlFlags & TIMING_PER_THREAD)
data = (nsTimingData*)PR_GetThreadPrivate(mThreadTimingDataIndex);
else
data = &mTimingData;
PR_ASSERT(data->mStartTime != 0);
if (data->mStartTime == 0)
return NS_ERROR_FAILURE;
PRIntervalTime elapsed = PR_IntervalNow();
elapsed -= data->mStartTime;
data->mStartTime = 0;
data->mTimingSamples++;
data->mTotalTime += elapsed;
data->mTotalSquaredTime += elapsed * elapsed;
*elapsedTime = elapsed;
if (mControlFlags & TIMING_PER_THREAD) {
// dump per-thread data into per-log data:
mTimingData.mTotalTime += data->mTotalTime;
mTimingData.mTotalSquaredTime += data->mTotalSquaredTime;
mTimingData.mTimingSamples += data->mTimingSamples;
// destroy TLS:
PRStatus status = PR_SetThreadPrivate(mThreadTimingDataIndex, nsnull);
if (status != PR_SUCCESS)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsLog::GetTimingStats(PRUint32 *sampleSize,
double *meanTime,
double *stdDevTime)
{
*sampleSize = mTimingData.mTimingSamples;
double mean = mTimingData.mTotalTime / mTimingData.mTimingSamples;
*meanTime = (PRIntervalTime)mean;
double variance = fabs(mTimingData.mTotalSquaredTime / mTimingData.mTimingSamples - mean * mean);
*stdDevTime = sqrt(variance);
return NS_OK;
}
NS_IMETHODIMP
nsLog::DescribeTiming(nsILog* out, const char* msg)
{
nsresult rv;
PR_ASSERT(mTimingData.mStartTime == 0);
if (mTimingData.mStartTime != 0) {
NS_LOG(this, STDOUT, ("%s: TIMING ERROR\n", msg));
return NS_ERROR_FAILURE;
}
PRUint32 realTimeSamples;
double realTimeMean, realTimeStdDev;
rv = GetTimingStats(&realTimeSamples, &realTimeMean, &realTimeStdDev);
if (NS_FAILED(rv)) return rv;
PRUint32 tps = PR_TicksPerSecond();
if (realTimeSamples > 1) {
NS_LOG(out, STDOUT, ("%s: %.2f +/- %.2f ms (%d samples)\n",
msg,
realTimeMean * 1000 / tps,
realTimeStdDev * 1000 / tps,
realTimeSamples));
}
else {
NS_LOG(out, STDOUT, ("%s: %.2f ms\n",
msg, realTimeMean * 1000 / tps));
}
return NS_OK;
}
NS_IMETHODIMP
nsLog::ResetTiming(void)
{
PR_ASSERT(mTimingData.mStartTime == 0);
mTimingData.mTotalTime = 0;
mTimingData.mTotalSquaredTime = 0;
mTimingData.mTimingSamples = 0;
return NS_OK;
}
NS_IMETHODIMP
nsLog::GetControlFlags(PRUint32 *flags)
{
@@ -635,43 +525,58 @@ nsLog::SetLogEventSink(nsILogEventSink* sink)
}
////////////////////////////////////////////////////////////////////////////////
// nsLogEvent
// nsLog
nsresult
nsLogEvent::Printf(const char* format, ...)
NS_IMETHODIMP
nsLog::Printf(const char* format, ...)
{
if (mMessage == nsnull) {
va_list args;
va_start(args, format);
mMessage = PR_vsmprintf(format, args);
va_end(args);
}
return mLog->PrintEvent(*this);
nsAutoMonitor monitor(gLogMonitor);
va_list args;
va_start(args, format);
const char* msg = PR_vsmprintf(format, args);
va_end(args);
return mSink->Print(this, msg);
}
nsresult
nsLogEvent::Vprintf(const char* format, va_list args)
NS_IMETHODIMP
nsLog::Vprintf(const char* format, va_list args)
{
if (mMessage == nsnull) {
mMessage = PR_vsmprintf(format, args);
}
return mLog->PrintEvent(*this);
nsAutoMonitor monitor(gLogMonitor);
const char* msg = PR_vsmprintf(format, args);
return mSink->Print(this, msg);
}
////////////////////////////////////////////////////////////////////////////////
// nsStandardLogEventSink
// nsLogIndent
nsStandardLogEventSink::nsStandardLogEventSink()
nsLogIndent::nsLogIndent(nsILog* log, const char* msg)
: mLog(log), mHeaderMsg(msg)
{
if (mHeaderMsg) mLog->Printf("[ Begin %s", mHeaderMsg);
(void)mLog->IncreaseIndent();
}
nsLogIndent::~nsLogIndent()
{
(void)mLog->DecreaseIndent();
if (mHeaderMsg) mLog->Printf("] End %s", mHeaderMsg);
}
////////////////////////////////////////////////////////////////////////////////
// nsFileLogEventSink
nsFileLogEventSink::nsFileLogEventSink()
: mName(nsnull),
mOutput(nsnull),
mDebugLevel(nsILog::LEVEL_NEVER),
mBeginningOfLine(PR_TRUE),
mCloseFile(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsStandardLogEventSink::~nsStandardLogEventSink()
nsFileLogEventSink::~nsFileLogEventSink()
{
if (mCloseFile) {
::fclose(mOutput);
@@ -680,19 +585,19 @@ nsStandardLogEventSink::~nsStandardLogEventSink()
if (mName) nsCRT::free(mName);
}
NS_IMPL_ISUPPORTS2(nsStandardLogEventSink,
nsIStandardLogEventSink,
NS_IMPL_ISUPPORTS2(nsFileLogEventSink,
nsIFileLogEventSink,
nsILogEventSink)
NS_IMETHODIMP
nsStandardLogEventSink::GetDestinationName(char* *result)
nsFileLogEventSink::GetDestinationName(char* *result)
{
*result = nsCRT::strdup(mName);
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsStandardLogEventSink::Init(const char* filePath, PRUint32 levelForDebugOutput)
nsFileLogEventSink::Init(const char* filePath)
{
FILE* filePtr;
if (nsCRT::strcmp(filePath, "1") == 0) {
@@ -707,73 +612,64 @@ nsStandardLogEventSink::Init(const char* filePath, PRUint32 levelForDebugOutput)
return NS_ERROR_FAILURE;
mCloseFile = PR_TRUE;
}
return InitFromFILE(filePath, filePtr, levelForDebugOutput);
return InitFromFILE(filePath, filePtr);
}
NS_IMETHODIMP
nsStandardLogEventSink::InitFromFILE(const char* name, FILE* filePtr, PRUint32 levelForDebugOutput)
nsFileLogEventSink::InitFromFILE(const char* name, FILE* filePtr)
{
mOutput = filePtr;
mDebugLevel = levelForDebugOutput;
mName = nsCRT::strdup(name);
return mName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsStandardLogEventSink::PrintEvent(nsLogEvent& event)
nsFileLogEventSink::Print(nsILog* log, const char* msg)
{
nsresult rv;
nsILog* log = event.GetLog();
PRUint32 level = event.GetLevel();
const char* msg = event.GetMsg();
if (level == nsILog::LEVEL_NEVER)
return NS_OK;
// do debug output first
if (level <= mDebugLevel) {
#ifdef XP_PC
OutputDebugString(msg);
#elif defined(XP_MAC)
{
# define BUF_SIZE 1024
char buf[BUF_SIZE];
PRUint32 len =
PL_snprintf(buf+1, BUF_SIZE-1, "ERROR: %s", msg);
buf[0] = (char) (len > 255 ? 255 : len);
DebugStr(StringPtr(buf));
}
#endif
}
if (!log->Test(level))
if (!NS_LOG_ENABLED(log))
return NS_OK;
nsAutoMonitor monitor(gLogMonitor);
// do debug output first
#ifdef XP_PC
OutputDebugString(msg);
#elif defined(XP_MAC)
{
# define BUF_SIZE 1024
char buf[BUF_SIZE];
PRUint32 len =
PR_snprintf(buf+1, BUF_SIZE-1, "%s", msg);
buf[0] = (char) (len > 255 ? 255 : len);
DebugStr(StringPtr(buf));
}
#endif
if (!mBeginningOfLine) {
::fputc('\n', mOutput);
mBeginningOfLine = PR_TRUE;
}
// print preamble
char levels[] = { 'X', 'E', 'W', ' ', 'D' };
PRUint32 flags;
rv = log->GetControlFlags(&flags);
if (NS_FAILED(rv)) return rv;
if (flags & nsILog::PRINT_THREAD_ID) {
::fprintf(mOutput, "%8x ", PR_CurrentThread());
}
else {
::fprintf(mOutput, "%8s ", "");
::fprintf(mOutput, "%8x ", (PRInt32)PR_CurrentThread());
mBeginningOfLine = PR_FALSE;
}
char* name;
rv = log->GetName(&name);
::fprintf(mOutput, "%-8.8s %c ",
flags & nsILog::PRINT_LOG_NAME ? name : "",
flags & nsILog::PRINT_LEVEL ? levels[level] : ' ');
nsCRT::free(name);
mBeginningOfLine = PR_FALSE;
if (flags & nsILog::PRINT_LOG_NAME) {
char* name;
rv = log->GetName(&name);
::fprintf(mOutput, "%-8.8s ",
flags & nsILog::PRINT_LOG_NAME ? name : "");
nsCRT::free(name);
mBeginningOfLine = PR_FALSE;
}
PRUint32 indentLevel;
rv = log->GetIndentLevel(&indentLevel);
@@ -782,7 +678,8 @@ nsStandardLogEventSink::PrintEvent(nsLogEvent& event)
indent:
// do indentation
for (PRUint32 i = 0; i < indentLevel; i++) {
::fputs("| ", mOutput);
::fprintf(mOutput, "| ");
mBeginningOfLine = PR_FALSE;
}
char c;
@@ -795,20 +692,29 @@ nsStandardLogEventSink::PrintEvent(nsLogEvent& event)
break;
}
else {
::fputs("\n ", mOutput);
::fprintf(mOutput, "\n ");
mBeginningOfLine = PR_FALSE;
goto indent;
}
default:
::fputc(c, mOutput);
mBeginningOfLine = PR_FALSE;
}
}
} while (0);
if (!mBeginningOfLine) {
::fputc('\n', mOutput);
mBeginningOfLine = PR_TRUE;
}
return NS_OK;
}
NS_IMETHODIMP
nsStandardLogEventSink::Flush()
nsFileLogEventSink::Flush(nsILog* log)
{
nsAutoMonitor monitor(gLogMonitor);
::fflush(mOutput);
return NS_OK;
}

View File

@@ -23,13 +23,15 @@
#ifndef nsLogging_h__
#define nsLogging_h__
#include "nsILoggingService.h"
#include "nslog.h"
#ifdef NS_ENABLE_LOGGING
#include "nsHashtable.h"
#include "nsCOMPtr.h"
////////////////////////////////////////////////////////////////////////////////
class nsLoggingService : public nsILoggingService
{
public:
@@ -52,58 +54,41 @@ protected:
////////////////////////////////////////////////////////////////////////////////
class nsTimingData {
public:
nsTimingData()
: mStartTime(0),
mTotalTime(0),
mTotalSquaredTime(0),
mTimingSamples(0) {
}
PRIntervalTime mStartTime;
double mTotalTime;
double mTotalSquaredTime;
PRUint32 mTimingSamples;
};
////////////////////////////////////////////////////////////////////////////////
class nsLog : public nsILog
{
public:
nsLog();
virtual ~nsLog();
NS_DECL_ISUPPORTS
NS_DECL_NSILOG
nsLog();
virtual ~nsLog();
NS_IMETHOD Printf(const char* format, ...);
NS_IMETHOD Vprintf(const char* format, va_list args);
nsresult Init(const char* name, PRUint32 controlFlags, nsILogEventSink* sink);
protected:
char* mName;
PRUint32 mControlFlags;
PRUint32 mIndentLevel;
PRUintn mThreadTimingDataIndex;
nsTimingData mTimingData;
nsCOMPtr<nsILogEventSink> mSink;
};
////////////////////////////////////////////////////////////////////////////////
class nsStandardLogEventSink : public nsIStandardLogEventSink
class nsFileLogEventSink : public nsIFileLogEventSink
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSILOGEVENTSINK
NS_DECL_NSISTANDARDLOGEVENTSINK
NS_DECL_NSIFILELOGEVENTSINK
nsStandardLogEventSink();
virtual ~nsStandardLogEventSink();
nsFileLogEventSink();
virtual ~nsFileLogEventSink();
protected:
char* mName;
FILE* mOutput;
PRUint32 mDebugLevel;
PRBool mBeginningOfLine;
PRBool mCloseFile;
};

View File

@@ -68,6 +68,8 @@
#include "pure.h"
#endif
#include "pldhash.h"
#include "nsLogging.h"
class dummyComparitor: public nsAVLNodeComparitor {
public:
virtual PRInt32 operator()(void* anItem1,void* anItem2)
@@ -151,4 +153,7 @@ void XXXNeverCalled()
ToNewCString(str1);
ToNewCString(str2);
PL_DHashTableFinish(NULL);
#ifdef NS_ENABLE_LOGGING
nsLog();
#endif
}

View File

@@ -32,6 +32,7 @@
#include "nsMemoryImpl.h"
#include "nsErrorService.h"
#include "nsLogging.h"
#include "nsArena.h"
#include "nsByteBuffer.h"
#ifdef PAGE_MANAGER
@@ -83,6 +84,7 @@
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
static NS_DEFINE_CID(kConsoleServiceCID, NS_CONSOLESERVICE_CID);
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
static NS_DEFINE_CID(kLoggingServiceCID, NS_LOGGINGSERVICE_CID);
// ds
static NS_DEFINE_CID(kArenaCID, NS_ARENA_CID);
static NS_DEFINE_CID(kByteBufferCID, NS_BYTEBUFFER_CID);
@@ -346,6 +348,14 @@ nsresult NS_COM NS_InitXPCOM2(const char* productName,
nsErrorService::Create);
if (NS_FAILED(rv)) return rv;
#ifdef NS_ENABLE_LOGGING
rv = RegisterGenericFactory(compMgr, kLoggingServiceCID,
NS_LOGGINGSERVICE_CLASSNAME,
NS_LOGGINGSERVICE_CONTRACTID,
nsLoggingService::Create);
if (NS_FAILED(rv)) return rv;
#endif
rv = RegisterGenericFactory(compMgr, kArenaCID,
NS_ARENA_CLASSNAME,
NS_ARENA_CONTRACTID,
@@ -588,6 +598,11 @@ nsresult NS_COM NS_InitXPCOM2(const char* productName,
nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
NS_IF_RELEASE(iim);
// get the logging service so that it gets registered with the service
// manager, and later unregistered
#ifdef NS_ENABLE_LOGGING
nsCOMPtr<nsILoggingService> logServ = do_GetService(kLoggingServiceCID, &rv);
#endif
return rv;
}

View File

@@ -26,6 +26,11 @@
#include "nsCRT.h"
#include "plhash.h"
#include "nsISizeOfHandler.h"
#include "nslog.h"
NS_IMPL_LOG(nsAtomTableLog)
#define PRINTF NS_LOG_PRINTF(nsAtomTableLog)
#define FLUSH NS_LOG_FLUSH(nsAtomTableLog)
/**
* The shared hash table for atom lookups.
@@ -53,8 +58,8 @@ NS_COM void NS_PurgeAtomTable(void)
if (gAtomHashTable) {
#if defined(DEBUG) && (defined(XP_UNIX) || defined(XP_PC))
if (gAtoms) {
if (getenv("MOZ_DUMP_ATOM_LEAKS")) {
printf("*** leaking %d atoms\n", gAtoms);
if (NS_LOG_ENABLED(nsAtomTableLog)) {
PRINTF("*** leaking %d atoms\n", gAtoms);
PL_HashTableEnumerateEntries(gAtomHashTable, DumpAtomLeaks, 0);
}
}