You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultTraceFactory.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Matthew Webster - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.weaver.tools;
  12. import java.io.File;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.io.PrintStream;
  16. public class DefaultTraceFactory extends TraceFactory {
  17. public final static String ENABLED_PROPERTY = "org.aspectj.tracing.enabled";
  18. public final static String FILE_PROPERTY = "org.aspectj.tracing.file";
  19. private boolean tracingEnabled = getBoolean(ENABLED_PROPERTY,false);
  20. private PrintStream print;
  21. public DefaultTraceFactory() {
  22. String filename = System.getProperty(FILE_PROPERTY);
  23. if (filename != null) {
  24. File file = new File(filename);
  25. try {
  26. print = new PrintStream(new FileOutputStream(file));
  27. }
  28. catch (IOException ex) {
  29. if (debug) ex.printStackTrace();
  30. }
  31. }
  32. }
  33. public boolean isEnabled() {
  34. return tracingEnabled;
  35. }
  36. public Trace getTrace (Class clazz) {
  37. DefaultTrace trace = new DefaultTrace(clazz);
  38. trace.setTraceEnabled(tracingEnabled);
  39. if (print != null) trace.setPrintStream(print);
  40. return trace;
  41. }
  42. }