25
25
import org.hibernate.annotations.CacheConcurrencyStrategy;
26
26
import org.hibernate.annotations.GenericGenerator;
27
27
import com.eucalyptus.bootstrap.Bootstrap;
28
import com.eucalyptus.entities.AbstractPersistent;
28
29
import com.google.common.collect.Lists;
32
@javax.persistence.Entity
31
33
@PersistenceContext( name = "eucalyptus_records" )
32
34
@Table( name = "records" )
33
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
35
@Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL )
34
36
@Inheritance( strategy = InheritanceType.TABLE_PER_CLASS )
35
37
@DiscriminatorColumn( name = "record_class", discriminatorType = DiscriminatorType.STRING )
36
38
@DiscriminatorValue( value = "base" )
37
public class BaseRecord implements Serializable, Record {
39
public class BaseRecord extends AbstractPersistent implements Serializable, Record {
39
private static Logger LOG = Logger.getLogger( BaseRecord.class );
41
@GeneratedValue( generator = "system-uuid" )
42
@GenericGenerator( name = "system-uuid", strategy = "uuid" )
43
@Column( name = "record_id" )
41
private static Logger LOG = Logger.getLogger( BaseRecord.class );
45
42
@Column( name = "record_timestamp" )
46
private Date timestamp;
43
private Date timestamp;
47
44
@Column( name = "record_type" )
48
45
@Enumerated( EnumType.STRING )
49
private EventType type;
46
private EventType type;
50
47
@Column( name = "record_class" )
51
48
@Enumerated( EnumType.STRING )
52
private EventClass eventClass;
49
private EventClass eventClass;
53
50
@Column( name = "record_creator" )
54
private String creator;
51
private String creator;
55
52
@Column( name = "record_code_location" )
56
private String codeLocation;
53
private String codeLocation;
57
54
@Column( name = "record_user_id" )
58
private String userId;
55
private String userId;
59
56
@Column( name = "record_correlation_id" )
60
private String correlationId;
57
private String correlationId;
62
59
@Column( name = "record_extra" )
64
61
@Column( name = "record_level" )
65
62
@Enumerated( EnumType.STRING )
66
private RecordLevel level;
68
private ArrayList others = Lists.newArrayList( );
70
private static final String ISNULL = "NULL";
72
private static final String NEXT = "\n";
74
private transient String lead;
76
private Class realCreator;
78
private static BlockingQueue<EventRecord> trace = new LinkedBlockingDeque<EventRecord>( );
80
private static BlockingQueue<EventRecord> debug = new LinkedBlockingDeque<EventRecord>( );
82
private static BlockingQueue<EventRecord> info = new LinkedBlockingDeque<EventRecord>( );
84
private static BlockingQueue<EventRecord> warn = new LinkedBlockingDeque<EventRecord>( );
86
private static BlockingQueue<EventRecord> error = new LinkedBlockingDeque<EventRecord>( );
88
private static BlockingQueue<EventRecord> fatal = new LinkedBlockingDeque<EventRecord>( );
63
private RecordLevel level;
65
private ArrayList others = Lists.newArrayList( );
67
private static final String ISNULL = "NULL";
69
protected static final String NEXT = "\n";
71
private transient String lead;
73
private Class realCreator;
75
private static BlockingQueue<EventRecord> trace = new LinkedBlockingDeque<EventRecord>( );
77
private static BlockingQueue<EventRecord> debug = new LinkedBlockingDeque<EventRecord>( );
79
private static BlockingQueue<EventRecord> info = new LinkedBlockingDeque<EventRecord>( );
81
private static BlockingQueue<EventRecord> warn = new LinkedBlockingDeque<EventRecord>( );
83
private static BlockingQueue<EventRecord> error = new LinkedBlockingDeque<EventRecord>( );
85
private static BlockingQueue<EventRecord> fatal = new LinkedBlockingDeque<EventRecord>( );
89
87
public BaseRecord( EventType type, EventClass clazz, Class creator, StackTraceElement codeLocation, String userId, String correlationId, String other ) {
91
89
this.eventClass = clazz;
92
90
this.realCreator = creator;
93
this.creator = creator.getSimpleName( );
94
this.codeLocation = codeLocation.toString( );
91
this.creator = creator != null
92
? creator.getSimpleName( )
94
this.codeLocation = codeLocation != null
95
? codeLocation.toString( )
95
97
this.userId = userId;
96
98
this.correlationId = correlationId;
97
this.timestamp = new Date();
99
this.timestamp = new Date( );
98
100
this.extra = other;
99
101
this.others.add( other );
102
104
public BaseRecord( ) {}
105
* @see com.eucalyptus.records.Record#info()
108
106
public Record info( ) {
109
107
this.level = RecordLevel.INFO;
110
108
Logger.getLogger( this.realCreator ).info( this );
115
* @see com.eucalyptus.records.Record#error()
118
112
public Record error( ) {
119
113
this.level = RecordLevel.ERROR;
120
114
Logger.getLogger( this.realCreator ).error( this );
125
* @see com.eucalyptus.records.Record#trace()
128
118
public Record trace( ) {
129
119
this.level = RecordLevel.TRACE;
130
120
Logger.getLogger( this.realCreator ).trace( this );
135
* @see com.eucalyptus.records.Record#debug()
138
124
public Record debug( ) {
139
125
this.level = RecordLevel.DEBUG;
140
126
Logger.getLogger( this.realCreator ).debug( this );
145
* @see com.eucalyptus.records.Record#warn()
131
public Record extreme( ) {
132
this.level = RecordLevel.TRACE;
133
Logs.extreme( ).trace( this );
138
public Record exhaust( ) {
139
this.level = RecordLevel.TRACE;
140
Logs.exhaust( ).trace( this );
148
144
public Record warn( ) {
149
145
this.level = RecordLevel.WARN;
150
146
Logger.getLogger( this.realCreator ).warn( this );
155
* @see com.eucalyptus.records.Record#next()
158
150
public Record next( ) {
159
this.others.add( NEXT );
161
152
for ( Object o : this.others ) {
153
if ( o == null ) continue;
162
154
this.extra += ":" + o.toString( );
156
Record newThis = new LogFileRecord( this.eventClass, this.type, this.realCreator, null, this.userId, this.correlationId, "" );
168
* @see com.eucalyptus.records.Record#append(java.lang.Object)
172
160
public Record append( Object... obj ) {
173
161
for ( Object o : obj ) {
174
this.others.add( o == null ? ISNULL : "" + o );
162
this.others.add( o == null
177
167
for ( Object o : this.others ) {
168
if ( o == null ) continue;
178
169
this.extra += ":" + o.toString( );
199
190
private String leadIn( ) {
200
return lead == null ? ( lead = String.format( ":%010d:%s:%s:%s:%s:", this.getTimestamp( ).getTime( ), this.getCreator( ),
201
( ( this.correlationId != null ) ? this.correlationId : "" ), ( ( this.userId != null ) ? this.userId : "" ),
202
this.type ) ) : lead;
192
? ( lead = String.format( ":%010d:%s:%s:%s:%s:", this.getTimestamp( ).getTime( ), this.getCreator( ),
193
( ( this.correlationId != null )
195
: "" ), ( ( this.userId != null )
206
* @see com.eucalyptus.records.Record#toString()
209
202
public String toString( ) {
210
203
String ret = this.leadIn( );
211
204
for ( Object o : this.others ) {
205
if ( o == null ) continue;
212
206
ret += ":" + o.toString( );
214
208
return ret.replaceAll( "::*", ":" ).replaceAll( NEXT, NEXT + this.leadIn( ) );
217
public String getId( ) {
221
public void setId( String id ) {
226
211
public Date getTimestamp( ) {
227
212
return this.timestamp;
230
215
public void setTimestamp( Date timestamp ) {
231
216
this.timestamp = timestamp;
234
219
public EventType getType( ) {
235
220
return this.type;
287
272
this.correlationId = correlationId;
291
* @see com.eucalyptus.records.Record#hashCode()
275
public Record withDetails( String userId, String primaryInfo, String key, String value ) {
276
this.userId = userId;
277
this.correlationId = primaryInfo;
278
return this.withDetails( key, value );
281
public Record withDetails( String key, String value ) {
282
this.others.clear( );
283
this.others.add( key );
284
this.others.add( value );
295
290
public int hashCode( ) {
296
291
final int prime = 31;
298
result = prime * result + ( ( this.eventClass == null ) ? 0 : this.eventClass.hashCode( ) );
299
result = prime * result + ( ( this.codeLocation == null ) ? 0 : this.codeLocation.hashCode( ) );
300
result = prime * result + ( ( this.correlationId == null ) ? 0 : this.correlationId.hashCode( ) );
301
result = prime * result + ( ( this.creator == null ) ? 0 : this.creator.hashCode( ) );
302
result = prime * result + ( ( this.timestamp == null ) ? 0 : this.timestamp.hashCode( ) );
303
result = prime * result + ( ( this.type == null ) ? 0 : this.type.hashCode( ) );
304
result = prime * result + ( ( this.userId == null ) ? 0 : this.userId.hashCode( ) );
293
result = prime * result + ( ( this.eventClass == null )
295
: this.eventClass.hashCode( ) );
296
result = prime * result + ( ( this.codeLocation == null )
298
: this.codeLocation.hashCode( ) );
299
result = prime * result + ( ( this.correlationId == null )
301
: this.correlationId.hashCode( ) );
302
result = prime * result + ( ( this.creator == null )
304
: this.creator.hashCode( ) );
305
result = prime * result + ( ( this.timestamp == null )
307
: this.timestamp.hashCode( ) );
308
result = prime * result + ( ( this.type == null )
310
: this.type.hashCode( ) );
311
result = prime * result + ( ( this.userId == null )
313
: this.userId.hashCode( ) );