stepfunc / rodbus

Rust implementation of Modbus with idiomatic bindings for C, C++, .NET, and Java
https://stepfunc.io/products/libraries/modbus/
Other
83 stars 23 forks source link

Invalid JSON Log Formatting #130

Closed xlukem closed 8 months ago

xlukem commented 8 months ago

I have enabled the JSON formatting in the rodbus log configuration to extract specific log data and log it with the spdlog library.

I have trouble extracting the IP and Port from this specific log, because the JSON is invalid.

Also, do you have documentation on the general JSON format used in the rodbus lib? Which data field are always used/ which ones only on server / client log etc..

Thank you very much!

{
    "fields": {
        "message": "channel enabled"
    },
    "span": {
        "endpoint": "HostAddr { addr: IpAddr(192.168.1.2), port: 502 }",
        "name": "Modbus-Client-TCP"
    },
    "spans": [
        {
            "endpoint": "HostAddr { addr: IpAddr(192.168.1.2), port: 502 }",
            "name": "Modbus-Client-TCP"
        }
    ]
}
jadamcrain commented 8 months ago

Hi @xlukem. The JSON output is controlled by the tracing-subscriber dependency. You can read about the format here.

The envelope you posted is valid JSON. I believe you're referring to the fact that some of the strings contained within the JSON are not JSON, e.g.:

"HostAddr { addr: IpAddr(192.168.1.2), port: 502 }"

The string above is Rust's debug representation of struct. It is not intended to be JSON, it's just a string.

Any of the text inside of a log message should not be relied upon as a stable feature. It's subject to change even between patch releases of library.

If there's some gap in the API that's forcing you to resort to parsing log messages to do something, please let me know and we can see if it can be added to the stable API.