Skip to content

Commit 484bad9

Browse files
committed
#509 修改日志格式
1 parent 188c0a9 commit 484bad9

14 files changed

+51
-74
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ public final void execute() {
154154
LogUtils.debug(log, jobName, "Saturn finish to execute job [{}], sharding context:{}.", jobName,
155155
shardingContext);
156156
} catch (Exception e) {
157-
LogUtils.warn(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
158-
e);
157+
LogUtils.warn(log, jobName, e.getMessage(), e);
159158
} finally {
160159
running = false;
161160
}
@@ -207,8 +206,7 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {
207206
if (ephemeralOwner != sessionId) {
208207
LogUtils.info(log, jobName,
209208
"item={} 's running node doesn't belong to current zk, node sessionid is {}, current zk "
210-
+ "sessionid is {}",
211-
item, ephemeralOwner, sessionId);
209+
+ "sessionid is {}", item, ephemeralOwner, sessionId);
212210
return false;
213211
} else {
214212
return true;
@@ -219,7 +217,7 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {
219217

220218
return false;
221219
} catch (Throwable e) {
222-
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
220+
LogUtils.error(log, jobName, e.getMessage(), e);
223221
return false;
224222
}
225223
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public Properties parseKV(String path) {
130130
if (tmps != null && tmps.length == 2) {
131131
kv.put(tmps[0].trim(), tmps[1].trim());
132132
} else {
133-
LogUtils.warn(log, jobName, "msg=Param is not valid {}", p);
133+
LogUtils.warn(log, jobName, "Param is not valid {}", p);
134134
}
135135
}
136136
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public void run() {
7272
if (!shardingItemFutureTask.isDone() && javaShardingItemCallable.setTimeout()) {
7373
String jobName = javaShardingItemCallable.getJobName();
7474
Integer item = javaShardingItemCallable.getItem();
75-
LogUtils.info(log, jobName, "[{}] msg=Force stop timeout job, jobName:{}, item:{}", jobName,
76-
jobName, item);
75+
LogUtils.info(log, jobName, "Force stop timeout job, jobName:{}, item:{}", jobName, item);
7776
// 调用beforeTimeout函数
7877
javaShardingItemCallable.beforeTimeout();
7978
// 强杀

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
8080
}
8181
if (ConfigurationNode.isEnabledPath(jobName, path) && Type.NODE_UPDATED == event.getType()) {
8282
Boolean isJobEnabled = Boolean.valueOf(new String(event.getData().getData()));
83-
LogUtils.info(log, jobName, "[{}] msg={} 's enabled change to {}", jobName, jobName, isJobEnabled);
83+
LogUtils.info(log, jobName, "{} 's enabled change to {}", jobName, isJobEnabled);
8484
jobConfiguration.reloadConfig();
8585
if (isJobEnabled) {
8686
if (!isJobNotNull()) {
@@ -121,7 +121,7 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
121121
return;
122122
}
123123
if (ConfigurationNode.isCronPath(jobName, path) && Type.NODE_UPDATED == event.getType()) {
124-
LogUtils.info(log, jobName, "[{}] msg={} 's cron update", jobName, jobName);
124+
LogUtils.info(log, jobName, "{} 's cron update", jobName);
125125

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

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String
6363
}
6464
if (ControlNode.isReportPath(jobName, path) && (Type.NODE_UPDATED == event.getType()
6565
|| Type.NODE_ADDED == event.getType())) {
66-
LogUtils.info(log, jobName,
67-
"[{}] msg={} received report event from console, start to flush data to zk.", jobName,
66+
LogUtils.info(log, jobName, "{} received report event from console, start to flush data to zk.",
6867
jobName);
6968
reportService.reportData2Zk();
7069
}

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ public void nodeChanged() throws Exception {
5959
@Override
6060
public void run() {
6161
try {
62-
LogUtils.debug(log, jobName, "[{}] msg=Leader host nodeChanged", jobName);
62+
LogUtils.debug(log, jobName, "Leader host nodeChanged", jobName);
6363
if (isShutdown) {
64-
LogUtils.debug(log, jobName, "[{}] msg=ElectionListenerManager has been shutdown",
65-
jobName);
64+
LogUtils.debug(log, jobName, "ElectionListenerManager has been shutdown", jobName);
6665
return;
6766
}
6867
if (!leaderElectionService.hasLeader()) {
69-
LogUtils.info(log, jobName, "[{}] msg=Leader crashed, elect a new leader now", jobName);
68+
LogUtils.info(log, jobName, "Leader crashed, elect a new leader now");
7069
leaderElectionService.leaderElection();
71-
LogUtils.info(log, jobName, "[{}] msg=Leader election completed", jobName);
70+
LogUtils.info(log, jobName, "Leader election completed");
7271
} else {
73-
LogUtils.debug(log, jobName,
74-
"[{}] msg=Leader is already existing, unnecessary to " + "election", jobName);
72+
LogUtils.debug(log, jobName, "Leader is already existing, unnecessary to " + "election");
7573
}
7674
} catch (Throwable t) {
7775
LogUtils.error(log, jobName, t.getMessage(), t);

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public void shutdown() {
4848
if (jobNodeStorage.isConnected() && executorName
4949
.equals(jobNodeStorage.getJobNodeDataDirectly(ElectionNode.LEADER_HOST))) {
5050
jobNodeStorage.removeJobNodeIfExisted(ElectionNode.LEADER_HOST);
51-
LogUtils.info(log, jobName, "[{}] msg={} that was {}'s leader, released itself", jobName,
52-
executorName, jobName);
51+
LogUtils.info(log, jobName, "{} that was {}'s leader, released itself", executorName, jobName);
5352
}
5453
} catch (Throwable t) {
5554
LogUtils.error(log, jobName, t.getMessage(), t);
@@ -72,7 +71,7 @@ public void leaderElection() {
7271
*/
7372
public Boolean isLeader() {
7473
while (!isShutdown.get() && !hasLeader()) {
75-
LogUtils.info(log, jobName, "[{}] msg=No leader, try to election", jobName);
74+
LogUtils.info(log, jobName, "No leader, try to election");
7675
leaderElection();
7776
}
7877
return executorName.equals(getJobNodeStorage().getJobNodeDataDirectly(ElectionNode.LEADER_HOST));
@@ -97,8 +96,7 @@ public void execute() {
9796
}
9897
if (!getJobNodeStorage().isJobNodeExisted(ElectionNode.LEADER_HOST)) {
9998
getJobNodeStorage().fillEphemeralJobNode(ElectionNode.LEADER_HOST, executorName);
100-
LogUtils.info(log, jobName, "[{}] msg=executor {} become job {}'s leader", jobName, executorName,
101-
jobName);
99+
LogUtils.info(log, jobName, "executor {} become job {}'s leader", executorName, jobName);
102100
}
103101
}
104102
}

saturn-core/src/main/java/com/vip/saturn/job/internal/failover/FailoverService.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ public void execute() {
168168
if (items != null && !items.isEmpty()) {
169169
int crashedItem = Integer
170170
.parseInt(getJobNodeStorage().getJobNodeChildrenKeys(FailoverNode.ITEMS_ROOT).get(0));
171-
LogUtils.debug(log, jobName, "[{}] msg=Elastic job: failover job begin, crashed item:{}.", jobName,
172-
crashedItem);
171+
LogUtils.debug(log, jobName, "Elastic job: failover job begin, crashed item:{}.", crashedItem);
173172
getJobNodeStorage()
174173
.fillEphemeralJobNode(FailoverNode.getExecutionFailoverNode(crashedItem), executorName);
175174
getJobNodeStorage().removeJobNodeIfExisted(FailoverNode.getItemsNode(crashedItem));

saturn-core/src/main/java/com/vip/saturn/job/internal/sharding/ShardingListenerManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void run() {
130130
if (jobScheduler == null || jobScheduler.getJob() == null) {
131131
return;
132132
}
133-
LogUtils.info(log, jobName, "[{}] msg={} trigger on-resharding", jobName, jobName);
133+
LogUtils.info(log, jobName, "{} trigger on-resharding", jobName);
134134
jobScheduler.getJob().onResharding();
135135
} catch (Throwable t) {
136136
LogUtils.error(log, jobName, "Exception throws during resharding", t);

saturn-core/src/main/java/com/vip/saturn/job/internal/sharding/ShardingService.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,31 @@ public synchronized void shardingIfNecessary() throws JobShuttingDownException {
172172
SHARDING_UN_NECESSARY.getBytes(StandardCharsets.UTF_8)).and();
173173
curatorTransactionFinal.commit();
174174
} catch (BadVersionException e) {
175-
LogUtils.warn(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName,
176-
"zookeeper bad version exception happens."), e);
175+
LogUtils.warn(log, jobName, "zookeeper bad version exception happens.", e);
177176
needRetry = true;
178177
retryCount--;
179178
} catch (Exception e) {
180179
// 可能多个sharding task导致计算结果有滞后,但是server机器已经被删除,导致commit失败
181180
// 实际上可能不影响最终结果,仍然能正常分配分片,因为还会有resharding事件被响应
182181
// 修改日志级别为warn级别,避免不必要的告警
183-
LogUtils.warn(log, jobName,
184-
String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, "Commit shards failed"), e);
182+
LogUtils.warn(log, jobName, "Commit shards failed", e);
185183
}
186184
if (needRetry) {
187185
if (retryCount >= 0) {
188-
LogUtils.info(log, jobName, SaturnConstant.LOG_FORMAT, jobName,
186+
LogUtils.info(log, jobName,
189187
"Bad version because of concurrency, will retry to get shards later");
190188
Thread.sleep(200L); // NOSONAR
191189
getDataStat = getNecessaryDataStat();
192190
} else {
193-
LogUtils.warn(log, jobName, SaturnConstant.LOG_FORMAT, jobName,
194-
"Bad version because of concurrency, give up to retry");
191+
LogUtils.warn(log, jobName, "Bad version because of concurrency, give up to retry");
195192
break;
196193
}
197194
} else {
198195
break;
199196
}
200197
}
201198
} catch (Exception e) {
202-
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
203-
e);
199+
LogUtils.error(log, jobName, e.getMessage(), e);
204200
} finally {
205201
getJobNodeStorage().removeJobNodeIfExisted(ShardingNode.PROCESSING);
206202
}
@@ -222,14 +218,14 @@ private boolean blockUntilShardingComplatedIfNotLeader() throws JobShuttingDownE
222218
if (!(isNeedSharding() || getJobNodeStorage().isJobNodeExisted(ShardingNode.PROCESSING))) {
223219
return true;
224220
}
225-
LogUtils.debug(log, jobName, "[{}] msg=Sleep short time until sharding completed", jobName);
221+
LogUtils.debug(log, jobName, "Sleep short time until sharding completed");
226222
BlockUtils.waitingShortTime();
227223
}
228224
}
229225

230226
private void waitingOtherJobCompleted() {
231227
while (!isShutdown && executionService.hasRunningItems()) {
232-
LogUtils.info(log, jobName, "[{}] msg=Sleep short time until other job completed.", jobName);
228+
LogUtils.info(log, jobName, "Sleep short time until other job completed.");
233229
BlockUtils.waitingShortTime();
234230
}
235231
}

saturn-core/src/main/java/com/vip/saturn/job/internal/statistics/ProcessCountResetTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void run() {
5252
// 清零zk统计值
5353
jobScheduler.getServerService().persistProcessFailureCount(0);
5454
jobScheduler.getServerService().persistProcessSuccessCount(0);
55-
LogUtils.error(log, jobName, "msg={} reset the job {}'s statistics data", executorName, jobName);
55+
LogUtils.error(log, jobName, "{} reset the job {}'s statistics data", executorName, jobName);
5656
}
5757
}
5858
} catch (Throwable t) {

saturn-core/src/main/java/com/vip/saturn/job/internal/statistics/StatisticsService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ public synchronized void startProcessCountJob() {
8282
if (processCountJobFuture != null) {
8383
processCountJobFuture.cancel(true);
8484
LogUtils.info(log, jobName,
85-
"[{}] msg=Reschedule ProcessCountJob of the {} job, the processCountIntervalSeconds is {}",
86-
jobName, jobConfiguration.getJobName(), processCountIntervalSeconds);
85+
"Reschedule ProcessCountJob of the {} job, the processCountIntervalSeconds is {}",
86+
jobConfiguration.getJobName(), processCountIntervalSeconds);
8787
}
8888
processCountJobFuture = processCountExecutor
8989
.scheduleAtFixedRate(new ProcessCountJob(jobScheduler), new Random().nextInt(10),
9090
processCountIntervalSeconds, TimeUnit.SECONDS);
9191

9292
} else { // don't count, reset to zero.
9393
if (processCountJobFuture != null) {
94-
LogUtils.info(log, jobName, "[{}] msg=shutdown the task of reporting statistics data");
94+
LogUtils.info(log, jobName, "shutdown the task of reporting statistics data");
9595
processCountJobFuture.cancel(true);
9696
processCountJobFuture = null;
9797
}

saturn-core/src/main/java/com/vip/saturn/job/internal/storage/JobNodeStorage.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void removeJobNode(final String node) {
174174
*/
175175
public void fillJobNodeIfNullOrOverwrite(final String node, final Object value) {
176176
if (null == value) {
177-
LogUtils.info(log, jobName, "[{}] msg=job node value is null, node:{}", jobName, node);
177+
LogUtils.info(log, jobName, "job node value is null, node:{}", node);
178178
return;
179179
}
180180
if (!isJobNodeExisted(node) || (!value.toString().equals(getJobNodeDataDirectly(node)))) {
@@ -269,8 +269,7 @@ public void executeInLeader(final String latchNode, final LeaderExecutionCallbac
269269
callback.execute();
270270
// CHECKSTYLE:OFF
271271
} catch (final Exception e) {
272-
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
273-
e);
272+
LogUtils.error(log, jobName, e.getMessage(), e);
274273
// CHECKSTYLE:ON
275274
if (e instanceof InterruptedException) {// NOSONAR
276275
Thread.currentThread().interrupt();
@@ -294,8 +293,7 @@ public void executeInLeader(final String latchNode, final LeaderExecutionCallbac
294293
}
295294
// CHECKSTYLE:OFF
296295
} catch (final Exception e) {
297-
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
298-
e);
296+
LogUtils.error(log, jobName, e.getMessage(), e);
299297
// CHECKSTYLE:ON
300298
if (e instanceof InterruptedException) {// NOSONAR
301299
Thread.currentThread().interrupt();
@@ -352,8 +350,7 @@ private boolean tryToRemoveNode(ZookeeperRegistryCenter newZk, String fullPath)
352350
newZk.remove(fullPath);
353351
return true;
354352
} catch (Exception e) {
355-
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
356-
e);
353+
LogUtils.error(log, jobName, e.getMessage(), e);
357354
}
358355
return false;
359356
}

0 commit comments

Comments
 (0)