Log rotation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elrondrules@gmail.com

    Log rotation

    I want to create a simple log rotation for the following scenario:

    I have a script that when executed will write debug and error messages
    to a specific file (say script.log).
    I want to create log rotation such a way that if the file size of
    script.log exceeds say 500KB, I want to rename script.log as
    script<day>1.lo g and the latest logs to be written to script.log.

    Essentially script.log should have the recent 500KB of logs.

    Is there any such inbuilt mechanism, else can you give some pointers
    to do this.

    Thanks
  • Jerry Stuckle

    #2
    Re: Log rotation

    elrondrules@gma il.com wrote:
    I want to create a simple log rotation for the following scenario:
    >
    I have a script that when executed will write debug and error messages
    to a specific file (say script.log).
    I want to create log rotation such a way that if the file size of
    script.log exceeds say 500KB, I want to rename script.log as
    script<day>1.lo g and the latest logs to be written to script.log.
    >
    Essentially script.log should have the recent 500KB of logs.
    >
    Is there any such inbuilt mechanism, else can you give some pointers
    to do this.
    >
    Thanks
    >
    Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
    PHP. Like logrotate.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • elrondrules@gmail.com

      #3
      Re: Log rotation

      On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
      elrondru...@gma il.com wrote:
      I want to create a simple log rotation for the following scenario:
      >
      I have a script that when executed will write debug and error messages
      to a specific file (say script.log).
      I want to create log rotation such a way that if the file size of
      script.log exceeds say 500KB, I want to rename script.log as
      script<day>1.lo g and the latest logs to be written to script.log.
      >
      Essentially script.log should have the recent 500KB of logs.
      >
      Is there any such inbuilt mechanism, else can you give some pointers
      to do this.
      >
      Thanks
      >
      Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
      PHP. Like logrotate.
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstuck...@attgl obal.net
      =============== ===
      thanks for the response..

      is there a sample that I can look at so that I can do a similar one in
      PHP?

      Comment

      • Jerry Stuckle

        #4
        Re: Log rotation

        elrondrules@gma il.com wrote:
        On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        >elrondru...@gm ail.com wrote:
        >>I want to create a simple log rotation for the following scenario:
        >>I have a script that when executed will write debug and error messages
        >>to a specific file (say script.log).
        >>I want to create log rotation such a way that if the file size of
        >>script.log exceeds say 500KB, I want to rename script.log as
        >>script<day>1. log and the latest logs to be written to script.log.
        >>Essentially script.log should have the recent 500KB of logs.
        >>Is there any such inbuilt mechanism, else can you give some pointers
        >>to do this.
        >>Thanks
        >Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
        >PHP. Like logrotate.
        >>
        >--
        >============== ====
        >Remove the "x" from my email address
        >Jerry Stuckle
        >JDS Computer Training Corp.
        >jstuck...@attg lobal.net
        >============== ====
        >
        thanks for the response..
        >
        is there a sample that I can look at so that I can do a similar one in
        PHP?
        >
        Don't know of one, but I haven't looked. Have you searched for log
        rotation scripts? There are several around, and most are very flexible.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • elrondrules@gmail.com

          #5
          Re: Log rotation

          On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          elrondru...@gma il.com wrote:
          On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          elrondru...@gma il.com wrote:
          >I want to create a simple log rotation for the following scenario:
          >I have a script that when executed will write debug and error messages
          >to a specific file (say script.log).
          >I want to create log rotation such a way that if the file size of
          >script.log exceeds say 500KB, I want to rename script.log as
          >script<day>1.l og and the latest logs to be written to script.log.
          >Essentially script.log should have the recent 500KB of logs.
          >Is there any such inbuilt mechanism, else can you give some pointers
          >to do this.
          >Thanks
          Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
          PHP. Like logrotate.
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===
          >
          thanks for the response..
          >
          is there a sample that I can look at so that I can do a similar one in
          PHP?
          >
          Don't know of one, but I haven't looked. Have you searched for log
          rotation scripts? There are several around, and most are very flexible.
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===
          I did search for log rotation scripts but couldnt find any. Let me
          keep looking.. though would be great if u can point to if you come
          across any

          Comment

          • Jerry Stuckle

            #6
            Re: Log rotation

            elrondrules@gma il.com wrote:
            On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >elrondru...@gm ail.com wrote:
            >>On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >>>elrondru...@ gmail.com wrote:
            >>>>I want to create a simple log rotation for the following scenario:
            >>>>I have a script that when executed will write debug and error messages
            >>>>to a specific file (say script.log).
            >>>>I want to create log rotation such a way that if the file size of
            >>>>script.lo g exceeds say 500KB, I want to rename script.log as
            >>>>script<day> 1.log and the latest logs to be written to script.log.
            >>>>Essential ly script.log should have the recent 500KB of logs.
            >>>>Is there any such inbuilt mechanism, else can you give some pointers
            >>>>to do this.
            >>>>Thanks
            >>>Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
            >>>PHP. Like logrotate.
            >>>--
            >>>============ ======
            >>>Remove the "x" from my email address
            >>>Jerry Stuckle
            >>>JDS Computer Training Corp.
            >>>jstuck...@at tglobal.net
            >>>============ ======
            >>thanks for the response..
            >>is there a sample that I can look at so that I can do a similar one in
            >>PHP?
            >Don't know of one, but I haven't looked. Have you searched for log
            >rotation scripts? There are several around, and most are very flexible.
            >>
            >--
            >============== ====
            >Remove the "x" from my email address
            >Jerry Stuckle
            >JDS Computer Training Corp.
            >jstuck...@attg lobal.net
            >============== ====
            >
            I did search for log rotation scripts but couldnt find any. Let me
            keep looking.. though would be great if u can point to if you come
            across any
            >
            As I said - I wouldn't do that in PHP - I'd use C or C++. And on my
            Linux systems, I just use logrotate.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Norman Peelman

              #7
              Re: Log rotation

              elrondrules@gma il.com wrote:
              On Mar 4, 6:11 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              >elrondru...@gm ail.com wrote:
              >>On Mar 4, 6:06 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              >>>elrondru...@ gmail.com wrote:
              >>>>I want to create a simple log rotation for the following scenario:
              >>>>I have a script that when executed will write debug and error messages
              >>>>to a specific file (say script.log).
              >>>>I want to create log rotation such a way that if the file size of
              >>>>script.lo g exceeds say 500KB, I want to rename script.log as
              >>>>script<day> 1.log and the latest logs to be written to script.log.
              >>>>Essential ly script.log should have the recent 500KB of logs.
              >>>>Is there any such inbuilt mechanism, else can you give some pointers
              >>>>to do this.
              >>>>Thanks
              >>>Nope, nothing in PHP. But then I think I'd do it in C or C++ instead of
              >>>PHP. Like logrotate.
              >>>--
              >>>============ ======
              >>>Remove the "x" from my email address
              >>>Jerry Stuckle
              >>>JDS Computer Training Corp.
              >>>jstuck...@at tglobal.net
              >>>============ ======
              >>thanks for the response..
              >>is there a sample that I can look at so that I can do a similar one in
              >>PHP?
              >Don't know of one, but I haven't looked. Have you searched for log
              >rotation scripts? There are several around, and most are very flexible.
              >>
              >--
              >============== ====
              >Remove the "x" from my email address
              >Jerry Stuckle
              >JDS Computer Training Corp.
              >jstuck...@attg lobal.net
              >============== ====
              >
              I did search for log rotation scripts but couldnt find any. Let me
              keep looking.. though would be great if u can point to if you come
              across any

              This is ugly, but it's what I used before i started logging to a db.
              Doesn't do filesize but will automatically change every day.

              LOGFILE is DEFINED() true or false to turn on/off logging.
              LOGNAME is DEFINED() as your log name.


              $u_id = uniqid('uid');
              $cr = chr(13);
              function logfile($txt)
              {
              if (LOGFILE)
              {
              $txt = date("G:i:s - ")."{$u-id} - {$txt}{$cr}";
              $lf = LOGNAME.date(' D M j - Y').'.log';
              $fp = fopen($lf,'a');
              if (flock($fp, LOCK_EX))
              {
              fwrite($fp,$txt ,1024);
              flock($fp, LOCK_UN);
              }
              fclose($fp);
              }
              }


              This was for multiple script calls logging to the same file, $u_id
              made it easy to group the entries. The date() made it easy to sort the
              entries. May help, may not. But like I said, I now log to a db.

              --
              Norman
              Registered Linux user #461062

              Comment

              Working...