Custom apache error logs for the directories inside the document root











up vote
1
down vote

favorite












I stuck with this issue, googled it around and got some solutions but unlikely it is not working properly. Can anyone give a solution for this please,



I'm running Apache2 in Ubuntu 14.04 machine. Have only one virtual host running in it
and have a document root under /var/www/html where our resides.



Inside html directory our code contains sub-directories. For eg. dir1, dir2.
I need the error log should be customized like all the error log related to code under dir1 should resides inside dir1 and same for dir2.



How I can customize the error logs?










share|improve this question
























  • Why not separate them in 2 different virtual hosts?
    – Dan
    Aug 31 '17 at 7:20










  • No. Customer don't want us to do that Dan!
    – harsha
    Aug 31 '17 at 7:22















up vote
1
down vote

favorite












I stuck with this issue, googled it around and got some solutions but unlikely it is not working properly. Can anyone give a solution for this please,



I'm running Apache2 in Ubuntu 14.04 machine. Have only one virtual host running in it
and have a document root under /var/www/html where our resides.



Inside html directory our code contains sub-directories. For eg. dir1, dir2.
I need the error log should be customized like all the error log related to code under dir1 should resides inside dir1 and same for dir2.



How I can customize the error logs?










share|improve this question
























  • Why not separate them in 2 different virtual hosts?
    – Dan
    Aug 31 '17 at 7:20










  • No. Customer don't want us to do that Dan!
    – harsha
    Aug 31 '17 at 7:22













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I stuck with this issue, googled it around and got some solutions but unlikely it is not working properly. Can anyone give a solution for this please,



I'm running Apache2 in Ubuntu 14.04 machine. Have only one virtual host running in it
and have a document root under /var/www/html where our resides.



Inside html directory our code contains sub-directories. For eg. dir1, dir2.
I need the error log should be customized like all the error log related to code under dir1 should resides inside dir1 and same for dir2.



How I can customize the error logs?










share|improve this question















I stuck with this issue, googled it around and got some solutions but unlikely it is not working properly. Can anyone give a solution for this please,



I'm running Apache2 in Ubuntu 14.04 machine. Have only one virtual host running in it
and have a document root under /var/www/html where our resides.



Inside html directory our code contains sub-directories. For eg. dir1, dir2.
I need the error log should be customized like all the error log related to code under dir1 should resides inside dir1 and same for dir2.



How I can customize the error logs?







14.04 apache2 log error-handling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 at 9:27









Mr Shunz

2,2091922




2,2091922










asked Aug 31 '17 at 6:19









harsha

769




769












  • Why not separate them in 2 different virtual hosts?
    – Dan
    Aug 31 '17 at 7:20










  • No. Customer don't want us to do that Dan!
    – harsha
    Aug 31 '17 at 7:22


















  • Why not separate them in 2 different virtual hosts?
    – Dan
    Aug 31 '17 at 7:20










  • No. Customer don't want us to do that Dan!
    – harsha
    Aug 31 '17 at 7:22
















Why not separate them in 2 different virtual hosts?
– Dan
Aug 31 '17 at 7:20




Why not separate them in 2 different virtual hosts?
– Dan
Aug 31 '17 at 7:20












No. Customer don't want us to do that Dan!
– harsha
Aug 31 '17 at 7:22




No. Customer don't want us to do that Dan!
– harsha
Aug 31 '17 at 7:22










3 Answers
3






active

oldest

votes

















up vote
0
down vote













I believe this is what you want:



SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2


Source:



https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache






share|improve this answer





















  • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
    – harsha
    Aug 31 '17 at 6:53










  • Even when you edit the name to ErrorLog?
    – George Udosen
    Aug 31 '17 at 6:56










  • Please see this: stackoverflow.com/questions/10395043/…
    – George Udosen
    Aug 31 '17 at 7:05










  • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
    – harsha
    Aug 31 '17 at 7:05










  • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
    – harsha
    Aug 31 '17 at 7:14


















up vote
0
down vote













According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs



It is not doable for the error log as ErrorLog directive works only in server config or virtual host context.
It is possible to separate AccessLog with features provided by setenvif module.



Alternatively one can try something like that:



ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"



Just put more sophisticated filtering script in between and may be you manage to achieve what you need.



Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.






share|improve this answer





















  • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
    – harsha
    Aug 31 '17 at 7:12










  • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
    – mestia
    Aug 31 '17 at 7:28


















up vote
0
down vote













Simply use in your vhost




ErrorLog error.log




and it will write error file in the same folder in which the script causing the error resides.



An error in




http://example.com/some/dir/test.php




will write the error in




/public_html/some/dir/error.log







