Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to aid in script logging/debugging UNIX
As a Mac OS X administrator and as someone who likes to use shell and perl scripts to automate things, I find myself doing a lot of debugging and logging. To make things simpler, I wrote a perl script which I call from other scripts to output errors, warnings, and info in an ordered, easy-to-read system-log-like format.

Save the script text to a file (logger.pl), open Terminal and change the file mode to allow execution (chmod u+x /path/to/logger.pl), and call the script within (or without) another a script like this:
logger.pl /path/to/your.log calling-process "log text"
Note the log file will be created if it doesn't already exist.

[robg adds: I haven't tested this one...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[3,680 views]  

A script to aid in script logging/debugging | 6 comments | Create New Account
Click here to return to the 'A script to aid in script logging/debugging' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to aid in script logging/debugging
Authored by: Lutin on Aug 21, '06 08:46:23AM

I tested this and it works as described.
It doesn't produce any error if it couldn't write to the file (lack of permission...), but I guess it doesn't really matter.
Might be helpful at times.



[ Reply to This | # ]
A script to aid in script logging/debugging
Authored by: danger guy on Aug 21, '06 09:22:30AM

When there's an error, like a file permissions error, the script will log to the system log file /var/log/system.log. check your system log when you don't see the errors you'd expect.

-aaron



[ Reply to This | # ]
A script to aid in script logging/debugging
Authored by: jeremyp on Aug 21, '06 09:34:42AM
What's wrong with the already supplied logger command which can log to a file or syslog? type man logger for info on using it.

[ Reply to This | # ]
A script to aid in script logging/debugging
Authored by: adrianm on Aug 21, '06 12:08:41PM

why? /usr/bin/logger is a command-line interface to syslog. it won't write to an arbitrary log file.



[ Reply to This | # ]
A script to aid in script logging/debugging
Authored by: jeremyp on Aug 21, '06 12:42:33PM

And if you are logging why would you not want to use the operating system's built in log facility?



[ Reply to This | # ]
A script to aid in script logging/debugging
Authored by: danger guy on Aug 21, '06 08:32:08PM

because sometimes you're just debugging code and sometimes you want to keep track of specific info (login/out detials or your own application output) that otherwise doesn't make sense being dumped in the system log.



[ Reply to This | # ]