Alejandro Acuña
2024-08-12 831c7bd85763b5eb5ef46664c65f0181824f9e13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package art.servers.log;
 
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
 
 
public class LogVMS
{
    BufferedWriter out = null;
 
    private static java.text.SimpleDateFormat _sdf = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS");
    private static java.text.SimpleDateFormat formato1 = new java.text.SimpleDateFormat("dd-MM-yyyy");
    private static java.text.SimpleDateFormat formato2 = new java.text.SimpleDateFormat("HH-mm-ss");
 
 
    public LogVMS (String identifier)
    {
        crear(identifier);
    }
 
 
 
 
 
    public void escribir (String mens)
    {
        try
        {
            out.write(_sdf.format(new java.util.Date()) + " - " + mens);
            out.newLine();
            out.flush();
        }
        catch (Exception e)
        {
        }
    }
 
 
    public void escribir (String mens, Exception exception)
    {
        try
        {
            StringWriter sw = new StringWriter();
            exception.printStackTrace(new PrintWriter(sw));
            out.write(_sdf.format(new java.util.Date()) + " - " + mens);
            out.write(_sdf.format(new java.util.Date()) + " - " + exception.getMessage());
            out.write(_sdf.format(new java.util.Date()) + " - " + sw.toString());
            out.newLine();
            out.flush();
        }
        catch (Exception e)
        {
        }
    }
 
 
 
 
 
 
    private void crear (String identifier)
    {
        try
        {
            Date date = new Date();
            try{out.close();} catch (Exception e){};
            try{out = null;} catch (Exception e){};
            String carpeta = "vms/Logs/" + identifier;
            File file = new File(carpeta);
            file.mkdirs();
            String carpeta2 = "vms/Logs/" + identifier + "/" + formato1.format(date);
            File file2 = new File(carpeta2);
            file2.mkdirs();
            String nombre = carpeta2 + "/" + formato2.format(date) + ".dat";
            out = new BufferedWriter (
                    new OutputStreamWriter (
                      new FileOutputStream (nombre)));
        }
        catch (Exception e)
        {
        }
    }
 
}