2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#include <stdarg.h>
|
|
27 |
#include <stdio.h>
|
|
28 |
#include <stdlib.h>
|
|
29 |
#include "Trace.h"
|
|
30 |
|
|
31 |
static int j2dTraceLevel = J2D_TRACE_INVALID;
|
|
32 |
static FILE *j2dTraceFile = NULL;
|
|
33 |
|
|
34 |
JNIEXPORT void JNICALL
|
|
35 |
J2dTraceImpl(int level, jboolean cr, const char *string, ...)
|
|
36 |
{
|
|
37 |
va_list args;
|
|
38 |
if (j2dTraceLevel < J2D_TRACE_OFF) {
|
|
39 |
J2dTraceInit();
|
|
40 |
}
|
|
41 |
if (level <= j2dTraceLevel) {
|
|
42 |
if (cr) {
|
|
43 |
switch (level) {
|
|
44 |
case J2D_TRACE_ERROR:
|
|
45 |
fprintf(j2dTraceFile, "[E] ");
|
|
46 |
break;
|
|
47 |
case J2D_TRACE_WARNING:
|
|
48 |
fprintf(j2dTraceFile, "[W] ");
|
|
49 |
break;
|
|
50 |
case J2D_TRACE_INFO:
|
|
51 |
fprintf(j2dTraceFile, "[I] ");
|
|
52 |
break;
|
|
53 |
case J2D_TRACE_VERBOSE:
|
|
54 |
fprintf(j2dTraceFile, "[V] ");
|
|
55 |
break;
|
|
56 |
case J2D_TRACE_VERBOSE2:
|
|
57 |
fprintf(j2dTraceFile, "[X] ");
|
|
58 |
break;
|
|
59 |
default:
|
|
60 |
break;
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
va_start(args, string);
|
|
65 |
vfprintf(j2dTraceFile, string, args);
|
|
66 |
va_end(args);
|
|
67 |
|
|
68 |
if (cr) {
|
|
69 |
fprintf(j2dTraceFile, "\n");
|
|
70 |
}
|
|
71 |
fflush(j2dTraceFile);
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
JNIEXPORT void JNICALL
|
|
76 |
J2dTraceInit()
|
|
77 |
{
|
|
78 |
char *j2dTraceLevelString = getenv("J2D_TRACE_LEVEL");
|
|
79 |
char *j2dTraceFileName;
|
|
80 |
j2dTraceLevel = J2D_TRACE_OFF;
|
|
81 |
if (j2dTraceLevelString) {
|
|
82 |
int traceLevelTmp = -1;
|
|
83 |
int args = sscanf(j2dTraceLevelString, "%d", &traceLevelTmp);
|
|
84 |
if (args > 0 &&
|
|
85 |
traceLevelTmp > J2D_TRACE_INVALID &&
|
|
86 |
traceLevelTmp < J2D_TRACE_MAX)
|
|
87 |
{
|
|
88 |
j2dTraceLevel = traceLevelTmp;
|
|
89 |
}
|
|
90 |
}
|
|
91 |
j2dTraceFileName = getenv("J2D_TRACE_FILE");
|
|
92 |
if (j2dTraceFileName) {
|
|
93 |
j2dTraceFile = fopen(j2dTraceFileName, "w");
|
|
94 |
if (!j2dTraceFile) {
|
|
95 |
printf("[E]: Error opening trace file %s\n", j2dTraceFileName);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
if (!j2dTraceFile) {
|
|
99 |
j2dTraceFile = stdout;
|
|
100 |
}
|
|
101 |
}
|