1 package es.caib.signatura.impl;
2
3 import java.io.File;
4 import java.io.FileWriter;
5
6 import java.io.Writer;
7
8
9
10 public class SigDebug {
11 public static final int DEBUG_LEVEL_NONE = 0;
12 public static final int DEBUG_LEVEL_NORMAL = 1;
13 public static final int DEBUG_LEVEL_VERBOSE = 2;
14
15 private static int level = 0;
16 private static boolean active = true;
17 private static boolean verbose = true;
18
19 private static String missatge = null;
20
21 private static File fitxerDebug = null;
22
23 public static final String NL = "\n";
24
25 public static void setLevel( int l ) {
26 level = l;
27 active = level > 0;
28 verbose = level > 1;
29 }
30
31 public static void setLevel( String l ) {
32 try {
33 if( l != null && l.length() > 0 ) {
34 setLevel( Integer.parseInt( l ) );
35 }
36 } catch(Throwable t) { }
37 }
38
39 public static void setFitxerDebug( File f ) {
40 fitxerDebug = f;
41 }
42
43
44
45
46
47
48 public static void write( String msg ) {
49 System.out.println( msg );
50 System.out.flush();
51 if( fitxerDebug != null )
52 {
53 try {
54 Writer log = new FileWriter( fitxerDebug, true );
55 log.write( msg + NL );
56 log.flush();
57 log.close();
58 } catch( Exception e ) {
59 e.printStackTrace();
60 }
61 }
62
63
64
65
66
67 }
68
69 public static boolean isActive()
70 {
71 return active;
72 }
73
74 public static boolean isVerbose()
75 {
76 return verbose;
77 }
78
79 public static int getLevel()
80 {
81 return level;
82 }
83 }