text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
set theAlias to items 1 thru -2 of theAlias as string
|
ASLog.applescript
|
set parts to explode(theAlias, separator)
|
ASLog.applescript
|
if ((count parts) > 1) then
|
ASLog.applescript
|
return implode(items 1 thru -2 of parts, separator) & separator
|
ASLog.applescript
|
end parent_folder_of
|
ASLog.applescript
|
on filename_of(theFile)
|
ASLog.applescript
|
if class of theFile is alias then
|
ASLog.applescript
|
if theFile contains colon then
|
ASLog.applescript
|
else if theFile contains backslash then
|
ASLog.applescript
|
else if theFile contains slash then
|
ASLog.applescript
|
if theFile ends with separator then
|
ASLog.applescript
|
set theFile to items 1 thru -2 of theFile as string
|
ASLog.applescript
|
set parts to explode(theFile, separator)
|
ASLog.applescript
|
return item -1 of parts
|
ASLog.applescript
|
end filename_of
|
ASLog.applescript
|
script ASLogger
|
ASLog.applescript
|
property class : "ASLogger"
|
ASLog.applescript
|
property _folderpath : missing value
|
ASLog.applescript
|
property _filename : missing value
|
ASLog.applescript
|
property dateformat : "%Y-%m-%d %H:%M:%S"
|
ASLog.applescript
|
property msgformat : "%datetime% [%lvlname%] %msg%"
|
ASLog.applescript
|
property level : LVL_INFO
|
ASLog.applescript
|
on log_debug(msg)
|
ASLog.applescript
|
_log_msg("DEBUG", msg)
|
ASLog.applescript
|
end log_debug
|
ASLog.applescript
|
on log_info(msg)
|
ASLog.applescript
|
_log_msg("INFO", msg)
|
ASLog.applescript
|
end log_info
|
ASLog.applescript
|
on log_warn(msg)
|
ASLog.applescript
|
_log_msg("WARN", msg)
|
ASLog.applescript
|
end log_warn
|
ASLog.applescript
|
on log_error(msg)
|
ASLog.applescript
|
_log_msg("ERROR", msg)
|
ASLog.applescript
|
on log_other(lvlname, msg)
|
ASLog.applescript
|
_log_msg(lvlname, msg)
|
ASLog.applescript
|
end log_other
|
ASLog.applescript
|
on _log_msg(lvlname, msg)
|
ASLog.applescript
|
set logpath to my _compile_filepath()
|
ASLog.applescript
|
if _should_log(lvlname) then
|
ASLog.applescript
|
if not _HelperLib's exists_file(logpath) then
|
ASLog.applescript
|
_HelperLib's create_file(logpath)
|
ASLog.applescript
|
set formattedMsg to _format_msg(msg, lvlname)
|
ASLog.applescript
|
_HelperLib's write_to_file(logpath, formattedMsg)
|
ASLog.applescript
|
log errmsg & "number " & errnum
|
ASLog.applescript
|
end _log_msg
|
ASLog.applescript
|
on _format_msg(msg, lvlname)
|
ASLog.applescript
|
copy my msgformat to formattedMsg
|
ASLog.applescript
|
set formattedMsg to _HelperLib's search_and_replace(formattedMsg, "%msg%", msg)
|
ASLog.applescript
|
set formattedMsg to _HelperLib's search_and_replace(formattedMsg, "%lvlname%", lvlname)
|
ASLog.applescript
|
set formattedMsg to _HelperLib's search_and_replace(formattedMsg, "%lvlnum%", value of my level as string)
|
ASLog.applescript
|
set formattedMsg to _HelperLib's search_and_replace(formattedMsg, "%datetime%", _HelperLib's get_date(my dateformat))
|
ASLog.applescript
|
return formattedMsg
|
ASLog.applescript
|
end _format_msg
|
ASLog.applescript
|
on _should_log(lvlname)
|
ASLog.applescript
|
set msglevel to get_level(lvlname)
|
ASLog.applescript
|
return value of msglevel ≥ value of my level
|
ASLog.applescript
|
end _should_log
|
ASLog.applescript
|
on _compile_filepath()
|
ASLog.applescript
|
return my _folderpath & my _filename
|
ASLog.applescript
|
end _compile_filepath
|
ASLog.applescript
|
script RotatingLogger
|
ASLog.applescript
|
property class : "RotatingLogger"
|
ASLog.applescript
|
property parent : ASLogger
|
ASLog.applescript
|
if _should_rotate(msg) then
|
ASLog.applescript
|
_rotate()
|
ASLog.applescript
|
my parent's _log_msg(lvlname, msg)
|
ASLog.applescript
|
on _should_rotate(msg)
|
ASLog.applescript
|
return _over_maxbytes(msg)
|
ASLog.applescript
|
end _should_rotate
|
ASLog.applescript
|
on _rotate()
|
ASLog.applescript
|
repeat with i from (maxfiles - 1) to 1 by -1
|
ASLog.applescript
|
set currentlog to (logpath & "." & i)
|
ASLog.applescript
|
set previouslog to (logpath & "." & i - 1)
|
ASLog.applescript
|
if exists (disk item currentlog) then
|
ASLog.applescript
|
delete disk item currentlog
|
ASLog.applescript
|
if exists disk item previouslog then
|
ASLog.applescript
|
set name of disk item previouslog to (my _filename & "." & i)
|
ASLog.applescript
|
set name of disk item logpath to my _filename & "." & "1"
|
ASLog.applescript
|
end _rotate
|
ASLog.applescript
|
on _over_maxbytes(msg)
|
ASLog.applescript
|
if maxbytes = 0 or not _HelperLib's exists_file(my _compile_filepath()) then
|
ASLog.applescript
|
set logsize to size of disk item (my _compile_filepath())
|
ASLog.applescript
|
return (logsize + (length of my _format_msg(msg))) > my maxbytes
|
ASLog.applescript
|
end _over_maxbytes
|
ASLog.applescript
|
on get_logger(logpath)
|
ASLog.applescript
|
copy ASLogger to l
|
ASLog.applescript
|
set {l's _folderpath, l's _filename} to _HelperLib's {parent_folder_of(logpath), filename_of(logpath)}
|
ASLog.applescript
|
end get_logger
|
ASLog.applescript
|
on get_logger_at_level(logpath, lvl)
|
ASLog.applescript
|
get_level_name(lvl)
|
ASLog.applescript
|
set l to get_logger(logpath)
|
ASLog.applescript
|
set l's level to lvl
|
ASLog.applescript
|
end get_logger_at_level
|
ASLog.applescript
|
on get_rotating_logger(logpath, maxbytes)
|
ASLog.applescript
|
copy RotatingLogger to l
|
ASLog.applescript
|
set l's maxbytes to maxbytes
|
ASLog.applescript
|
end get_rotating_logger
|
ASLog.applescript
|
on get_rotating_logger_at_level(logpath, maxbytes, lvl)
|
ASLog.applescript
|
set l to get_rotating_logger(logpath, maxbytes)
|
ASLog.applescript
|
end get_rotating_logger_at_level
|
ASLog.applescript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.