text
stringlengths
0
15.7k
source
stringlengths
6
112
on logWarning(msg)
logManager.applescript
set fullMessage to ts & " Warning! " & msg
logManager.applescript
end logWarning
logManager.applescript
on _logToFile(msg)
logManager.applescript
set fileSize to size of (info for file logFilePath)
logManager.applescript
on error eMsg number eNum
logManager.applescript
set fileSize to 0
logManager.applescript
if fileSize ≥ maxSize then archive()
logManager.applescript
if writeToFile(msg) is false then
logManager.applescript
log msg
logManager.applescript
end _logToFile
logManager.applescript
on archive()
logManager.applescript
set i to 9
logManager.applescript
if i < 0 then exit repeat
logManager.applescript
set archivePath to parentFolderPath & logFileName & ".log." & (i as text) & ".gz"
logManager.applescript
get info for file archivePath
logManager.applescript
set archiveExists to true
logManager.applescript
on error errorMessage
logManager.applescript
set archiveExists to false
logManager.applescript
if archiveExists then
logManager.applescript
if i is 9 then
logManager.applescript
do shell script "rm -f " & quoted form of (POSIX path of archivePath)
logManager.applescript
do shell script "mv " & quoted form of (POSIX path of archivePath) & " " & quoted form of (POSIX path of previousArchivePath)
logManager.applescript
set previousArchivePath to archivePath
logManager.applescript
do shell script "gzip --suffix '.0.gz' " & quoted form of (POSIX path of logFilePath)
logManager.applescript
end archive
logManager.applescript
on timestamp(aDate as date, aFormat)
logManager.applescript
tell aDate as «class isot» as string
logManager.applescript
tell contents
logManager.applescript
if aFormat is 1 then
logManager.applescript
return text 1 thru 10 & " " & text 12 thru -1
logManager.applescript
else if aFormat is 2 then
logManager.applescript
return text 1 thru 10 & "_" & text 12 thru 13 & "-" & text 15 thru 16 & "-" & text 18 thru 19
logManager.applescript
else if aFormat is 3 then
logManager.applescript
set shortMonths to {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
logManager.applescript
return item (month of aDate) of shortMonths & " " & (day of aDate as text) & " " & text 12 thru -1
logManager.applescript
else if aFormat is 4 then
logManager.applescript
return text 1 thru 4 & text 6 thru 7 & text 9 thru 13 & text 15 thru 16 & text 18 thru 19
logManager.applescript
else if aFormat is 5 then
logManager.applescript
return text 1 thru 4 & text 6 thru 7 & text 9 thru 10 & text 12 thru 13 & text 15 thru 16 & text 18 thru 19
logManager.applescript
error "timestamp(): Unknown time format: " & (aFormat as text) number 1
logManager.applescript
end timestamp
logManager.applescript
on hfsPath(aPath)
logManager.applescript
set aPath to aPath as text
logManager.applescript
if aPath starts with "'" and aPath ends with "'" then
logManager.applescript
set aPath to text 2 thru -2 of anyPath
logManager.applescript
if aPath does not contain "/" and aPath does not contain ":" then
logManager.applescript
set aPath to "./" & aPath
logManager.applescript
if aPath starts with "~" then
logManager.applescript
set userPath to POSIX path of (path to home folder)
logManager.applescript
if userPath ends with "/" then set userPath to (text 1 thru -2 of userPath) as text
logManager.applescript
if aPath is "~" then
logManager.applescript
set aPath to userPath
logManager.applescript
set aPath to userPath & (text 2 thru -1 of aPath)
logManager.applescript
else if aPath starts with "./" then
logManager.applescript
set aPath to text 3 thru -1 of aPath
logManager.applescript
set myPath to POSIX path of kScriptPath
logManager.applescript
set myPath to POSIX path of (path to me)
logManager.applescript
set prvDlmt to text item delimiters
logManager.applescript
set parentDirectoryPath to (text items 1 thru -2 of myPath) & "" as text
logManager.applescript
set text item delimiters to prvDlmt
logManager.applescript
set aPath to parentDirectoryPath & aPath
logManager.applescript
else if aPath starts with "../" then
logManager.applescript
set text item delimiters to "../"
logManager.applescript
set pathComponents to text items of aPath
logManager.applescript
set parentDirectoryCount to (count of pathComponents) - 1
logManager.applescript
set myPathComponents to text items of myPath
logManager.applescript
set parentDirectoryPath to (items 1 thru ((count of items of myPathComponents) - parentDirectoryCount) of myPathComponents) & "" as text
logManager.applescript
set aPath to parentDirectoryPath & item -1 of pathComponents
logManager.applescript
if aPath does not contain ":" then
logManager.applescript
set aPath to (POSIX file aPath) as text
logManager.applescript
return aPath
logManager.applescript
end hfsPath
logManager.applescript
on hfsPathForParent(anyPath)
logManager.applescript
set anyPath to anyPath as text
logManager.applescript
if anyPath starts with "'" and anyPath ends with "'" then
logManager.applescript
set anyPath to text 2 thru -2 of anyPath
logManager.applescript
if anyPath starts with "~" then
logManager.applescript
if userPath ends with "/" then set userPath to text 1 thru -2 of userPath as text
logManager.applescript
if anyPath is "~" then
logManager.applescript
set anyPath to userPath
logManager.applescript
set anyPath to userPath & text 2 thru -1 of anyPath
logManager.applescript
if anyPath does not contain ":" then set anyPath to (POSIX file anyPath) as text
logManager.applescript
if anyPath does not end with ":" then set anyPath to anyPath & ":"
logManager.applescript
set parentPath to (text items 1 thru -3 of anyPath as text) & ":"
logManager.applescript
return parentPath
logManager.applescript
end hfsPathForParent
logManager.applescript
on writeToFile(content)
logManager.applescript
open for access file logFilePath with write permission
logManager.applescript
error "Could not open file with write permission: " & errorMessage number errorNumber
logManager.applescript
set fileEnd to 0
logManager.applescript
set fileEnd to (get eof of file logFilePath) + 1
logManager.applescript
write (content & (ASCII character 10)) to file logFilePath starting at fileEnd as «class utf8»
logManager.applescript
close access file logFilePath
logManager.applescript
error "Error while writing to file: " & errorMessage number errorNumber
logManager.applescript
set errorMessage to "writeToFile(): " & errorMessage
logManager.applescript
error errorMessage number errorNumber
logManager.applescript
tell LogManager
logManager.applescript
initWithPath(aLogFilePath)
logManager.applescript
return LogManager
logManager.applescript