@@ -19,19 +19,45 @@ In this example not only do the node logs output in json but we can add arbitrar
1919 logger. info(" Initializing the transaction." );
2020```
2121
22- When we log this informational message, it gets output along with the other key value pairs we've specified.
22+ When we log this informational message, it gets output along with the other key value pairs we've specified in a JSON formatt:
23+ ```
24+ {
25+ "instant": {
26+ "epochSecond": 1612982209,
27+ "nanoOfSecond": 487000000
28+ },
29+ "thread": "Node thread-1",
30+ "level": "INFO",
31+ "loggerName": "net.corda",
32+ "message": "Initializing the transaction.",
33+ "endOfBatch": true,
34+ "loggerFqcn": "org.apache.logging.slf4j.Log4jLogger",
35+ "contextMap": {
36+ "actor_id": "internalShell",
37+ "actor_owning_identity": "O=PartyA, L=London, C=GB",
38+ "actor_store_id": "NODE_CONFIG",
39+ "fiber-id": "10000001",
40+ "flow-id": "94543b19-b949-441e-9962-bc50dcd7ad55",
41+ "initiator": "O=PartyA, L=London, C=GB",
42+ "invocation_id": "a53a3a5d-b450-456e-a0f1-dfb7dcdce6dd",
43+ "invocation_timestamp": "2021-02-10T18:36:49.312Z",
44+ "origin": "internalShell",
45+ "session_id": "e8ba737e-e809-4a14-8c3b-284b7ae5ed88",
46+ "session_timestamp": "2021-02-10T18:36:49.022Z",
47+ "target": "O=PartyB, L=New York, C=US",
48+ "thread-id": "168"
49+ },
50+ "threadId": 168,
51+ "threadPriority": 5
52+ }
53+ ```
2354This can be quite powerful if you're looking to produce a consumable output stream to a log aggregator like splunk.
2455
2556You can end up getting log feeds in json that look something like this:
2657
2758``` json
2859{"instant" :{"epochSecond" :1612369055 ,"nanoOfSecond" :12000000 },"thread" :" main" ,"level" :" INFO" ,"loggerName" :" net.corda.node.internal.Node" ,"message" :" Vendor: Corda Open Source" ,"endOfBatch" :true ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :1 ,"threadPriority" :5 }
29- {"instant" :{"epochSecond" :1612369055 ,"nanoOfSecond" :12000000 },"thread" :" main" ,"level" :" INFO" ,"loggerName" :" net.corda.node.internal.Node" ,"message" :" Release: 4.6" ,"endOfBatch" :false ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :1 ,"threadPriority" :5 }
30- {"instant" :{"epochSecond" :1612369055 ,"nanoOfSecond" :12000000 },"thread" :" main" ,"level" :" INFO" ,"loggerName" :" net.corda.node.internal.Node" ,"message" :" Platform Version: 8" ,"endOfBatch" :false ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :1 ,"threadPriority" :5 }
31- {"instant" :{"epochSecond" :1612369055 ,"nanoOfSecond" :12000000 },"thread" :" main" ,"level" :" INFO" ,"loggerName" :" net.corda.node.internal.Node" ,"message" :" Revision: 85e387ea730d9be7d6dc2b23caba1ee18305af74" ,"endOfBatch" :false ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :1 ,"threadPriority" :5 }
32- {"instant" :{"epochSecond" :1612369055 ,"nanoOfSecond" :13000000 },"thread" :" main" ,"level" :" INFO" ,"loggerName" :" net.corda.node.internal.Node" ,"message" :" PID: 94369" ,"endOfBatch" :false ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :1 ,"threadPriority" :5 }
33- . . .
34-
60+ . . .More Node Startup loggings
3561
3662// when our flow is run we see the log we specified
3763{"instant" :{"epochSecond" :1612460471 ,"nanoOfSecond" :866000000 },"thread" :" pool-10-thread-2" ,"level" :" INFO" ,"loggerName" :" net.corda.tools.shell.FlowShellCommand" ,"message" :" Executing command \" flow start net.corda.samples.logging.flows.YoFlow target: PartyA\" ," ,"endOfBatch" :true ,"loggerFqcn" :" org.apache.logging.slf4j.Log4jLogger" ,"threadId" :224 ,"threadPriority" :5 }
@@ -40,58 +66,6 @@ You can end up getting log feeds in json that look something like this:
4066```
4167
4268
43- ## Concepts
44-
45- In the original yo application that this sample was based on, the app sent what is essentially a "yo" state from one node to another.
46- Here we're highlighting how easy it is to issue log messages with arbitrary key value pairs, we have an example of this in our YoFlow.
47-
48- ```java
49- public SignedTransaction call() throws FlowException {
50- // note we're creating a logger first with the shared name from our other example.
51- Logger logger = LoggerFactory.getLogger("net.corda");
52-
53- progressTracker.setCurrentStep(CREATING);
54-
55- Party me = getOurIdentity();
56-
57- // here we have our first opportunity to log out the contents of the flow arguments.
58- ThreadContext.put("initiator", me.getName().toString());
59- ThreadContext.put("target", target.getName().toString());
60- // publish to the log with the additional context
61- logger.info("Initializing the transaction.");
62- // flush the threadContext
63- ThreadContext.removeAll(Arrays.asList("initiator", "target"));
64-
65- // Obtain a reference to a notary.
66- final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
67-
68- Command<YoContract.Commands.Send> command = new Command<YoContract.Commands.Send>(new YoContract.Commands.Send(), Arrays.asList(me.getOwningKey()));
69- YoState state = new YoState(me, target);
70- StateAndContract stateAndContract = new StateAndContract(state, YoContract.ID);
71- TransactionBuilder utx = new TransactionBuilder(notary).withItems(stateAndContract, command);
72-
73- progressTracker.setCurrentStep(VERIFYING);
74- utx.verify(getServiceHub());
75-
76- progressTracker.setCurrentStep(SIGNING);
77- SignedTransaction stx = getServiceHub().signInitialTransaction(utx);
78-
79- // inject details to the threadcontext to be exported as json
80- ThreadContext.put("tx_id", stx.getId().toString());
81- ThreadContext.put("notary", notary.getName().toString());
82- // publish to the log with the additional context
83- logger.info("Finalizing the transaction.");
84- // flush the threadContext
85- ThreadContext.removeAll(Arrays.asList("tx_id", "notary"));
86-
87- progressTracker.setCurrentStep(FINALISING);
88- FlowSession targetSession = initiateFlow(target);
89- return subFlow(new FinalityFlow(stx, Arrays.asList(targetSession), Objects.requireNonNull(FINALISING.childProgressTracker())));
90- }
91- ```
92-
93-
94-
9569## Usage
9670
9771
0 commit comments