1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Description: test program for logging's basic functions
20 /* lth. re-define PR_LOG() */
24 #define PR_LOG_TEST(_module,_level) ((_module)->level <= (_level))
25 #define PR_LOG(_module,_level,_args) \
27 if (PR_LOG_TEST(_module,_level)) \
33 static void Error(const char* msg
)
35 printf("\t%s\n", msg
);
38 static void PR_CALLBACK
forked(void *arg
)
44 PR_LogPrint("%s logging creating mutex\n", (const char*)arg
);
46 PR_LogPrint("%s logging creating condition variable\n", (const char*)arg
);
47 cv
= PR_NewCondVar(ml
);
49 PR_LogPrint("%s waiting on condition timeout 10 times\n", (const char*)arg
);
50 for (i
= 0; i
< 10; ++i
)
53 PR_WaitCondVar(cv
, PR_SecondsToInterval(1));
57 PR_LogPrint("%s logging destroying condition variable\n", (const char*)arg
);
58 PR_DestroyCondVar(cv
);
59 PR_LogPrint("%s logging destroying mutex\n", (const char*)arg
);
61 PR_LogPrint("%s forked thread exiting\n", (const char*)arg
);
64 static void UserLogStuff( void )
66 PRLogModuleInfo
*myLM
;
69 myLM
= PR_NewLogModule( "userStuff" );
72 printf("UserLogStuff(): can't create new log module\n" );
76 PR_LOG( myLM
, PR_LOG_NOTICE
, ("Log a Notice %d\n", 1 ));
78 for (i
= 0; i
< 10 ; i
++ )
80 PR_LOG( myLM
, PR_LOG_DEBUG
, ("Log Debug number: %d\n", i
));
84 } /* end UserLogStuff() */
86 int main(int argc
, char **argv
)
90 PR_Init(PR_USER_THREAD
, PR_PRIORITY_NORMAL
, 0);
95 if (!PR_SetLogFile(argv
[1]))
97 Error("Access: Cannot create log file");
102 /* Start logging something here */
103 PR_LogPrint("%s logging into %s\n", argv
[0], argv
[1]);
105 PR_LogPrint("%s creating new thread\n", argv
[0]);
108 ** Now change buffering.
110 PR_SetLogBuffering( 65500 );
111 thread
= PR_CreateThread(
112 PR_USER_THREAD
, forked
, (void*)argv
[0], PR_PRIORITY_NORMAL
,
113 PR_LOCAL_THREAD
, PR_JOINABLE_THREAD
, 0);
114 PR_LogPrint("%s joining thread\n", argv
[0]);
118 PR_JoinThread(thread
);