|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 // Original author: ekr@rtfm.com |
|
8 |
|
9 #ifndef logging_h__ |
|
10 #define logging_h__ |
|
11 |
|
12 #if defined(PR_LOG) |
|
13 #error "Must #include logging.h before any IPDL-generated files or other files that #include prlog.h." |
|
14 #endif |
|
15 |
|
16 // Enforce logging under production builds for MOZ_MTLOG friends. |
|
17 #ifndef PR_LOGGING |
|
18 #define FORCE_PR_LOG 1 |
|
19 #endif |
|
20 |
|
21 #include <sstream> |
|
22 #include <prlog.h> |
|
23 |
|
24 #if defined(PR_LOGGING) |
|
25 |
|
26 #define ML_EMERG 1 |
|
27 #define ML_ERROR 2 |
|
28 #define ML_WARNING 3 |
|
29 #define ML_NOTICE 4 |
|
30 #define ML_INFO 5 |
|
31 #define ML_DEBUG 6 |
|
32 |
|
33 // PR_LOGGING is on --> make useful MTLOG macros |
|
34 #define MOZ_MTLOG_MODULE(n) \ |
|
35 static PRLogModuleInfo* getLogModule() { \ |
|
36 static PRLogModuleInfo* log; \ |
|
37 if (!log) \ |
|
38 log = PR_NewLogModule(n); \ |
|
39 return log; \ |
|
40 } |
|
41 |
|
42 #define MOZ_MTLOG(level, b) \ |
|
43 do { \ |
|
44 std::stringstream str; \ |
|
45 str << b; \ |
|
46 PR_LOG(getLogModule(), level, ("%s", str.str().c_str())); } while(0) |
|
47 |
|
48 #else |
|
49 // PR_LOGGING is off --> make no-op MTLOG macros |
|
50 #define MOZ_MTLOG_MODULE(n) |
|
51 #define MOZ_MTLOG(level, b) |
|
52 |
|
53 #endif // defined(PR_LOGGING) |
|
54 |
|
55 #endif // logging_h__ |