Does HAProxy support logging to a file?












13















I've just installed haproxy on my test server.



Is there a way of making it write its logs to a local file, rather than syslog?



This is only for testing so I don't want to start opening ports / cluttering up syslog with all my test data.



Unfortunately, the only information I can find all revolves around logging to a syslog server.



I tried using:



log /home/user/ha.log local0


in my config. But that told me:



[ALERT] 039/095022 (9528) : sendto logger #1 failed: No such file or directory (errno=2)


When I restarted. So I created the file with touch /home/user/ha.log and restarted at which point I got:



[ALERT] 039/095055 (9593) : sendto logger #1 failed: Connection refused (errno=111)


Is this possible, or am I going to have to configure syslog etc. to see my test data?










share|improve this question




















  • 2





    I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

    – Michael - sqlbot
    Feb 9 '16 at 12:23


















13















I've just installed haproxy on my test server.



Is there a way of making it write its logs to a local file, rather than syslog?



This is only for testing so I don't want to start opening ports / cluttering up syslog with all my test data.



Unfortunately, the only information I can find all revolves around logging to a syslog server.



I tried using:



log /home/user/ha.log local0


in my config. But that told me:



[ALERT] 039/095022 (9528) : sendto logger #1 failed: No such file or directory (errno=2)


When I restarted. So I created the file with touch /home/user/ha.log and restarted at which point I got:



[ALERT] 039/095055 (9593) : sendto logger #1 failed: Connection refused (errno=111)


Is this possible, or am I going to have to configure syslog etc. to see my test data?










share|improve this question




















  • 2





    I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

    – Michael - sqlbot
    Feb 9 '16 at 12:23
















13












13








13


3






I've just installed haproxy on my test server.



Is there a way of making it write its logs to a local file, rather than syslog?



This is only for testing so I don't want to start opening ports / cluttering up syslog with all my test data.



Unfortunately, the only information I can find all revolves around logging to a syslog server.



I tried using:



log /home/user/ha.log local0


in my config. But that told me:



[ALERT] 039/095022 (9528) : sendto logger #1 failed: No such file or directory (errno=2)


When I restarted. So I created the file with touch /home/user/ha.log and restarted at which point I got:



[ALERT] 039/095055 (9593) : sendto logger #1 failed: Connection refused (errno=111)


Is this possible, or am I going to have to configure syslog etc. to see my test data?










share|improve this question
















I've just installed haproxy on my test server.



Is there a way of making it write its logs to a local file, rather than syslog?



This is only for testing so I don't want to start opening ports / cluttering up syslog with all my test data.



Unfortunately, the only information I can find all revolves around logging to a syslog server.



I tried using:



log /home/user/ha.log local0


in my config. But that told me:



[ALERT] 039/095022 (9528) : sendto logger #1 failed: No such file or directory (errno=2)


When I restarted. So I created the file with touch /home/user/ha.log and restarted at which point I got:



[ALERT] 039/095055 (9593) : sendto logger #1 failed: Connection refused (errno=111)


Is this possible, or am I going to have to configure syslog etc. to see my test data?







logs haproxy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 9 at 23:09









Chris Stryczynski

600419




600419










asked Feb 9 '16 at 10:07









IGGtIGGt

67541526




67541526








  • 2





    I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

    – Michael - sqlbot
    Feb 9 '16 at 12:23
















  • 2





    I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

    – Michael - sqlbot
    Feb 9 '16 at 12:23










2




2





I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

– Michael - sqlbot
Feb 9 '16 at 12:23







I don't think HAProxy can log to a file, and I suspect the reason for this is that writes to disk are a blocking operation. Why do you really not want to use syslog? Config is not all that tricky. You can assign a local facility to HAProxy and configure your syslog daemon to write those entries to a different file, and not to other syslog files (or network streams), if you're not wanting the HAProxy logs not to be mixed in with everything else.

– Michael - sqlbot
Feb 9 '16 at 12:23












3 Answers
3






active

oldest

votes


















12














Haproxy simply doesn't support logging to files.
As stated in the documentation (https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-log), the "log" statement takes as first parameter an address.
If that's a file, it's a unix socket and HAProxy will speak in the syslog format to this socket.
Haproxy is designed like this because its responsability is to proxy requests, not write files, it delegates writing of log files to syslog.
If you don't want to mess with your machine, you can for example install logstash and run:

logstash -e 'input { unix { path => "/tmp/haprxoy_log.sock" } } output { stdout { } }'

and add:

log /tmp/haprxoy_log.sock

In your haproxy.cfg to test it.






