]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionStep.java
Improve logging
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / execution / ExecutionStep.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.execution;
18
19 import java.io.Serializable;
20 import java.util.Date;
21
22 /**
23 * An atomic step to be notified in during an {@link ExecutionProcess}. Can be a
24 * log or the start/end of a phase, etc.
25 */
26 public class ExecutionStep implements Serializable {
27 private static final long serialVersionUID = 798640526532912161L;
28
29 // public final static String START = "START";
30 // public final static String END = "END";
31 public final static String PHASE_START = "PHASE_START";
32 public final static String PHASE_END = "PHASE_END";
33 public final static String ERROR = "ERROR";
34 public final static String WARNING = "WARNING";
35 public final static String INFO = "INFO";
36 public final static String DEBUG = "DEBUG";
37 public final static String TRACE = "TRACE";
38
39 // TODO make the fields final and private when we don't need POJO support
40 // anymore (that
41 // is when SlcExecutionStep is removed)
42 protected String type;
43 protected String thread;
44 protected Date timestamp;
45 protected String log;
46
47 /** Empty constructor */
48 public ExecutionStep() {
49 thread = Thread.currentThread().getName();
50 }
51
52 /** Creates a step at the current date of type INFO */
53 public ExecutionStep(String log) {
54 this(new Date(), INFO, log);
55 }
56
57 /** Creates a step at the current date */
58 public ExecutionStep(String type, String log) {
59 this(new Date(), type, log);
60 }
61
62 /** Creates a step of the given type. */
63 public ExecutionStep(Date timestamp, String type, String log) {
64 this(timestamp, type, log, Thread.currentThread().getName());
65 }
66
67 public ExecutionStep(Date timestamp, String type, String log, String thread) {
68 this.type = type;
69 this.timestamp = timestamp;
70 this.thread = thread;
71 this.log = addLog(log);
72 }
73
74 public String getType() {
75 return type;
76 }
77
78 public Date getTimestamp() {
79 return timestamp;
80 }
81
82 public String getThread() {
83 return thread;
84 }
85
86 /**
87 * Return the string that should be stored in the log field. Can be null if
88 * another mechanism is used to store log lines.
89 */
90 protected String addLog(String log) {
91 return log;
92 }
93
94 public String getLog() {
95 return log;
96 }
97
98 @Override
99 public String toString() {
100 return "Execution step, thread=" + thread + ", type=" + type;
101 }
102
103 }