Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM logmsg.cmd - JeremyD
  4. @REM Logs text messages to the screen and/or in a log file
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. use strict;
  13. use lib $ENV{RAZZLETOOLPATH};
  14. use ParseArgs;
  15. use Logmsg;
  16. sub Usage { print<<USAGE; exit(1) }
  17. Prints the given string to the screen and into a file.
  18. Used by command scripts to log messages.
  19. usage: logmsg.cmd < message | \@filename > [logfile]
  20. /t If specified, the message is timestamped.
  21. message Specifies the text to be logged, should
  22. be quoted.
  23. filename A filename preceeded by an at-sign (\@)
  24. may be given instead of a message. The
  25. contents will be appened into the log
  26. if the given file exists.
  27. logfile Specifies the name of the log file.
  28. LOGFILE, if defined, is the default.
  29. If this parameter is not specified and
  30. LOGFILE is not defined, the message is
  31. displayed on the screen only.
  32. ex: call logmsg.cmd "This is the message to display."
  33. call logmsg.cmd \@mylog.txt
  34. USAGE
  35. my ($message, $logfile, $timestamp);
  36. parseargs('?' => \&Usage,
  37. 't' => \$timestamp,
  38. \$message,
  39. \$logfile);
  40. if ($logfile) {
  41. $ENV{LOGFILE} = $logfile;
  42. }
  43. $ENV{SCRIPT_NAME} ||= '????';
  44. # if the message starts with an @ interpret the rest as a filename to
  45. # append to the log
  46. if ($message =~ /^\@(.*)/) {
  47. if (-e $1) {
  48. append_file($1);
  49. }
  50. else {
  51. # do nothing if file to append does not exist
  52. }
  53. }
  54. # no initial @, message is just a string to be logged
  55. else {
  56. if ($timestamp) {
  57. timemsg($message);
  58. }
  59. else {
  60. logmsg($message);
  61. }
  62. }