Accumulating logs, instead of overwriting them

Accepted Solution Solved
Reply
Super Contributor
Posts: 252
Accepted Solution

Accumulating logs, instead of overwriting them

On our VA box we have several autoload directories, with Linux shell scripts firing every fifteen minutes to see if there's anything to load. This works really well and has been doing so pretty much faultlessly for a year now.

 

But the logs are timestamped - every fifteen minutes, every day, every month... For auditing purposes, we realistically need to be able to go back over the last month if necessary to track any problems.

 

I could set up a filename pattern and use logrotate (as I've done elsewhere), but as an interim measure so I can see exactly what's going on, I'd like to be able to get the logs to accumulate daily (so the log file looks like AutoLoad_2016.08.02.log, with all today's logs together).

 

Calling SAS in batch mode with -log overwrites the log; other SAS batch commands (exportpackage, for example) append onto existing logs.

 

Does anyone have any ideas? Any other options I could try?


Accepted Solutions
Solution
‎08-02-2016 08:11 PM
PROC Star
Posts: 1,290

Re: Accumulating logs, instead of overwriting them

I would look into the -logparm option. It seems to allow the sort of control over logfile generation you want, combined with the -log option.

View solution in original post


All Replies
Super User
Posts: 11,105

Re: Accumulating logs, instead of overwriting them

Completely untested but

 

proc printto log="pat\file &sysdate..txt";

run;

 

might work. Add that to the start of the job.

Log says just to write the log, the bit of = is the destination file. Without the option NEW the procedure should append to the destination file.

 

Note that this does not turn off the other log behavior so you can experiment with options.

 

Super User
Posts: 5,354

Re: Accumulating logs, instead of overwriting them

[ Edited ]

If you can run in batch mode, PROC PRINTTO should give you viable options.  You can begin each program with:

 

proc printto log=file of your choice mod;

run;

 

Then the rest of the log will be written to the file that you designate.

 

The MOD option allows appending instead of replacing.  You might have to adjust the code the very first time, or it might work as is.

 

You should be able to use macro language to automate the name of the file you write to, based on the current date.

 

**** EDITED:  Looks like I have to type a little faster if I want to be the first to answer!

 

 

Super Contributor
Posts: 252

Re: Accumulating logs, instead of overwriting them

Yeah thanks, but I was avoiding using printto and mod. I want to specify where it goes on the command line.

 

I thought it was interesting that the sas and exportpackage commands appear to work differently.

Solution
‎08-02-2016 08:11 PM
PROC Star
Posts: 1,290

Re: Accumulating logs, instead of overwriting them

I would look into the -logparm option. It seems to allow the sort of control over logfile generation you want, combined with the -log option.

Super Contributor
Posts: 252

Re: Accumulating logs, instead of overwriting them

Ladies and gentlemen, we have a winner. Thank you!

Super User
Posts: 5,354

Re: Accumulating logs, instead of overwriting them

If you're determined to avoid PRINTTO, you could try this approach.

 

Let the logs accumulate as separate files.

 

Write a SAS program to run once per day, to automatically:

 

  • Detect which logs belong to yesterday's programs.  This should be easy enough if the logs are all in one folder and if they include the date as part of the file name.
  • Consolidate them into one file by treating the logs as raw data:  read each line of each log as a variable, and write that variable to a file you designate.  (The naming of the file could be automated, so as not to require programming changes.)
  • Once the consolidated log file is in place, remove the individual logs.

That's just the big picture ... they are some details that go along with it, if this seems like a better approach.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 459 views
  • 1 like
  • 4 in conversation