Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: talk/app/webrtc/java/src/org/webrtc/Logging.java

Issue 1338033003: Log to webrtc logging stream from java code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: not lose tag Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products 13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import java.io.ByteArrayOutputStream;
31 import java.io.PrintStream;
32 import java.nio.charset.Charset;
30 import java.util.EnumSet; 33 import java.util.EnumSet;
31 34
32 /** Java wrapper for WebRTC & libjingle logging. */ 35 /** Java wrapper for WebRTC & libjingle logging. */
33 public class Logging { 36 public class Logging {
34 static { 37 static {
35 System.loadLibrary("jingle_peerconnection_so"); 38 System.loadLibrary("jingle_peerconnection_so");
36 } 39 }
37 40
38 // Keep in sync with webrtc/common_types.h:TraceLevel. 41 // Keep in sync with webrtc/common_types.h:TraceLevel.
39 public enum TraceLevel { 42 public enum TraceLevel {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 public static void enableTracing( 80 public static void enableTracing(
78 String path, EnumSet<TraceLevel> levels, Severity severity) { 81 String path, EnumSet<TraceLevel> levels, Severity severity) {
79 int nativeLevel = 0; 82 int nativeLevel = 0;
80 for (TraceLevel level : levels) { 83 for (TraceLevel level : levels) {
81 nativeLevel |= level.level; 84 nativeLevel |= level.level;
82 } 85 }
83 nativeEnableTracing(path, nativeLevel, severity.ordinal()); 86 nativeEnableTracing(path, nativeLevel, severity.ordinal());
84 } 87 }
85 88
86 public static void log(Severity severity, String tag, String message) { 89 public static void log(Severity severity, String tag, String message) {
87 nativeLog(severity.ordinal(), tag + ": " + message); 90 nativeLog(severity.ordinal(), tag, message);
91 }
92
93 public static void d(String tag, String message) {
94 log(Severity.LS_INFO, tag, message);
95 }
96
97 public static void e(String tag, String message) {
98 log(Severity.LS_ERROR, tag, message);
99 }
100
101 public static void w(String tag, String message) {
102 log(Severity.LS_WARNING, tag, message);
103 }
104
105 public static void e(String tag, String message, Throwable e) {
106 log(Severity.LS_ERROR, tag, message);
107 log(Severity.LS_ERROR, tag, e.toString());
108 log(Severity.LS_ERROR, tag, getStackTraceAsString(e));
109 }
110
111 public static void w(String tag, String message, Throwable e) {
112 log(Severity.LS_WARNING, tag, message);
113 log(Severity.LS_WARNING, tag, e.toString());
114 log(Severity.LS_WARNING, tag, getStackTraceAsString(e));
115 }
116
117 public static void v(String tag, String message) {
118 log(Severity.LS_VERBOSE, tag, message);
119 }
120
121 private static String getStackTraceAsString(Throwable e) {
AlexG 2015/09/14 20:12:33 May be mimic Android implementation here (getStack
jiayl2 2015/09/14 20:54:38 Done.
122 ByteArrayOutputStream ostream = new ByteArrayOutputStream();
123 PrintStream pstream = new PrintStream(ostream);
124 e.printStackTrace(pstream);
125 return ostream.toString();
88 } 126 }
89 127
90 private static native void nativeEnableTracing( 128 private static native void nativeEnableTracing(
91 String path, int nativeLevels, int nativeSeverity); 129 String path, int nativeLevels, int nativeSeverity);
92 private static native void nativeEnableLogThreads(); 130 private static native void nativeEnableLogThreads();
93 private static native void nativeEnableLogTimeStamps(); 131 private static native void nativeEnableLogTimeStamps();
94 private static native void nativeLog(int severity, String message); 132 private static native void nativeLog(int severity, String tag, String message) ;
95 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698