Generate Customized Log files for ODK Briefcase 1.13


(paul macharia) #1

Hello ODKers,

What is the problem? Please be detailed.

I need to generate log files for all the pull and export activities. I run scheduled pull and export from Aggregate every day. With ODK Briefcase 1.7 I could have ">C:\ODK\Logs/Export_Form_XYZ_%date:~10,4%%date:~4,2%%date:~7,2%.log 2>&1;" and ">C:\ODK\Logs/Pull_Form_XYZ_%date:~10,4%%date:~4,2%%date:~7,2%.log 2>&1;" for and export and it worked fine.

When I run the pull and export scheduled tasks, I don't see the briefcase.log file anywhere.

What ODK tool and version are you using? And on what device and operating system version?

I am using ODK Briefcase 1.13 running on a Windows 10 Machine

I have scheduled Pull and Export 7 Forms everyday. I would like to have a log file for each Form. If is not possible, then let me know where the Briefcase.log is stored so that I am able to review and backup.

Asante
Paul Macharia


(Kkrawczyk123) #2

Hi!
Unfortunately, I don't know how to obtain a separate log file for each operation, others might help with that, but I know how to obtain overall briefcase.log file. You can use an instruction form https://github.com/opendatakit/briefcase#logging after that log file will be created in your briefcase folder.


(paul macharia) #3

Thanks kkrawczyk123,

However, I have tired out this without success. How far do I need to customize the logback.xml file?

Paul


(Kkrawczyk123) #4

I think that copy the content of res/logback.xml.example file to to res/logback.xml should be enough.


(paul macharia) #5

ODK Team,

Anyone with an idea of how to generate customized log files?

Asante,
Paul Macharia


(Yaw Anokwa) #6

@paul_macharia When you said you tried the instructions at https://github.com/opendatakit/briefcase#logging, what exactly did you try.?


(paul macharia) #7

Yaw,

I went to https://docs.opendatakit.org/briefcase-using/#cli-use and on the

"How to use a custom log configuration"

I created the logback.xml and saved at the same storage with the bat script. I added "$ java -Dlogging.config="{path/to/logback.xml}" to bat script.

I don't see any generated log file when I run the batch file.

Asante,
Paul Macharia


(Yaw Anokwa) #8

Just a guess here, but is there a log in the location where you are running the script from (not the location of the briefcase.jar)?


(paul macharia) #9

Yaw,

When I run the batch file directly (execute the file from its location) a log file is saved on this location. When the batch file runs a part of a scheduled task, no log file is generated.

Asante,
Paul Macharia


(Guillermo) #10

Hi @paul_macharia!

I'm sorry for taking so much time for answering your question! This is kind of complex and takes some time to explain.

Briefcase uses SLF4J and Logback for logging, and it's shipped with a default logging configuration that will leave a briefcase.log file wherever you launch Briefcase. It does some other stuff like rotating the log file once a day, but that's not important.

I see that you've already tried to change the logging configuration by providing a different configuration file with the -Dlogging.config=/path/to/config/file.xml JVM flag, which is great. It would help me to know the contents of the logback.xml file you've created.

This is the standard configuration file that's bundled with Briefcase:

<configuration>
  <appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>briefcase.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>briefcase.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
      <totalSizeCap>100MB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="ROLLINGFILE" />
  </root>
</configuration>

As you can see, the <appender name="STDOUT" .../> doesn't say where the log file should be saved (it only defined the filename). This is done by design to get the log file at the same path where you run the java -jar briefcase.jar command.

If you want Briefcase to leave the log file at some specific, fixed path, you would need to change the appender.rollingPolicy.fileNamePattern value:

<configuration>
  <appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>briefcase.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>C:\some\fixed\path\briefcase.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
      <totalSizeCap>100MB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="ROLLINGFILE" />
  </root>
</configuration>

This configuration would leave the log file at C:\some\fixed\path\briefcase.log

On the other hand, if you'd prefer Briefcase to spit out log contents on the console, you could have this configuration instead:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

(paul macharia) #11

Thanks @ggalmazor!

Please let me review what I did and build on your detailed email. Will feedback soon......

Asante,
Paul Macharia