Jump to content

limit size of log file


Recommended Posts

Hi there all - I am using this to log the progress of my running script: 

now my script runs 24.7 and I have no idea how to limit the size of the log file so it doesnt get out of hand - maybe periodically erase the first 100 lines or so... any ideas?

 

Link to comment
Share on other sites

If you are going to limit Size and not the amount of lines on the logfile you could check the logfile size and if is greater than your define max size then take the last 200 lines and delete your old logfile and create a new one with only the last 200 lines of the old one.

Something like this could give you some ideas:

#include <File.au3>
$iFileSize = FileGetSize(@ScriptDir&"\logfile.log")
$iMaxSize = 540708 ; ~528kb
If $iFileSize >= $iMaxSize Then
    $countLines = _FileCountLines(@ScriptDir&"\logfile.log")
EndIf
; Take for example last 200 lines
$startLine = $countLines - 200
For $i = $startLine To $countLines
    $lines = FileReadLine(@ScriptDir&"\logfile.log",$i)
Next

Regards
Alien.
 

Link to comment
Share on other sites

Thanks for the suggestions guys - I prefer the option of a new log file once a day.  The problem I have is that I cant delete the old log file as I get 'It is being used by another application' - any idea how do I 'release' it?

Link to comment
Share on other sites

Probably need to close it in your script you're using.

Close it then copy the file to something like Logs.old with a date. I usually have all of my logs formatted as

Quote

[MM/DD/YYYY] [HH:MM:SS] Line of log data

[MM/DD/YYYY] [HH:MM:SS] Line of log data

[MM/DD/YYYY] [HH:MM:SS] Line of log data

[MM/DD/YYYY] [HH:MM:SS] Line of log data

So it's easy to fetch the first and last line, extract the data (even time if I wanted that for my file) and use that for the file name.

Link to comment
Share on other sites

11 minutes ago, InunoTaishou said:

[MM/DD/YYYY] [HH:MM:SS] Line of log data

Isn't that a terrible date format? YYYY-MM-DD is the only one that lets you easily grab entries between two given dates, for instance. Then display dates according to your locale (or favorite) format for human consumption.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 hour ago, jchd said:

Isn't that a terrible date format? YYYY-MM-DD is the only one that lets you easily grab entries between two given dates, for instance. Then display dates according to your locale (or favorite) format for human consumption.

Why YYYY-MM-DD is better than MM-DD-YYYY or better than DD-MM-YYYY I don't mean to make a dispute, i'm just curious to know and learn.

Regards
Alien.

Link to comment
Share on other sites

10 minutes ago, alien4u said:

Why YYYY-MM-DD is better than MM-DD-YYYY or better than DD-MM-YYYY I don't mean to make a dispute, i'm just curious to know and learn.

YYYYMMDDhh:mm.ss

The same reason thousands,hundreds,tens,ones.tenthshundreths  is the best way to group your money

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

1 hour ago, iamtheky said:

YYYYMMDDhh:mm.ss

The same reason thousands,hundreds,tens,ones.tenthshundreths  is the best way to group your money

Base on this then should be:
YYYYmmssDDhhMM (Years > mm = ss > DD>hh>>MM.

I think there is no better Date Format, otherwise there will be a unified one? don't you think so?

Regards
Alien.

Edited by alien4u
Wrong example before.
Link to comment
Share on other sites

YYYY-MM-DD is good for normal sorting by year/month/day

DD-MM-YYYY is good when you like to sort by day,e.g. each 1. of month remember for paying bill for parking

MM-DD-YYYY is good for sorting for birthday dates e.g. who has this month birthday

But with all formats you can get a solution, but not necessary shortest/fasted  scriptcode

 

 

Edited by AutoBert
Link to comment
Share on other sites

Sure, but if generic logging is the goal.  Setting ranges seems easier.  It's sure as hell better than everything being the number of seconds since jan. 1 1970.  Screw that format.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

The reason, are you really going to be looking at log files from 2014 in 2016?

The only time it might be relevant is around the new year. If they're grouped by 2016 then I'm going to have dozens of files all starting with the same 2016 and then have to go to month. If I start with month then I know exactly what month it's going to be in and I can narrow it down to the day I want. (And obviously don't start with day because then you could have 3 files starting with 01-MM-YYYY)

Link to comment
Share on other sites

11 hours ago, alien4u said:

I think there is no better Date Format, otherwise there will be a unified one? don't you think so?

There is a unified one, it's called ISO 8601 and is THE standard date format that's used internationally to represent how dates/times should be formatted.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Is there a standard Microsoft way to access this ISO8601 date on any Windows?

Is there an AutoIt macro that will always return ISO8601 dates?

Quote

ISO 8601 tackles this uncertainty by setting out an internationally agreed way to represent dates:

YYYY-MM-DD

For example, September 27, 2012 is represented as 2012-09-27.

I read somewhere once, someone mentioning "20120927" not looking much like a date... I save documents with this date format...

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...