2

I have a Java program that is executed by SQL Server using SQL Server's Java language extension. The Java program logs output to a file using logback. Here's my logback.xml config:

<configuration>

  <property name="USER_HOME" value="/var/data/" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${USER_HOME}/myApp.log</file>
   <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} [%thread] - %msg%n</pattern>
    </encoder>
 </appender>

  <root level="debug">
    <appender-ref ref="FILE" />
  </root>
</configuration>

Here's a typical log setup & statement in a class:

@Slf4j // using lombok
public class MyApp extends AbstractSqlServerExtensionExecutor {

    public MyApp() {
        executorExtensionVersion = SQLSERVER_JAVA_LANG_EXTENSION_V1;
        executorInputDatasetClassName = PrimitiveDataset.class.getName();
        executorOutputDatasetClassName = PrimitiveDataset.class.getName();
    } 

    public PrimitiveDataset execute(PrimitiveDataset input, 
             LinkedHashMap<String, Object> params) {
         log.error("hello world"); // work fine when called in a standalone app

Logging works fine when running the program as a standalone application (i.e. java MyApp) on a Windows machine. However, when the program is executed as a SQL Server Language Extensions application, no log file is created. I tried changing <file>${USER_HOME}/myApp.log</file> to <file>myApp.log</file> but still cannot find the log file.

Is there a place to check SQL Server logs to see why the Java application log file is not being created? How can I have the program log when it is being run by SQL Server language extension? I'm suspecting that the program may be prevented (sandboxed) by SQL Server from writing to the file system.

James
  • 2,876
  • 18
  • 72
  • 116
  • Just do this test, change the log file location to the folder that SQL server service running account can access, e.g., the database data file folder and see whether the logs are created. – PeterHe Oct 04 '19 at 19:49
  • Thanks for the suggestion. I just tried that I receive the following error on SSMS Messages console even after changing the folder permissions to `Full Control` for `Everyone`: `ERROR in ch.qos.logback.core.FileAppender[FILE] - openFile(/Program Files/Microsoft SQL Server/MSSQL15.MSSQLSERVER/MSSQL/DATA/myApp.log,true) call failed. java.io.FileNotFoundException: \Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\myApp.log (Access is denied)` – James Oct 04 '19 at 20:32

0 Answers0