Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #include <stdio.h>
6 : #include <string.h>
7 : #include <stdarg.h>
8 :
9 : #include "CSFLog.h"
10 : #include "base/basictypes.h"
11 :
12 : #include <map>
13 : #include "prrwlock.h"
14 : #include "prthread.h"
15 : #include "nsThreadUtils.h"
16 :
17 : #include "mozilla/Logging.h"
18 : #include "mozilla/Sprintf.h"
19 :
20 : mozilla::LazyLogModule gSignalingLog("signaling");
21 :
22 0 : void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, va_list args)
23 : {
24 : #ifdef STDOUT_LOGGING
25 : printf("%s\n:",tag);
26 : vprintf(format, args);
27 : #else
28 :
29 0 : mozilla::LogLevel level = static_cast<mozilla::LogLevel>(priority);
30 :
31 : // Skip doing any of this work if we're not logging the indicated level...
32 0 : if (!MOZ_LOG_TEST(gSignalingLog, level)) {
33 0 : return;
34 : }
35 :
36 : // Trim the path component from the filename
37 0 : const char *lastSlash = sourceFile;
38 0 : while (*sourceFile) {
39 0 : if (*sourceFile == '/' || *sourceFile == '\\') {
40 0 : lastSlash = sourceFile;
41 : }
42 0 : sourceFile++;
43 : }
44 0 : sourceFile = lastSlash;
45 0 : if (*sourceFile == '/' || *sourceFile == '\\') {
46 0 : sourceFile++;
47 : }
48 :
49 : #define MAX_MESSAGE_LENGTH 1024
50 : char message[MAX_MESSAGE_LENGTH];
51 :
52 0 : const char *threadName = NULL;
53 :
54 : // Check if we're the main thread...
55 0 : if (NS_IsMainThread()) {
56 0 : threadName = "main";
57 : } else {
58 0 : threadName = PR_GetThreadName(PR_GetCurrentThread());
59 : }
60 :
61 : // If we can't find it anywhere, use a blank string
62 0 : if (!threadName) {
63 0 : threadName = "";
64 : }
65 :
66 0 : VsprintfLiteral(message, format, args);
67 0 : MOZ_LOG(gSignalingLog, level, ("[%s|%s] %s:%d: %s",
68 : threadName, tag, sourceFile, sourceLine,
69 : message));
70 : #endif
71 :
72 : }
73 :
74 0 : void CSFLog( CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, ...)
75 : {
76 : va_list ap;
77 0 : va_start(ap, format);
78 :
79 0 : CSFLogV(priority, sourceFile, sourceLine, tag, format, ap);
80 0 : va_end(ap);
81 0 : }
82 :
|