10 Replies Latest reply on Apr 17, 2012 3:42 PM by Joseph Fouts

    How to use environment variables in standalone.xml

    Joseph Fouts Novice

      I'm tring to setup a log file in standalone.xml file and would like to have it be located in a path that is

      defined in an environment variable.

       

      Does someone know how I would us an environment  variable in the standalone.xml file?

       

      Here is my current code:

       

            <periodic-rotating-file-handler name="ENTERPRISE">
                  <formatter>
                      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %10t %-5p - %m [%c]%n"/>
                  </formatter>           
                  <file relative-to="jboss.server.log.dir" path="Enterprise.log"/>
                  <suffix value=".yyyy-MM-dd"/>
                  <append value="true"/>
              </periodic-rotating-file-handler>

       

      I tried this but it did not work:

       

      <file relative-to="${MYENV_VAR}" path="Enterprise.log"/>

       

       

      Any help is appreciated.

       

      Thanks.

        • 1. Re: How to use environment variables in standalone.xml
          Tomaz Cerar Master

          Hi,

           

          not all elements/configuration flags support expressions.

          to make sure if the property you are looking for supports it, you can connect to server with cli

           

          and type ":read-resource-description" on context you are interested (for instance /subsystem=logging/periodic-rotating-file-handler=FILE) where you will get output like this:

           

          "append" => {

              "type" => BOOLEAN,

              "description" => "Specify whether to append to the target file.",

             "expressions-allowed" => false,

              "nillable" => true,

              "default" => true,

              "access-type" => "read-write",

              "storage" => "configuration",

              "restart-required" => "resource-services"

          },

          where you can see if attribute supports expression or it doesn't.

           

          As for your exact problem goes, attribute relative-to is it self a system property evaluated, that is why you can just write

           

          <file relative-to="MYENV_VAR" path="Enterprise.log"/>

          and it should work.

           

          --

          tomaz

          • 2. Re: How to use environment variables in standalone.xml
            Joseph Fouts Novice

            Thanks for the help Tomaz,

             

            I tried the following and I still can't get the file to go to the correct location:

             

            <file relative-to="MYENV_VAR" path="/logs/Enterprise.log"/>

            <file relative-to="MYENV_VAR" path="\logs\Enterprise.log"/>

            <file relative-to="MYENV_VAR" path="Enterprise.log"/>

             

            I want the log file to go to the following folder:

            c:\enterprise\logs

             

            SET from command line shows MYENV_VAR pointing to the following:

             

            MYENV_VAR=c:\enterprise

             

            Any ideas?

             

            Thanks.

            • 3. Re: How to use environment variables in standalone.xml
              Tomaz Cerar Master

              Hi,

               

              you are right, currently this does not work. Currently only solution for your would be to use

               

              <file path="c:\enterprise\logs\Enterprise.log"/>

              it has to be without relative-to attribute.

               

              Best way to address this is to create enhancment in jira, to support expressions for this attributes.

               

              --

              tomaz

              • 4. Re: How to use environment variables in standalone.xml
                Joseph Fouts Novice

                Bummer.

                 

                Thanks for your help.

                Not sure how or where to create a jira.

                • 5. Re: How to use environment variables in standalone.xml
                  Tomaz Cerar Master

                  hi,

                  just go to jira: https://issues.jboss.org/browse/AS7 and in top right corner you have create issue..

                   

                  --

                  tomaz

                  • 7. Re: How to use environment variables in standalone.xml
                    James Perkins Master

                    You can add a path though that would work the same. In CLI you could:

                     

                    /path=my.log.dir:add(path="C:\enterprise")
                    

                     

                    Then in in the relative-to attribute you just use my.log.dir.

                    • 8. Re: How to use environment variables in standalone.xml
                      Joseph Fouts Novice

                      Hi James,

                       

                      What I am trying to avoid is having to define the log folder location in multiple places.

                      Our thought was if we define an environment variable then all would just use that variable to define their log file location.

                      We have multiple systems that log to a specific folder.

                       

                      The log4j.properties file was able to access the systems environment variables and all worked well.

                      Seems as though JBoss logging should be able to accomplish the same thing.

                       

                      I'm not to familiar with the CLI.

                      How would I add the path definition to the standalone.xml file?

                       

                      Thanks.

                      • 9. Re: How to use environment variables in standalone.xml
                        James Perkins Master

                        It's not really an issue with JBoss Logging as much as we don't allow it in the logging subsystem in AS 7. I'm probably just missing something, but how many instances of AS7 will be running on a single box?

                         

                        Anyway, CLI is just a simple command line interface. Once the service is up you could just run:

                         

                        %JBOSS_HOME%\bin\jboss-cli.bat --connect "/path=my.log.dir:add(path=\"C:\\enterprise\")"
                        

                         

                        The XML would result in standalone.xml (I'm assuming standalone is being run here):

                         

                        <paths>
                            <path name="my.log.dir" path="C:\enterprise"/>
                        </paths>
                        

                         

                        It could easily be scripted as well for each server you deploy. Just a one time run script that goes through and adds the path and the loggers.

                        • 10. Re: How to use environment variables in standalone.xml
                          Joseph Fouts Novice

                          Thanks James I appreciate your help.

                           

                          We currently only have one instance of AS7 running a a single box.

                          The multiple systems are 3rd party systems that we must work with.

                          Our system is an AS7 system.

                          The concept is that we have multiple 3rd party systems that form an enterprise.

                          All logging for the enterprise must log to the same log folder.

                          The log folder is defined by an environment variable.

                           

                          If client decided to change the log folder location only the environment variable has to be

                          changed for all systems to pick up the change.

                           

                          Having to document/remember to change multiple locations is something that we try

                          an avoid.

                           

                          I hope this explains our enterprise central logging process better.

                           

                           

                          Hopefully a better way will be developed to accomplish what I am after in the future.

                           

                          Thanks.