Repository navigation
Expand file tree
/
Copy pathLoggable.java
More file actions
99 lines (89 loc) · 4.11 KB
/
Copy pathLoggable.java
File metadata and controls
99 lines (89 loc) · 4.11 KB
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
91
92
93
94
95
96
97
98
99
package com.compact.tools.hire;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* Service Log Klasse
*/
public class Loggable extends HireSession
{
//--------------------------------------------------------------------------------------------------------------------------------
public Loggable()
{
}
//--------------------------------------------------------------------------------------------------------------------------------
//TODO C: auf log4j umsteigen
/**
* Logmeldung in Stdandard Logfile des Application Servers. Basiert auf dem
* NCSA Log Format.
*
* @param message
* die Logausgabe
*/
public void log( final Object message )
{
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// Aufrufende Klasse ermitteln
String callingClass = stackTrace[2].getClassName().substring( stackTrace[2].getClassName().lastIndexOf( "." ) + 1 );
System.out.println( this.getSessionId() + " [" + new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ).format( new Date() ) + "]=> Hire Service->"
+ callingClass + "::" + stackTrace[2].getMethodName() + "(): " + message );
}
/**
* Logmeldung in Stdandard Logfile des Application Servers. Basiert auf dem
* NCSA Log Format.
*
* @param message
* die Logausgabe
*/
public void logCron( final Object message )
{
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// Aufrufende Klasse ermitteln
String callingClass = stackTrace[2].getClassName().substring( stackTrace[2].getClassName().lastIndexOf( "." ) + 1 );
System.out.println( "HIRE CRON" + " [" + new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ).format( new Date() ) + "]=> Hire Service->"
+ callingClass + "::" + stackTrace[2].getMethodName() + "(): " + message );
}
/**
* Logmeldung in Standard Logfile des Application Servers. Basiert auf dem
* NCSA Log Format. Ausgabe "called" mit Zeilennummer.
*/
public void log()
{
try {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// Aufrufende Klasse ermitteln
String callingClass = stackTrace[2].getClassName().substring( stackTrace[2].getClassName().lastIndexOf( "." ) + 1 );
System.out.println( this.getSessionId() + " [" + new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ).format( new Date() )
+ "]=> Hire Service->" + stackTrace[2].getLineNumber() + " " + callingClass + "::" + stackTrace[2].getMethodName() + "(): "
+ "called" );
}
catch( Exception e ) {
e.printStackTrace();
}
}
/**
* Logmeldung in Standard Logfile des Application Servers. Basiert auf dem
* NCSA Log Format. Ausgabe "called" mit Zeilennummer.
*/
public static void logS( final Object message) {
try {
ServletRequestAttributes attr = null;
try {
attr = ( ServletRequestAttributes ) RequestContextHolder.currentRequestAttributes();
}
catch (Exception e) {}
String sessionId = ( attr == null ) ? "HIRE CRON" : attr.getRequest().getSession().getId();
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// Aufrufende Klasse ermitteln
String callingClass = stackTrace[2].getClassName().substring( stackTrace[2].getClassName().lastIndexOf( "." ) + 1 );
System.out.println( sessionId + " [" + new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ).format( new Date() )
+ "]=> Hire Service->" + callingClass + "::" + stackTrace[2].getMethodName() + "(): "
+ message );
}
catch( Exception e ) {
e.printStackTrace();
}
}
//--------------------------------------------------------------------------------------------------------------------------------
}