traccar-server.log Verbosity

loloski8 years ago

Hi Guys,

Is there any documented settings that will log not only the basic data like lon,lat and speed but the other IO attribute as well just like what have shown in the traccar-web portal.

The reason for this is i'm basically feeding the log to elastic search for visualizing purposes.

Current:

[8283EADD] id: 862462033517011, time: 2017-02-20 12:40:54, lat: 14.42907, lon: 121.02772, speed: 0.0, course: 165.3

Expected:

[8283EADD] id: 862462033517011, time: 2017-02-20 12:40:54, lat: 14.42907, lon: 121.02772, speed: 0.0, course: 165.3 io03: 1, io27:34
loloski8 years ago

I try to read the source, but can't see the obvious I try to look on the helper class
/traccar/src/org/traccar/helper/Log.java it's not there and a couple of various places. can anyone shed somelight on this thanks!

loloski8 years ago
            StringBuilder s = new StringBuilder();
            s.append(formatChannel(e.getChannel())).append(" ");
            s.append("id: ").append(uniqueId).append(", ");
            s.append("time: ").append(
                    new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime())).append(", ");
            s.append("lat: ").append(String.format("%.5f", position.getLatitude())).append(", ");
            s.append("lon: ").append(String.format("%.5f", position.getLongitude())).append(", ");
            s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", ");
            s.append("course: ").append(String.format("%.1f", position.getCourse()));
            Object cmdResult = position.getAttributes().get(Position.KEY_RESULT);
            if (cmdResult != null) {
                s.append(", result: ").append(cmdResult);
            }
            Log.info(s.toString());

Ok after digging the codebase even further I see it was on MainEventHandler.java the problem is Position model they way it designed is not returning this extra Input/Output sensor from device sure it was stored on the DB

The question is how can I bring this extra data Inputs as part of the String builder code above, thanks in advance

Anton Tananaev8 years ago

All addition parameters, like input/output, are store in the attributes, co you can get them using "getAttributes()" method. See the command result for an example.

loloski8 years ago

Hi Anton,

Thanks for a speedy reply, I try a code below it build's perfectly but I don't know if I understood you correctly :)

            Object cmdIo = position.getAttributes().get(Position.KEY_INPUT);
            if (cmdIo != null) {
                s.append(", input: ").append(cmdIo);
            }
Anton Tananaev8 years ago

Well, the key that you are using should match the one you want to print out.

loloski8 years ago

Hi Anton,

I try all keys available from Position model to no avail it's always null I believed, I even try KEY_ORIGINAL just to make it sure it was not null but still no output from traccar-server.log

I'm sorry if I can't really find this trivial thing :)

Anton Tananaev8 years ago

From your first example, it seems like the keys you should be using are "io03" and "io27".

loloski8 years ago

Hi Anton,

It's working now, thanks from your help much appreciate it :)