share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f951497%2fcustom-apache-error-logs-for-the-directories-inside-the-document-root%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








    up vote
    0
    down vote













    I believe this is what you want:



    SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
    SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

    CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
    CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2


    Source:



    https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache






    share|improve this answer





















    • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
      – harsha
      Aug 31 '17 at 6:53










    • Even when you edit the name to ErrorLog?
      – George Udosen
      Aug 31 '17 at 6:56










    • Please see this: stackoverflow.com/questions/10395043/…
      – George Udosen
      Aug 31 '17 at 7:05










    • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
      – harsha
      Aug 31 '17 at 7:05










    • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
      – harsha
      Aug 31 '17 at 7:14















    up vote
    0
    down vote













    I believe this is what you want:



    SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
    SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

    CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
    CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2


    Source:



    https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache






    share|improve this answer





















    • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
      – harsha
      Aug 31 '17 at 6:53










    • Even when you edit the name to ErrorLog?
      – George Udosen
      Aug 31 '17 at 6:56










    • Please see this: stackoverflow.com/questions/10395043/…
      – George Udosen
      Aug 31 '17 at 7:05










    • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
      – harsha
      Aug 31 '17 at 7:05










    • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
      – harsha
      Aug 31 '17 at 7:14













    up vote
    0
    down vote










    up vote
    0
    down vote









    I believe this is what you want:



    SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
    SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

    CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
    CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2


    Source:



    https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache






    share|improve this answer












    I believe this is what you want:



    SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
    SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

    CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
    CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2


    Source:



    https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 31 '17 at 6:40









    George Udosen

    18.9k94266




    18.9k94266












    • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
      – harsha
      Aug 31 '17 at 6:53










    • Even when you edit the name to ErrorLog?
      – George Udosen
      Aug 31 '17 at 6:56










    • Please see this: stackoverflow.com/questions/10395043/…
      – George Udosen
      Aug 31 '17 at 7:05










    • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
      – harsha
      Aug 31 '17 at 7:05










    • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
      – harsha
      Aug 31 '17 at 7:14


















    • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
      – harsha
      Aug 31 '17 at 6:53










    • Even when you edit the name to ErrorLog?
      – George Udosen
      Aug 31 '17 at 6:56










    • Please see this: stackoverflow.com/questions/10395043/…
      – George Udosen
      Aug 31 '17 at 7:05










    • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
      – harsha
      Aug 31 '17 at 7:05










    • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
      – harsha
      Aug 31 '17 at 7:14
















    Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
    – harsha
    Aug 31 '17 at 6:53




    Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs.
    – harsha
    Aug 31 '17 at 6:53












    Even when you edit the name to ErrorLog?
    – George Udosen
    Aug 31 '17 at 6:56




    Even when you edit the name to ErrorLog?
    – George Udosen
    Aug 31 '17 at 6:56












    Please see this: stackoverflow.com/questions/10395043/…
    – George Udosen
    Aug 31 '17 at 7:05




    Please see this: stackoverflow.com/questions/10395043/…
    – George Udosen
    Aug 31 '17 at 7:05












    CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
    – harsha
    Aug 31 '17 at 7:05




    CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct?
    – harsha
    Aug 31 '17 at 7:05












    I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
    – harsha
    Aug 31 '17 at 7:14




    I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log
    – harsha
    Aug 31 '17 at 7:14












    up vote
    0
    down vote













    According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs



    It is not doable for the error log as ErrorLog directive works only in server config or virtual host context.
    It is possible to separate AccessLog with features provided by setenvif module.



    Alternatively one can try something like that:



    ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"



    Just put more sophisticated filtering script in between and may be you manage to achieve what you need.



    Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.






    share|improve this answer





















    • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
      – harsha
      Aug 31 '17 at 7:12










    • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
      – mestia
      Aug 31 '17 at 7:28















    up vote
    0
    down vote













    According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs



    It is not doable for the error log as ErrorLog directive works only in server config or virtual host context.
    It is possible to separate AccessLog with features provided by setenvif module.



    Alternatively one can try something like that:



    ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"



    Just put more sophisticated filtering script in between and may be you manage to achieve what you need.



    Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.






    share|improve this answer





















    • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
      – harsha
      Aug 31 '17 at 7:12










    • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
      – mestia
      Aug 31 '17 at 7:28













    up vote
    0
    down vote










    up vote
    0
    down vote









    According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs



    It is not doable for the error log as ErrorLog directive works only in server config or virtual host context.
    It is possible to separate AccessLog with features provided by setenvif module.



    Alternatively one can try something like that:



    ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"



    Just put more sophisticated filtering script in between and may be you manage to achieve what you need.



    Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.






    share|improve this answer












    According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs



    It is not doable for the error log as ErrorLog directive works only in server config or virtual host context.
    It is possible to separate AccessLog with features provided by setenvif module.



    Alternatively one can try something like that:



    ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"



    Just put more sophisticated filtering script in between and may be you manage to achieve what you need.



    Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 31 '17 at 6:54









    mestia

    613




    613












    • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
      – harsha
      Aug 31 '17 at 7:12










    • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
      – mestia
      Aug 31 '17 at 7:28


















    • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
      – harsha
      Aug 31 '17 at 7:12










    • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
      – mestia
      Aug 31 '17 at 7:28
















    Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
    – harsha
    Aug 31 '17 at 7:12




    Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on.
    – harsha
    Aug 31 '17 at 7:12












    In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
    – mestia
    Aug 31 '17 at 7:28




    In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers.
    – mestia
    Aug 31 '17 at 7:28










    up vote
    0
    down vote













    Simply use in your vhost




    ErrorLog error.log




    and it will write error file in the same folder in which the script causing the error resides.



    An error in




    http://example.com/some/dir/test.php




    will write the error in




    /public_html/some/dir/error.log







    share|improve this answer

























      up vote
      0
      down vote













      Simply use in your vhost




      ErrorLog error.log




      and it will write error file in the same folder in which the script causing the error resides.



      An error in




      http://example.com/some/dir/test.php




      will write the error in




      /public_html/some/dir/error.log







      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Simply use in your vhost




        ErrorLog error.log




        and it will write error file in the same folder in which the script causing the error resides.



        An error in




        http://example.com/some/dir/test.php




        will write the error in




        /public_html/some/dir/error.log







        share|improve this answer












        Simply use in your vhost




        ErrorLog error.log




        and it will write error file in the same folder in which the script causing the error resides.



        An error in




        http://example.com/some/dir/test.php




        will write the error in




        /public_html/some/dir/error.log








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 at 7:22









        Sunil Gautam

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2faskubuntu.com%2fquestions%2f951497%2fcustom-apache-error-logs-for-the-directories-inside-the-document-root%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

            Mouse cursor on multiple screens with different PPI

            Agildo Ribeiro

            Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”