Skip to main content
5-Regular Member
November 5, 2019
Question

Writing to ThingWorx logs via REST API

  • November 5, 2019
  • 6 replies
  • 2545 views

Hi everyone,

 

ThingWorx provides the capability to write arbitrary messages to log entities (e.g. CommunicationLog, ApplicationLog, ScriptLog, etc.) using the REST API.

 

As we prepare for the rollout of the next version of ThingWorx, we would like to understand if anyone is actually using the REST API to write to logs.

 

If so, how are you using it?

 

If not, we are considering removing this capability in order to focus on providing and maintaining other great functionality.

 

Thanks for your feedback.

6 replies

11-Garnet
November 6, 2019

Hi,
you could solve this by implementing an extension. Define your own Shape with some services. Within these services you can address your required logger.

 

Logger APP_LOGGER = LogUtilities.getInstance().getApplicationLogger("sublogger-name");
Logger CONFIG_LOGGER = LogUtilities.getInstance().getConfigurationLogger("sublogger-name");

 

Create a thing, add your shape. Now can use this thing via REST to report into specific logger.

11-Garnet
November 6, 2019
This may help: import attached extension.
Create a thing name 'MyLogger' using shape 'IF.LoggerShape'.
LoggerThing.png
Now you can try directly from Javascript:
 
Things['MyLogger'].ApplicationInfoLog({
logger: "Foo" /* STRING */,
message: "Hello" /* STRING */
});
Our via REST: you need to adjust hostname (and thing-name).
http://hostname:8080/Thingworx/Things/MyLogger/Services/ApplicationInfoLog
POST body like:
{
"logger"": "Foo"
"message"": "Hello via REST"
}

 

LoggerSOAPUI.png

 

Result should be like this:

LoggerOutput.png

 

Regards,

Marcus

19-Tanzanite
November 8, 2019

Hi Walter, what is the API you're referring to?

 

 

19-Tanzanite
November 11, 2019

In addition to my question, here's the reason why I ask.

1. From an "I want to write to a log" usecase, the preferred way is to use in the ThingWorx services a "logger.warn" statement (or similar), which is usually used to debug service functionality. Since ThingWorx is REST capable OOTM, this will also result in an user's capability to call a service via REST to be capable to write in any of the logs, indirectly

 

In addition to the snippet above, each of the logs, have a service, called 

Logs["ApplicationLog"].Write({    level: undefined /* STRING */,    origin: undefined /* STRING */,    message: undefined /* STRING */});

That would allow direct writing to the any of the logs.

 

Even if we stop supporting the direct route, the user would still be capable to write to the logs, indirectly.

 

 

18-Opal
November 10, 2019

Hello @Walter_Haydock,

 

I've never seen it used on any project. The opposite use case (i.e. streaming ThingWorx logs into external systems) would make more sense IMHO.

 

/ Constantine

19-Tanzanite
November 11, 2019

I support Constantine's feedback.

I remember lots of RFPs' that asked us to prove "we can output/send logs to a central logging system" (eg: Cigna).

That was/is a problem, since in the product we don't have an event that would allow us to intercept the message and call an external API. We always would need to resort to workarounds, which are not so nice in some cases.