Skip to content

Commit 3d34ad3

Browse files
committed
#509 修改日志输出格式
1 parent 0721246 commit 3d34ad3

21 files changed

+296
-238
lines changed

saturn-core/src/main/java/com/vip/saturn/job/basic/AbstractElasticJob.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public final void execute() {
150150
LogUtils.debug(log, jobName, "Saturn finish to execute job [{}], sharding context:{}.", jobName,
151151
shardingContext);
152152
} catch (Exception e) {
153-
log.warn(String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
153+
LogUtils.warn(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
154+
e);
154155
} finally {
155156
running = false;
156157
}
@@ -190,7 +191,8 @@ private void executeJobInternal(final JobExecutionMultipleShardingContext shardi
190191
* @return 是否继续执行完complete节点,清空failover信息
191192
*/
192193
private boolean checkIfZkLostAfterExecution(final Integer item) {
193-
CuratorFramework curatorFramework = (CuratorFramework) executionService.getCoordinatorRegistryCenter().getRawClient();
194+
CuratorFramework curatorFramework = (CuratorFramework) executionService.getCoordinatorRegistryCenter()
195+
.getRawClient();
194196
try {
195197
String runningPath = JobNodePath.getNodeFullPath(jobName, ExecutionNode.getRunningNode(item));
196198
Stat itemStat = curatorFramework.checkExists().forPath(runningPath);
@@ -200,7 +202,8 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {
200202
long ephemeralOwner = itemStat.getEphemeralOwner();
201203
if (ephemeralOwner != sessionId) {
202204
LogUtils.info(log, jobName,
203-
"item={} 's running node doesn't belong to current zk, node sessionid is {}, current zk sessionid is {}",
205+
"item={} 's running node doesn't belong to current zk, node sessionid is {}, current zk "
206+
+ "sessionid is {}",
204207
item, ephemeralOwner, sessionId);
205208
return false;
206209
} else {
@@ -212,7 +215,7 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {
212215

213216
return false;
214217
} catch (Throwable e) {
215-
log.error(String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
218+
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
216219
return false;
217220
}
218221
}

saturn-core/src/main/java/com/vip/saturn/job/basic/AbstractSaturnJob.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.vip.saturn.job.exception.JobException;
99
import com.vip.saturn.job.executor.SaturnExecutorService;
1010
import com.vip.saturn.job.internal.statistics.ProcessCountStatistics;
11+
import com.vip.saturn.job.utils.LogEvents;
1112
import com.vip.saturn.job.utils.LogUtils;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
@@ -129,7 +130,7 @@ public Properties parseKV(String path) {
129130
if (tmps != null && tmps.length == 2) {
130131
kv.put(tmps[0].trim(), tmps[1].trim());
131132
} else {
132-
log.warn("msg=Param is not valid {}", p);
133+
LogUtils.warn(log, jobName, "msg=Param is not valid {}", p);
133134
}
134135
}
135136
}

saturn-core/src/main/java/com/vip/saturn/job/basic/JobScheduler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ public void shutdown(boolean removejob) {
286286
job.shutdown();
287287
}
288288
} catch (final Exception e) {
289-
log.error(String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
289+
LogUtils.error(log, jobName,
290+
String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
290291
}
291292

292293
listenerManager.shutdown();

saturn-core/src/main/java/com/vip/saturn/job/basic/TimeoutSchedulerExecutor.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class TimeoutSchedulerExecutor {
1818

1919
private static Logger log = LoggerFactory.getLogger(TimeoutSchedulerExecutor.class);
2020

21-
private static ConcurrentHashMap<String, ScheduledThreadPoolExecutor> scheduledThreadPoolExecutorMap = new ConcurrentHashMap<>();
21+
private static ConcurrentHashMap<String, ScheduledThreadPoolExecutor> scheduledThreadPoolExecutorMap =
22+
new ConcurrentHashMap<>();
2223

2324
private TimeoutSchedulerExecutor() {
2425

@@ -71,7 +72,8 @@ public void run() {
7172
if (!shardingItemFutureTask.isDone() && javaShardingItemCallable.setTimeout()) {
7273
String jobName = javaShardingItemCallable.getJobName();
7374
Integer item = javaShardingItemCallable.getItem();
74-
log.info("[{}] msg=Force stop timeout job, jobName:{}, item:{}", jobName, jobName, item);
75+
LogUtils.info(log, jobName, "[{}] msg=Force stop timeout job, jobName:{}, item:{}", jobName,
76+
jobName, item);
7577
// 调用beforeTimeout函数
7678
javaShardingItemCallable.beforeTimeout();
7779
// 强杀

saturn-core/src/main/java/com/vip/saturn/job/internal/config/ConfigurationListenerManager.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.vip.saturn.job.internal.listener.AbstractJobListener;
2222
import com.vip.saturn.job.internal.listener.AbstractListenerManager;
2323
import com.vip.saturn.job.internal.storage.JobNodePath;
24+
import com.vip.saturn.job.utils.LogUtils;
2425
import org.apache.curator.framework.CuratorFramework;
2526
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
2627
import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
@@ -79,7 +80,7 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
7980
}
8081
if (ConfigurationNode.isEnabledPath(jobName, path) && Type.NODE_UPDATED == event.getType()) {
8182
Boolean isJobEnabled = Boolean.valueOf(new String(event.getData().getData()));
82-
log.info("[{}] msg={} 's enabled change to {}", jobName, jobName, isJobEnabled);
83+
LogUtils.info(log, jobName, "[{}] msg={} 's enabled change to {}", jobName, jobName, isJobEnabled);
8384
jobConfiguration.reloadConfig();
8485
if (isJobEnabled) {
8586
if (!isJobNotNull()) {
@@ -120,7 +121,7 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
120121
return;
121122
}
122123
if (ConfigurationNode.isCronPath(jobName, path) && Type.NODE_UPDATED == event.getType()) {
123-
log.info("[{}] msg={} 's cron update", jobName, jobName);
124+
LogUtils.info(log, jobName, "[{}] msg={} 's cron update", jobName, jobName);
124125

125126
String cronFromZk = jobConfiguration.getCronFromZk();
126127
if (!jobScheduler.getPreviousConf().getCron().equals(cronFromZk)) {

saturn-core/src/main/java/com/vip/saturn/job/internal/config/ConfigurationService.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.vip.saturn.job.sharding.node.SaturnExecutorsNode;
2424
import com.vip.saturn.job.threads.SaturnThreadFactory;
2525
import com.vip.saturn.job.utils.JsonUtils;
26+
import com.vip.saturn.job.utils.LogEvents;
27+
import com.vip.saturn.job.utils.LogUtils;
2628
import org.apache.commons.lang3.StringUtils;
2729
import org.codehaus.jackson.map.type.MapType;
2830
import org.codehaus.jackson.map.type.TypeFactory;
@@ -97,7 +99,7 @@ public void run() {
9799
try {
98100
jobScheduler.getJob().notifyJobEnabled();
99101
} catch (Throwable t) {
100-
LOGGER.error(t.getMessage(), t);
102+
LogUtils.error(LOGGER, LogEvents.ExecutorEvent.COMMON, t.getMessage(), t);
101103
}
102104
}
103105
});
@@ -110,7 +112,7 @@ public void run() {
110112
try {
111113
jobScheduler.getJob().notifyJobDisabled();
112114
} catch (Throwable t) {
113-
LOGGER.error(t.getMessage(), t);
115+
LogUtils.error(LOGGER, LogEvents.ExecutorEvent.COMMON, t.getMessage(), t);
114116
}
115117
}
116118
});
@@ -181,7 +183,9 @@ public Map<Integer, String> getShardingItemParameters() {
181183
try {
182184
result.put(Integer.valueOf(item), exec);
183185
} catch (final NumberFormatException ex) {
184-
LOGGER.warn("Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex);
186+
LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON,
187+
"Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped",
188+
item, item, ex);
185189
}
186190
}
187191
}

saturn-core/src/main/java/com/vip/saturn/job/internal/control/ControlListenerManager.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
1010
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
* specific language governing permissions and limitations under the License.
@@ -14,6 +14,7 @@
1414

1515
package com.vip.saturn.job.internal.control;
1616

17+
import com.vip.saturn.job.utils.LogUtils;
1718
import org.apache.curator.framework.CuratorFramework;
1819
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
1920
import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
@@ -60,9 +61,10 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
6061
if (isShutdown) {
6162
return;
6263
}
63-
if (ControlNode.isReportPath(jobName, path)
64-
&& (Type.NODE_UPDATED == event.getType() || Type.NODE_ADDED == event.getType())) {
65-
log.info("[{}] msg={} received report event from console, start to flush data to zk.", jobName,
64+
if (ControlNode.isReportPath(jobName, path) && (Type.NODE_UPDATED == event.getType()
65+
|| Type.NODE_ADDED == event.getType())) {
66+
LogUtils.info(log, jobName,
67+
"[{}] msg={} received report event from console, start to flush data to zk.", jobName,
6668
jobName);
6769
reportService.reportData2Zk();
6870
}

saturn-core/src/main/java/com/vip/saturn/job/internal/control/ReportService.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
1010
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
* specific language governing permissions and limitations under the License.
@@ -20,6 +20,8 @@
2020
import java.util.Map;
2121
import java.util.Map.Entry;
2222

23+
import com.vip.saturn.job.utils.LogEvents;
24+
import com.vip.saturn.job.utils.LogUtils;
2325
import org.slf4j.Logger;
2426
import org.slf4j.LoggerFactory;
2527

@@ -51,28 +53,28 @@ public void reportData2Zk() {
5153
Integer item = next.getKey();
5254
ExecutionInfo info = next.getValue();
5355
if (!shardingItems.contains(item)) {
54-
log.info(
55-
"sharding items don't have such item: {}, reporter is going to ignore this executionInfo: {}",
56-
item, info);
56+
LogUtils.info(log, LogEvents.ExecutorEvent.COMMON,
57+
"sharding items don't have such item: {}, reporter is going to ignore this "
58+
+ "executionInfo: {}", item, info);
5759
continue;
5860
}
5961
if (info.getLastBeginTime() != null) {
60-
jobScheduler.getJobNodeStorage().replaceJobNode(ExecutionNode.getLastBeginTimeNode(item),
61-
info.getLastBeginTime());
62+
jobScheduler.getJobNodeStorage()
63+
.replaceJobNode(ExecutionNode.getLastBeginTimeNode(item), info.getLastBeginTime());
6264
}
6365
if (info.getLastCompleteTime() != null) {
6466
jobScheduler.getJobNodeStorage().replaceJobNode(ExecutionNode.getLastCompleteTimeNode(item),
6567
info.getLastCompleteTime());
6668
}
6769
if (info.getNextFireTime() != null) {
68-
jobScheduler.getJobNodeStorage().replaceJobNode(ExecutionNode.getNextFireTimeNode(item),
69-
info.getNextFireTime());
70+
jobScheduler.getJobNodeStorage()
71+
.replaceJobNode(ExecutionNode.getNextFireTimeNode(item), info.getNextFireTime());
7072
}
7173
jobScheduler.getJobNodeStorage().replaceJobNode(ExecutionNode.getJobLog(item),
7274
(info.getJobLog() == null ? "" : info.getJobLog()));
7375
jobScheduler.getJobNodeStorage().replaceJobNode(ExecutionNode.getJobMsg(item),
7476
(info.getJobMsg() == null ? "" : info.getJobMsg()));
75-
log.info("done flushed {} to zk.", info);
77+
LogUtils.info(log, LogEvents.ExecutorEvent.COMMON, "done flushed {} to zk.", info);
7678
}
7779
infoMap.clear();
7880
}

saturn-core/src/main/java/com/vip/saturn/job/internal/election/ElectionListenerManager.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package com.vip.saturn.job.internal.election;
1313

14+
import com.vip.saturn.job.utils.LogUtils;
1415
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
@@ -58,20 +59,22 @@ public void nodeChanged() throws Exception {
5859
@Override
5960
public void run() {
6061
try {
61-
log.debug("[{}] msg=Leader host nodeChanged", jobName);
62+
LogUtils.debug(log, jobName, "[{}] msg=Leader host nodeChanged", jobName);
6263
if (isShutdown) {
63-
log.debug("[{}] msg=ElectionListenerManager has been shutdown", jobName);
64+
LogUtils.debug(log, jobName, "[{}] msg=ElectionListenerManager has been shutdown",
65+
jobName);
6466
return;
6567
}
6668
if (!leaderElectionService.hasLeader()) {
67-
log.info("[{}] msg=Leader crashed, elect a new leader now", jobName);
69+
LogUtils.info(log, jobName, "[{}] msg=Leader crashed, elect a new leader now", jobName);
6870
leaderElectionService.leaderElection();
69-
log.info("[{}] msg=Leader election completed", jobName);
71+
LogUtils.info(log, jobName, "[{}] msg=Leader election completed", jobName);
7072
} else {
71-
log.debug("[{}] msg=Leader is already existing, unnecessary to election", jobName);
73+
LogUtils.debug(log, jobName,
74+
"[{}] msg=Leader is already existing, unnecessary to " + "election", jobName);
7275
}
7376
} catch (Throwable t) {
74-
log.error(t.getMessage(), t);
77+
LogUtils.error(log, jobName, t.getMessage(), t);
7578
}
7679
}
7780
});

saturn-core/src/main/java/com/vip/saturn/job/internal/election/LeaderElectionService.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
1010
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
* specific language governing permissions and limitations under the License.
@@ -17,6 +17,7 @@
1717
import java.util.concurrent.atomic.AtomicBoolean;
1818

1919
import com.vip.saturn.job.internal.storage.JobNodeStorage;
20+
import com.vip.saturn.job.utils.LogUtils;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -26,8 +27,8 @@
2627

2728
/**
2829
* 选举主节点的服务.
29-
*
30-
*
30+
*
31+
*
3132
*/
3233
public class LeaderElectionService extends AbstractSaturnService {
3334
static Logger log = LoggerFactory.getLogger(LeaderElectionService.class);
@@ -44,13 +45,14 @@ public void shutdown() {
4445
if (isShutdown.compareAndSet(false, true)) {
4546
try { // Release my leader position
4647
JobNodeStorage jobNodeStorage = getJobNodeStorage();
47-
if (jobNodeStorage.isConnected()
48-
&& executorName.equals(jobNodeStorage.getJobNodeDataDirectly(ElectionNode.LEADER_HOST))) {
48+
if (jobNodeStorage.isConnected() && executorName
49+
.equals(jobNodeStorage.getJobNodeDataDirectly(ElectionNode.LEADER_HOST))) {
4950
jobNodeStorage.removeJobNodeIfExisted(ElectionNode.LEADER_HOST);
50-
log.info("[{}] msg={} that was {}'s leader, released itself", jobName, executorName, jobName);
51+
LogUtils.info(log, jobName, "[{}] msg={} that was {}'s leader, released itself", jobName,
52+
executorName, jobName);
5153
}
5254
} catch (Throwable t) {
53-
log.error(t.getMessage(), t);
55+
LogUtils.error(log, jobName, t.getMessage(), t);
5456
}
5557
}
5658
}
@@ -70,15 +72,15 @@ public void leaderElection() {
7072
*/
7173
public Boolean isLeader() {
7274
while (!isShutdown.get() && !hasLeader()) {
73-
log.info("[{}] msg=No leader, try to election", jobName);
75+
LogUtils.info(log, jobName, "[{}] msg=No leader, try to election", jobName);
7476
leaderElection();
7577
}
7678
return executorName.equals(getJobNodeStorage().getJobNodeDataDirectly(ElectionNode.LEADER_HOST));
7779
}
7880

7981
/**
8082
* 判断是否已经有主节点
81-
*
83+
*
8284
* @return 是否已经有主节点
8385
*/
8486
public boolean hasLeader() {
@@ -95,7 +97,8 @@ public void execute() {
9597
}
9698
if (!getJobNodeStorage().isJobNodeExisted(ElectionNode.LEADER_HOST)) {
9799
getJobNodeStorage().fillEphemeralJobNode(ElectionNode.LEADER_HOST, executorName);
98-
log.info("[{}] msg=executor {} become job {}'s leader", jobName, executorName, jobName);
100+
LogUtils.info(log, jobName, "[{}] msg=executor {} become job {}'s leader", jobName, executorName,
101+
jobName);
99102
}
100103
}
101104
}

0 commit comments

Comments
 (0)