-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a worker ID definer for use in logging.
- Loading branch information
1 parent
8fea95a
commit 334dbc7
Showing
2 changed files
with
35 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/org/opentripplanner/analyst/cluster/WorkerIdDefiner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.opentripplanner.analyst.cluster; | ||
|
||
import ch.qos.logback.core.PropertyDefinerBase; | ||
|
||
/** | ||
* A class that allows the logging framework to access the worker ID; with a custom logback config | ||
* this can be used to print the machine ID with each log message. This is useful if you have multiple | ||
* workers logging to the same log aggregation service. | ||
* | ||
* This does seem like it should be a static class of AnalystWorker, but AnalystWorker needs this | ||
* class loaded to initialize its logger which is a static field, so it would have to be at the top | ||
* of the file, above the logger definition, which is ugly and confusing so we leave it as its own | ||
* bona fide class. | ||
* | ||
* It would seem that Mapped Diagnostic Contexts would be ideal for this purpose, but they are | ||
* thread-scoped, and computation takes place in multiple threads; we need this to be JVM-scoped. | ||
*/ | ||
public class WorkerIdDefiner extends PropertyDefinerBase { | ||
@Override public String getPropertyValue() { | ||
return AnalystWorker.machineId; | ||
} | ||
} |