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