Skip to content

Commit

Permalink
Bug 1134 - Refine Logging using 'LoggerIf' - Replace System.err w/ Lo…
Browse files Browse the repository at this point in the history
…gging where appropriate
  • Loading branch information
sgothel committed Mar 6, 2015
1 parent 8eb9e27 commit 54dcf42
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 156 deletions.
7 changes: 3 additions & 4 deletions src/java/com/jogamp/gluegen/CMethodBindingEmitter.java
Expand Up @@ -44,10 +44,9 @@
import java.text.MessageFormat;

import com.jogamp.common.os.MachineDataInfo;
import com.jogamp.gluegen.Logging.LoggerIf;
import com.jogamp.gluegen.cgram.types.*;

import java.util.logging.Logger;

/** Emits the C-side component of the Java<->C JNI binding. */
public class CMethodBindingEmitter extends FunctionEmitter {

Expand All @@ -57,7 +56,7 @@ public class CMethodBindingEmitter extends FunctionEmitter {
protected static final String arrayRes = "_array_res";
protected static final String arrayIdx = "_array_idx";

protected final Logger LOG;
protected final LoggerIf LOG;

protected MethodBinding binding;

Expand Down Expand Up @@ -129,7 +128,7 @@ public CMethodBindingEmitter(final MethodBinding binding,
final JavaConfiguration configuration)
{
super(output, false, configuration);
LOG = Logging.getLogger(CMethodBindingEmitter.class.getPackage().getName());
LOG = Logging.getLogger(CMethodBindingEmitter.class.getPackage().getName(), CMethodBindingEmitter.class.getSimpleName());

assert(binding != null);
assert(javaClassName != null);
Expand Down
7 changes: 7 additions & 0 deletions src/java/com/jogamp/gluegen/GlueGen.java
Expand Up @@ -71,6 +71,8 @@ public class GlueGen implements GlueEmitterControls {

private static boolean debug = false;

private static Level logLevel = null;

public static boolean debug() { return debug; }

@Override
Expand Down Expand Up @@ -103,6 +105,8 @@ public void run(final Reader reader, final String filename, final Class<?> emitt
try {
if(debug) {
Logging.getLogger().setLevel(Level.ALL);
} else if( null != logLevel ) {
Logging.getLogger().setLevel(logLevel);
}
final GlueEmitter emit;
if (emitterClass == null) {
Expand Down Expand Up @@ -377,6 +381,9 @@ public static void main(final String... args) {
emitterFQN = arg.substring(2);
} else if (arg.startsWith("-C")) {
cfgFiles.add(arg.substring(2));
} else if (arg.equals("--logLevel")) {
i++;
logLevel = Level.parse(args[i]);
} else if (arg.equals("--debug")) {
debug=true;
} else if (arg.equals("--dumpCPP")) {
Expand Down
106 changes: 41 additions & 65 deletions src/java/com/jogamp/gluegen/JavaConfiguration.java
Expand Up @@ -42,6 +42,7 @@

import com.jogamp.gluegen.JavaEmitter.EmissionStyle;
import com.jogamp.gluegen.JavaEmitter.MethodAccess;
import com.jogamp.gluegen.Logging.LoggerIf;

import java.io.*;
import java.lang.reflect.Array;
Expand All @@ -51,8 +52,6 @@
import com.jogamp.gluegen.jgram.*;
import com.jogamp.gluegen.cgram.types.*;

import java.util.logging.Logger;

import static java.util.logging.Level.*;
import static com.jogamp.gluegen.JavaEmitter.MethodAccess.*;
import static com.jogamp.gluegen.JavaEmitter.EmissionStyle.*;
Expand All @@ -61,17 +60,13 @@
JavaEmitter. */

public class JavaConfiguration {

public static final boolean DEBUG_IGNORES = GlueGen.debug() || false;
public static final boolean DEBUG_RENAMES = GlueGen.debug() || false;

private int nestedReads;
private String packageName;
private String implPackageName;
private String className;
private String implClassName;

protected final Logger LOG;
protected final LoggerIf LOG;

public static String NEWLINE = System.getProperty("line.separator");

Expand Down Expand Up @@ -186,7 +181,7 @@ public class JavaConfiguration {
private final Map<String, List<String>> javaEpilogues = new HashMap<String, List<String>>();

public JavaConfiguration() {
LOG = Logging.getLogger(JavaConfiguration.class.getPackage().getName());
LOG = Logging.getLogger(JavaConfiguration.class.getPackage().getName(), JavaConfiguration.class.getSimpleName());
}

/** Reads the configuration file.
Expand Down Expand Up @@ -728,48 +723,48 @@ public String extendedParentClass(final String className) {
return parentClass.get(className);
}

public void dumpIgnoresOnce() {
if(!dumpedIgnores) {
dumpedIgnores = true;
dumpIgnores();
public void logIgnoresOnce() {
if(!loggedIgnores) {
loggedIgnores = true;
logIgnores();
}
}
private static boolean dumpedIgnores = false;
private static boolean loggedIgnores = false;

public void dumpIgnores() {
System.err.println("Extended Intf: ");
public void logIgnores() {
LOG.log(INFO, "Extended Intf: {0}", extendedIntfSymbolsIgnore.size());
for (final String str : extendedIntfSymbolsIgnore) {
System.err.println("\t"+str);
LOG.log(INFO, "\t{0}", str);
}
System.err.println("Extended Impl: ");
LOG.log(INFO, "Extended Impl: {0}", extendedImplSymbolsIgnore.size());
for (final String str : extendedImplSymbolsIgnore) {
System.err.println("\t"+str);
LOG.log(INFO, "\t{0}", str);
}
System.err.println("Ignores (All): ");
LOG.log(INFO, "Ignores (All): {0}", ignores.size());
for (final Pattern pattern : ignores) {
System.err.println("\t"+pattern);
LOG.log(INFO, "\t{0}", pattern);
}
}

public void dumpRenamesOnce() {
if(!dumpedRenames) {
dumpedRenames = true;
dumpRenames();
public void logRenamesOnce() {
if(!loggedRenames) {
loggedRenames = true;
logRenames();
}
}
private static boolean dumpedRenames = false;
private static boolean loggedRenames = false;

public void dumpRenames() {
System.err.println("Symbol Renames: ");
public void logRenames() {
LOG.log(INFO, "Symbol Renames: {0}", javaSymbolRenames.size());
for (final String key : javaSymbolRenames.keySet()) {
System.err.println("\t"+key+" -> "+javaSymbolRenames.get(key));
LOG.log(INFO, "\t{0} -> {1}", key, javaSymbolRenames.get(key));
}

System.err.println("Symbol Aliasing (through renaming): ");
LOG.log(INFO, "Symbol Aliasing (through renaming): {0}", javaSymbolRenames.size());
for(final String newName : javaSymbolRenames.values()) {
final Set<String> origNames = javaRenamedSymbols.get(newName);
if(null!=origNames) {
System.err.println("\t"+newName+" <- "+origNames);
LOG.log(INFO, "\t{0} <- {1}", newName, origNames);
}
}
}
Expand Down Expand Up @@ -848,8 +843,8 @@ private static boolean onePatternMatch(final Pattern ignoreRegexp, final Set<Str
return false;
}
protected final boolean shouldIgnoreInInterface_Int(final AliasedSymbol symbol) {
if(DEBUG_IGNORES) {
dumpIgnoresOnce();
if( GlueGen.debug() ) {
logIgnoresOnce();
}
final String name = symbol.getName();
final Set<String> aliases = symbol.getAliasedNames();
Expand All @@ -859,18 +854,14 @@ protected final boolean shouldIgnoreInInterface_Int(final AliasedSymbol symbol)
oneInSet(extendedIntfSymbolsIgnore, aliases)
)
{
if(DEBUG_IGNORES) {
System.err.println("Ignore Intf ignore (one): "+symbol.getAliasedString());
}
LOG.log(INFO, "Ignore Intf ignore (one): {0}", symbol.getAliasedString());
return true;
}
// Simple case-2; the entire symbol (orig and renamed) is _not_ in the not-empty interface only table
if ( !extendedIntfSymbolsOnly.isEmpty() &&
!extendedIntfSymbolsOnly.contains( name ) &&
!oneInSet(extendedIntfSymbolsOnly, aliases) ) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Intf !extended (all): " + symbol.getAliasedString());
}
LOG.log(INFO, "Ignore Intf !extended (all): {0}", symbol.getAliasedString());
return true;
}
return shouldIgnoreInImpl_Int(symbol);
Expand Down Expand Up @@ -901,18 +892,14 @@ protected final boolean shouldIgnoreInImpl_Int(final AliasedSymbol symbol) {
oneInSet(extendedImplSymbolsIgnore, aliases)
)
{
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl ignore (one): "+symbol.getAliasedString());
}
LOG.log(INFO, "Ignore Impl ignore (one): {0}", symbol.getAliasedString());
return true;
}
// Simple case-2; the entire symbol (orig and renamed) is _not_ in the not-empty interface only table
if ( !extendedImplSymbolsOnly.isEmpty() &&
!extendedImplSymbolsOnly.contains( name ) &&
!oneInSet(extendedImplSymbolsOnly, aliases) ) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl !extended (all): " + symbol.getAliasedString());
}
LOG.log(INFO, "Ignore Impl !extended (all): {0}", symbol.getAliasedString());
return true;
}

Expand All @@ -921,9 +908,7 @@ protected final boolean shouldIgnoreInImpl_Int(final AliasedSymbol symbol) {
for (final Pattern ignoreRegexp : ignores) {
final Matcher matcher = ignoreRegexp.matcher(name);
if ( matcher.matches() || onePatternMatch(ignoreRegexp, aliases) ) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl RegEx: "+symbol.getAliasedString());
}
LOG.log(INFO, "Ignore Impl RegEx: {0}", symbol.getAliasedString());
return true;
}
}
Expand All @@ -938,9 +923,7 @@ protected final boolean shouldIgnoreInImpl_Int(final AliasedSymbol symbol) {
// Special case as this is most often likely to be the case.
// Unignores are not used very often.
if(unignores.isEmpty()) {
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl unignores==0: "+symbol.getAliasedString()+" -> "+name);
}
LOG.log(INFO, "Ignore Impl unignores==0: {0} -> {1}", symbol.getAliasedString(), name);
return true;
}
boolean unignoreFound = false;
Expand All @@ -952,11 +935,10 @@ protected final boolean shouldIgnoreInImpl_Int(final AliasedSymbol symbol) {
}
}

if (!unignoreFound)
if(DEBUG_IGNORES) {
System.err.println("Ignore Impl !unignore: "+symbol.getAliasedString()+" -> "+name);
}
return true;
if (!unignoreFound) {
LOG.log(INFO, "Ignore Impl !unignore: {0} -> {1}", symbol.getAliasedString(), name);
return true;
}
}
}
}
Expand Down Expand Up @@ -1010,8 +992,8 @@ public String renameJavaType(final String javaTypeName) {
function under the hood. Returns null if this symbol has not
been explicitly renamed. */
public String getJavaSymbolRename(final String origName) {
if(DEBUG_RENAMES) {
dumpRenamesOnce();
if( LOG.isLoggable(INFO) ) {
logRenamesOnce();
}
return javaSymbolRenames.get(origName);
}
Expand All @@ -1023,18 +1005,12 @@ public Set<String> getRenamedJavaSymbols(final String aliasedName) {

/** Programmatically adds a rename directive for the given symbol. */
public void addJavaSymbolRename(final String origName, final String newName) {
if(DEBUG_RENAMES) {
System.err.print("\tRename "+origName+" -> "+newName);
}
LOG.log(INFO, "\tRename {0} -> {1}", origName, newName);
final String prevValue = javaSymbolRenames.put(origName, newName);
if(null != prevValue && !prevValue.equals(newName)) {
throw new RuntimeException("Rename-Override Attampt: "+origName+" -> "+newName+
", but "+origName+" -> "+prevValue+" already exist. Run in 'debug' mode to analyze!");
}
if(DEBUG_RENAMES) {
System.err.println();
}

Set<String> origNames = javaRenamedSymbols.get(newName);
if(null == origNames) {
origNames = new HashSet<String>();
Expand Down Expand Up @@ -1118,7 +1094,7 @@ protected void dispatch(final String cmd, final StringTokenizer tok, final File
try{
emissionStyle = EmissionStyle.valueOf(readString("Style", tok, filename, lineNo));
}catch(final IllegalArgumentException ex) {
LOG.log(WARNING, "Error parsing \"style\" command at line {0} in file \"{1}\"", new Object[]{lineNo, filename});
LOG.log(WARNING, "Error parsing \"style\" command at line {0} in file \"{1}\"", lineNo, filename);
}
} else if (cmd.equalsIgnoreCase("AccessControl")) {
readAccessControl(tok, filename, lineNo);
Expand Down

0 comments on commit 54dcf42

Please sign in to comment.