share|improve this answer































    6














    You can change haproxy log config file under /etc/rsyslog.d/ to point the file to the path you like. Not sure about other distribution. For me, I'm using Debian. I changed /etc/rsyslog.d/49-haproxy.conf to point to /var/log/haproxy/haproxy.log,



    # Create an additional socket in haproxy's chroot in order to allow logging via
    # /dev/log to chroot'ed HAProxy processes
    $AddUnixListenSocket /var/lib/haproxy/dev/log

    # Send HAProxy messages to a dedicated logfile
    if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log
    &~


    You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip.



    Then restart rsyslog.service.



    sudo systemctl restart rsyslog.service


    Now haproxy.log.* file will be in /var/log/haproxy/ directory.






    share|improve this answer

































      0














      You have tried to configured in the user home directory, haproxy doesn't have permission to access user's home directory, so that cause issue.



      Instead try in other location, create directory in /var/<directory>



      log /var/<directory>/ha.log





      share|improve this answer



















      • 2





        I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

        – IGGt
        Feb 9 '16 at 10:56











      • In log why you giving local0 in the end?

        – KKD
        Feb 9 '16 at 11:24






      • 1





        I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

        – IGGt
        Feb 9 '16 at 11:41











      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f260940%2fdoes-haproxy-support-logging-to-a-file%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      12














      Haproxy simply doesn't support logging to files.
      As stated in the documentation (https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-log), the "log" statement takes as first parameter an address.
      If that's a file, it's a unix socket and HAProxy will speak in the syslog format to this socket.
      Haproxy is designed like this because its responsability is to proxy requests, not write files, it delegates writing of log files to syslog.
      If you don't want to mess with your machine, you can for example install logstash and run:

      logstash -e 'input { unix { path => "/tmp/haprxoy_log.sock" } } output { stdout { } }'

      and add:

      log /tmp/haprxoy_log.sock

      In your haproxy.cfg to test it.






      share|improve this answer




























        12














        Haproxy simply doesn't support logging to files.
        As stated in the documentation (https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-log), the "log" statement takes as first parameter an address.
        If that's a file, it's a unix socket and HAProxy will speak in the syslog format to this socket.
        Haproxy is designed like this because its responsability is to proxy requests, not write files, it delegates writing of log files to syslog.
        If you don't want to mess with your machine, you can for example install logstash and run:

        logstash -e 'input { unix { path => "/tmp/haprxoy_log.sock" } } output { stdout { } }'

        and add:

        log /tmp/haprxoy_log.sock

        In your haproxy.cfg to test it.






        share|improve this answer


























          12












          12








          12







          Haproxy simply doesn't support logging to files.
          As stated in the documentation (https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-log), the "log" statement takes as first parameter an address.
          If that's a file, it's a unix socket and HAProxy will speak in the syslog format to this socket.
          Haproxy is designed like this because its responsability is to proxy requests, not write files, it delegates writing of log files to syslog.
          If you don't want to mess with your machine, you can for example install logstash and run:

          logstash -e 'input { unix { path => "/tmp/haprxoy_log.sock" } } output { stdout { } }'

          and add:

          log /tmp/haprxoy_log.sock

          In your haproxy.cfg to test it.






          share|improve this answer













          Haproxy simply doesn't support logging to files.
          As stated in the documentation (https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#3.1-log), the "log" statement takes as first parameter an address.
          If that's a file, it's a unix socket and HAProxy will speak in the syslog format to this socket.
          Haproxy is designed like this because its responsability is to proxy requests, not write files, it delegates writing of log files to syslog.
          If you don't want to mess with your machine, you can for example install logstash and run:

          logstash -e 'input { unix { path => "/tmp/haprxoy_log.sock" } } output { stdout { } }'

          and add:

          log /tmp/haprxoy_log.sock

          In your haproxy.cfg to test it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 17 '17 at 11:16









          user801247user801247

          25525




          25525

























              6














              You can change haproxy log config file under /etc/rsyslog.d/ to point the file to the path you like. Not sure about other distribution. For me, I'm using Debian. I changed /etc/rsyslog.d/49-haproxy.conf to point to /var/log/haproxy/haproxy.log,



              # Create an additional socket in haproxy's chroot in order to allow logging via
              # /dev/log to chroot'ed HAProxy processes
              $AddUnixListenSocket /var/lib/haproxy/dev/log

              # Send HAProxy messages to a dedicated logfile
              if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log
              &~


              You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip.



              Then restart rsyslog.service.



              sudo systemctl restart rsyslog.service


              Now haproxy.log.* file will be in /var/log/haproxy/ directory.






              share|improve this answer






























                6














                You can change haproxy log config file under /etc/rsyslog.d/ to point the file to the path you like. Not sure about other distribution. For me, I'm using Debian. I changed /etc/rsyslog.d/49-haproxy.conf to point to /var/log/haproxy/haproxy.log,



                # Create an additional socket in haproxy's chroot in order to allow logging via
                # /dev/log to chroot'ed HAProxy processes
                $AddUnixListenSocket /var/lib/haproxy/dev/log

                # Send HAProxy messages to a dedicated logfile
                if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log
                &~


                You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip.



                Then restart rsyslog.service.



                sudo systemctl restart rsyslog.service


                Now haproxy.log.* file will be in /var/log/haproxy/ directory.






                share|improve this answer




























                  6












                  6








                  6







                  You can change haproxy log config file under /etc/rsyslog.d/ to point the file to the path you like. Not sure about other distribution. For me, I'm using Debian. I changed /etc/rsyslog.d/49-haproxy.conf to point to /var/log/haproxy/haproxy.log,



                  # Create an additional socket in haproxy's chroot in order to allow logging via
                  # /dev/log to chroot'ed HAProxy processes
                  $AddUnixListenSocket /var/lib/haproxy/dev/log

                  # Send HAProxy messages to a dedicated logfile
                  if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log
                  &~


                  You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip.



                  Then restart rsyslog.service.



                  sudo systemctl restart rsyslog.service


                  Now haproxy.log.* file will be in /var/log/haproxy/ directory.






                  share|improve this answer















                  You can change haproxy log config file under /etc/rsyslog.d/ to point the file to the path you like. Not sure about other distribution. For me, I'm using Debian. I changed /etc/rsyslog.d/49-haproxy.conf to point to /var/log/haproxy/haproxy.log,



                  # Create an additional socket in haproxy's chroot in order to allow logging via
                  # /dev/log to chroot'ed HAProxy processes
                  $AddUnixListenSocket /var/lib/haproxy/dev/log

                  # Send HAProxy messages to a dedicated logfile
                  if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log
                  &~


                  You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip.



                  Then restart rsyslog.service.



                  sudo systemctl restart rsyslog.service


                  Now haproxy.log.* file will be in /var/log/haproxy/ directory.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 19 '17 at 4:48

























                  answered Dec 5 '17 at 9:09









                  FonzieFonzie

                  11614




                  11614























                      0














                      You have tried to configured in the user home directory, haproxy doesn't have permission to access user's home directory, so that cause issue.



                      Instead try in other location, create directory in /var/<directory>



                      log /var/<directory>/ha.log





                      share|improve this answer



















                      • 2





                        I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                        – IGGt
                        Feb 9 '16 at 10:56











                      • In log why you giving local0 in the end?

                        – KKD
                        Feb 9 '16 at 11:24






                      • 1





                        I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                        – IGGt
                        Feb 9 '16 at 11:41
















                      0














                      You have tried to configured in the user home directory, haproxy doesn't have permission to access user's home directory, so that cause issue.



                      Instead try in other location, create directory in /var/<directory>



                      log /var/<directory>/ha.log





                      share|improve this answer



















                      • 2





                        I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                        – IGGt
                        Feb 9 '16 at 10:56











                      • In log why you giving local0 in the end?

                        – KKD
                        Feb 9 '16 at 11:24






                      • 1





                        I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                        – IGGt
                        Feb 9 '16 at 11:41














                      0












                      0








                      0







                      You have tried to configured in the user home directory, haproxy doesn't have permission to access user's home directory, so that cause issue.



                      Instead try in other location, create directory in /var/<directory>



                      log /var/<directory>/ha.log





                      share|improve this answer













                      You have tried to configured in the user home directory, haproxy doesn't have permission to access user's home directory, so that cause issue.



                      Instead try in other location, create directory in /var/<directory>



                      log /var/<directory>/ha.log






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 9 '16 at 10:22









                      KKDKKD

                      344315




                      344315








                      • 2





                        I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                        – IGGt
                        Feb 9 '16 at 10:56











                      • In log why you giving local0 in the end?

                        – KKD
                        Feb 9 '16 at 11:24






                      • 1





                        I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                        – IGGt
                        Feb 9 '16 at 11:41














                      • 2





                        I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                        – IGGt
                        Feb 9 '16 at 10:56











                      • In log why you giving local0 in the end?

                        – KKD
                        Feb 9 '16 at 11:24






                      • 1





                        I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                        – IGGt
                        Feb 9 '16 at 11:41








                      2




                      2





                      I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                      – IGGt
                      Feb 9 '16 at 10:56





                      I tried sudo touch /var/log/ha.log and added log /var/log/ha.log local0 to my config, but got the same error as above connection refused.

                      – IGGt
                      Feb 9 '16 at 10:56













                      In log why you giving local0 in the end?

                      – KKD
                      Feb 9 '16 at 11:24





                      In log why you giving local0 in the end?

                      – KKD
                      Feb 9 '16 at 11:24




                      1




                      1





                      I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                      – IGGt
                      Feb 9 '16 at 11:41





                      I tried leaving it out, but when I restarted I got the error 'log' expects <address> and <facility> as arguments. so required something there. According to the instructions <facility> must be one of the 24 standard syslog facilities (which I think may be part of the problem)

                      – IGGt
                      Feb 9 '16 at 11:41


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f260940%2fdoes-haproxy-support-logging-to-a-file%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      19世紀