<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <br>
    <br>
    <div class="moz-cite-prefix">On 26/01/2024 10:46, Robert Scholte
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:034201da5044$f893b980$e9bb2c80$@apache.org">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered medium)">
      <style>@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}div.WordSection1
        {page:WordSection1;}ol
        {margin-bottom:0cm;}ul
        {margin-bottom:0cm;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi,<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><span lang="EN-US">I’m working on a new
            application, using jlink to build it.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">One challenge is related
            to the simplelogger of SLF4J (as SLF4J-api is probably the
            most used logging api, the simplelogger implementation
            matches my requirements)<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">There are 2 things that
            I would like to adjust:<o:p></o:p></span></p>
        <ol style="margin-top:0cm" type="1" start="1">
          <li class="MsoListParagraph" style="margin-left:-18.0pt;mso-list:l0 level1 lfo2"><span lang="EN-US">Simplelogger uses the classloader to find the
              simplelogger.properties ( <a href="https://github.com/qos-ch/slf4j/blob/master/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java#L107-L130" moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/qos-ch/slf4j/blob/master/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java#L107-L130</a>
              ). <o:p></o:p></span></li>
        </ol>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">However, I want to externalize this file to
            ${java.home}/conf/simplelogger.properties, so users can
            adjust it to their preferences. If I could change the
            classloader I could control where to find this file.<o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">When bundling simplelogger with jlink the jar
            will end up in the AppClassloader due to the
            SimpleServiceProvider. <o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">The only option to avoid this, is to move this
            jar to a separate directory and when making a new
            ModuleLayer, and use ModuleFinder with this path. <o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">But still, I see no way to change the
            classloader for this jar.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <ol style="margin-top:0cm" type="1" start="2">
          <li class="MsoListParagraph" style="margin-left:-18.0pt;mso-list:l0 level1 lfo2"><span lang="EN-US">The simplelogger.properties is the default
              configuration, and I want to make it possible to override
              these values. <o:p></o:p></span></li>
        </ol>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">The simplelogger offers the option to use
            SystemProperties to override values from
            simplelogger.properties.<o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">I want to avoid that the System.properties will
            be polluted with entities just for logging.<o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">As far as I know it is not possible to scope
            System.properties: they are global, available for every part
            of the application.<o:p></o:p></span></p>
        <p class="MsoListParagraph" style="margin-left:18.0pt"><span lang="EN-US">Another idea I had was to extend the
            simplelogging.properties resources at runtime using the
            SequenceInputStream, and for this I also need to have
            control over the classloader, as it requires to override the
            ClassLoader.getResourceAsStream()<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">It seems both challenges
            could be solved if could control the classloader (while
            still being protected by jdk.internal.loader.Loader).<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Am I missing some
            feature or it there another way to solve these issues?<o:p></o:p></span></p>
        <br>
      </div>
    </blockquote>
    Hi Robert,<br>
    <br>
    The code you linked to using the current Thread's context
    ClassLoader (CCL) to find the resource. So not the same thing as the
    class loader that defined SimpleLoggerConfiguration. At a guess,
    that code look like it is intended to support bundling of logging
    configuration with an application. It means code can set the current
    Thread's CCL, initialize SL4J to so it find the resource (config
    file) with that class loader, and reset it after.<br>
    <br>
    To be editable in ${java.home}/conf would require
    changing SimpleLoggerConfiguration.loadProperties to look for the
    properties file there. The defining classer for
    SimpleLoggerConfiguration won't change that as Class.getResource or
    ClassLoader.getResource doesn't find resources there.<br>
    <br>
    -Alan<br>
    <br>
    <br>
    <br>
    <br>
    <br>
  </body>
</html>