Author Topic: Are you logging your lisp routine usage?  (Read 12385 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 346
Are you logging your lisp routine usage?
« on: November 01, 2011, 05:53:04 PM »
This is directed primarily at the cad manager types.

Are any of you logging how much your lisp routines are being used?

I have seen managers (the cad managers boss) that question the creation of routines.  With logs showing how much routines are being used and an estimate of the time saved each use it seems it would be easier to justify the development time.

I'm just wondering if anyone else is doing something similar.

Mike

ronjonp

  • Needs a day job
  • Posts: 7409
Re: Are you logging your lisp routine usage?
« Reply #1 on: November 01, 2011, 06:07:43 PM »
I've been logging routines for about 5 years now. It's a good tool to see what people are using (and not) and where to focus on upgrades.  :-)

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Are you logging your lisp routine usage?
« Reply #2 on: November 01, 2011, 06:41:19 PM »
I don't log useage.  Most of my works are "library" type files at various depths of calling so the lowest ones get called a lot by the automation.  Management trusts me to invest my time well, and since it usually ends up making things easier and faster for the users and producing better results for the clients there are few questions.

While its possible to log the time taken for a routine, its kind of hard to log the time taken if the routine *isn't* used.  Plus its not just a matter of time expended - drawings can be done all on one layer faster than doing it on the correct layers but it still fails the quality test.  To my mind there are two good measurements of worth.  The first is the clients are happy with what we provide them, both in quality and cost.  The second is the users spending more time on designing than fighting (or gaming) the system.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

mkweaver

  • Bull Frog
  • Posts: 346
Re: Are you logging your lisp routine usage?
« Reply #3 on: November 01, 2011, 08:57:04 PM »
I'm not logging the time spent in a routine, just the number of times the routine is run (and by whom).

I agree, it is a good resource for identifying training needs.

The time lost through not using a routine is difficult to quantify.  I have some layer automation routines that save significant time and make it easier to comply with our standards than it would be without them.  If I look at the logs and see that someone is not using the layer routines then I know they are spending more time on their drawings than they need to - it's time for some training.

Mike

Krushert

  • Seagull
  • Posts: 13678
  • FREE BEER Tomorrow!!
Re: Are you logging your lisp routine usage?
« Reply #4 on: November 01, 2011, 09:35:26 PM »
Interesting Topic.  Thanks!
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Didge

  • Bull Frog
  • Posts: 211
Re: Are you logging your lisp routine usage?
« Reply #5 on: November 02, 2011, 07:00:07 AM »
I've been logging for about 10 years now, and have found a few benefits.

1. It aids me in de-bugging as it leaves a history of a users action leading-up to an error.
2. It allows me to suggest more appropriate working methods to the users.
3. It allows me to target future software development.
4. It gives management lots of coloured graphs for their enjoyment.
5. Its a great way of earning respect.

But most of all, when estimated time savings are multiplied by an hourly rates,

6. It justifies my employment  :-)

Typically, annual cost benefits to my organisation amount to approximately 20 times my salary, so I would whole-heartedly recommend logging. 

I only wish I'd negotiated a salary equal to 20% of the savings.   :ugly:
Think Slow......

Biscuits

  • Bull Frog
  • Posts: 495
Re: Are you logging your lisp routine usage?
« Reply #6 on: November 02, 2011, 08:51:34 AM »
I'm curious.................how does one go about creating/maintaining a log on lisp usage?
Is there something built into the routine? If so, I would like to see an example.

jaydee

  • Guest
Re: Are you logging your lisp routine usage?
« Reply #7 on: November 02, 2011, 09:36:36 AM »
Hi ronjonp and didge. Any chance that you could share the routine how to lodge the lisp usage.
The approach i could think of is have a write-line to append to text file on all function.
Thankyou
« Last Edit: November 02, 2011, 09:46:47 AM by jaydee »

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #8 on: November 02, 2011, 09:56:14 AM »
vlr-lisp-reactor comes to mind.  :wink:

ronjonp

  • Needs a day job
  • Posts: 7409
Re: Are you logging your lisp routine usage?
« Reply #9 on: November 02, 2011, 10:12:18 AM »
vlr-lisp-reactor comes to mind.  :wink:

Exactly :) ... I'll try to post what I have later ... it's kinda very scattered right now so I'll have to do some cleanup.

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Are you logging your lisp routine usage?
« Reply #10 on: November 02, 2011, 10:25:00 AM »
Hi ronjonp and didge. Any chance that you could share the routine how to lodge the lisp usage.
The approach i could think of is have a write-line to append to text file on all function.
Thankyou

Could probably improve performance and data acquisition using an in-memory MSXML.DOMDocument object, saving it out when the drawing is closed.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Dashmonkey

  • Newt
  • Posts: 29
  • (defun sleep nil nil)
Re: Are you logging your lisp routine usage?
« Reply #11 on: November 02, 2011, 11:15:44 AM »
Management trusts me to invest my time well, and since it usually ends up making things easier and faster for the users and producing better results for the clients there are few questions.

Dude, that's AWESOME!
Within that statement, at least in my mind, lies the key to job satisfaction.

...are your guys hiring? :D
I didn't break it, I swear! ...ok, I broke it.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Are you logging your lisp routine usage?
« Reply #12 on: November 02, 2011, 12:45:57 PM »
Management trusts me to invest my time well, and since it usually ends up making things easier and faster for the users and producing better results for the clients there are few questions.

Dude, that's AWESOME!
Within that statement, at least in my mind, lies the key to job satisfaction.

...are your guys hiring? :D

Focus.  We've got lots of divisions in a number of locations, so there is usually a demand for somebody with a given set of skill.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Dashmonkey

  • Newt
  • Posts: 29
  • (defun sleep nil nil)
Re: Are you logging your lisp routine usage?
« Reply #13 on: November 02, 2011, 04:49:12 PM »
Management trusts me to invest my time well, and since it usually ends up making things easier and faster for the users and producing better results for the clients there are few questions.

Dude, that's AWESOME!
Within that statement, at least in my mind, lies the key to job satisfaction.

...are your guys hiring? :D

Focus.  We've got lots of divisions in a number of locations, so there is usually a demand for somebody with a given set of skill.

Crazy! I work for Can-Am (Calgary). It's nice to see another Canuck 'round here :D
I didn't break it, I swear! ...ok, I broke it.

GDF

  • Water Moccasin
  • Posts: 2062
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Didge

  • Bull Frog
  • Posts: 211
Re: Are you logging your lisp routine usage?
« Reply #15 on: November 04, 2011, 07:10:49 AM »
Here's a cheap and cheerful logging function. It saves entries to a monthly CSV text file for easy manipulation within a spreadsheet. 

Just add the line  (Lisp-Log "your Command Name") to the beginning of each routine.

Code: [Select]
(defun LISP-LOG (CMD / Path Adminpath Adminfile)
  (if (and (setq Path (getvar "TEMPPREFIX")) ; replace this path with a suitable network drive
   (setq Adminpath (strcat Path "Lisp-Log-File_" (menucmd (strcat "m=$(edtime,$(getvar," "date" ")," "MONYYYY" ")")) ".csv"))
   (if (findfile Adminpath) (setq Adminfile (open Adminpath "a"))(setq Adminfile (open Adminpath "w")))
      )
    (progn
      (write-line (strcase (strcat (getvar "LOGINNAME") "," CMD ","
(menucmd (strcat "m=$(edtime,$(getvar," "date" ")," "DDDD D MONTH YYYY H:MMam/pm" ")")) ","
(vl-string-translate "," "*" (strcat (getvar "dwgprefix")(getvar "dwgname"))))) Adminfile)
      (close Adminfile)
      T
    )
    (alert "Logging Error")
  )
)
Think Slow......

V-Man

  • Bull Frog
  • Posts: 335
  • I exist therefore I am!
Re: Are you logging your lisp routine usage?
« Reply #16 on: November 04, 2011, 08:24:32 AM »
Here's one from Ron back in 2004. Still works.

Code: [Select]
;;; :FUNCTION
;;; ADDS ENTRIES TO THE LOCAL AND SERVER ENUMERATION FILES
;;; :LIMITATIONS
;;; NONE
;;; :USAGE
;;; ADD THE FOLLOWING LINES TO THE LSP ROUTINES YOU WANT TO RECORD
;;; (IF (= nil id:lispold)
;;;     (setq id:lispold "x")
;;;     (setq id:lispold id:lisp))
;;; (setq id:lisp "FILENAME.lsp")
;;; (c:LispCounter)
;;; :PLATFORMS
;;; 2000+
;;; :AUTHOR
;;; Ron Heigh
;;; email: ron.heigh@globaldetailing.com
;;; :VERSION
;;; 1.0 July 01, 2004
;;; Copyright 2004
;;;
(DEFUN c:LispCounter (/ D YR MO DAY MT HR M S P_TIME P_DATE fp:output fp:output2)
  (setq D   (rtos (getvar "CDATE") 2 6)
    YR  (substr D 3 2)
    MO  (substr D 5 2)
    DAY (substr D 7 2)
  ) ; end of setq
  (setq P_DATE (strcat MO "/" DAY "/" YR))
  (setq
    D  (rtos (getvar "CDATE") 2 6)
    MT (substr D 10 2)
    MT (atoi MT)
  ) ; end of setq
  (if (> MT 12)
    (setq HR (- MT 12))
    (setq HR MT)
  )
  (if (>= MT 12)
    (setq TOD " PM")
    (setq TOD " AM")
  )
  (setq HR (rtos HR 2 0))
  (setq
    M  (substr D 12 2)
    S  (substr D 14 2)
  ) ; end of setq
  (setq P_TIME (strcat HR ":" M ":" S TOD))
  (setq labeltext (strcat p_date " " P_time))
  (setq fp:output (open "c:\\lisp_count.csv" "a"))
  (write-line (strcat id:lisp "," P_DATE "," P_TIME "," (getvar "loginname")) fp:output)
  (close fp:output)
  (princ)
)
AutoCAD 2010 64-bit, AutoCADMap 2008, 2010, Revit 2012

pBe

  • Bull Frog
  • Posts: 399
Re: Are you logging your lisp routine usage?
« Reply #17 on: November 04, 2011, 08:29:43 AM »
vlr-lisp-reactor comes to mind.  :wink:

I never knew that reactor even exists  :lol:

Thanks Lee

Exactly :) ... I'll try to post what I have later ...

Great  :-D

Thank you for that Ron, you are too kind.

Chris

  • Swamp Rat
  • Posts: 547
Re: Are you logging your lisp routine usage?
« Reply #18 on: November 04, 2011, 08:51:10 AM »
you would almost have to use the reactor in order to really log the routine usage, unless you only have one defun per file.  It depends on what you are looking for, if you want to just trace your routines, or see how much any routine is being used.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Re: Are you logging your lisp routine usage?
« Reply #19 on: November 06, 2011, 06:15:35 PM »
Great Topic

One Question, does the counter slow down the work significant?

 
Bernd

ronjonp

  • Needs a day job
  • Posts: 7409
Re: Are you logging your lisp routine usage?
« Reply #20 on: November 06, 2011, 07:59:43 PM »
I don't notice any speed differences.

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #21 on: November 07, 2011, 11:29:06 AM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.

KewlToyZ

  • Guest
Re: Are you logging your lisp routine usage?
« Reply #22 on: November 08, 2011, 12:17:24 PM »
I did something a bit low bro using
Code: [Select]
(defun c:MyRoutine()

(command "LOGFILEON")
; insert code here
(command "LOGFILEOFF")
)
In my routines. I had all of the users using the same profile so they all save to a log file directory on their individual hard drives.
I did try some logging systems before saving to a network storage folder but found it was crashing cad when publishing for a reason neither myself nor Autodesk could figure out why and abandoned.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Are you logging your lisp routine usage?
« Reply #23 on: November 08, 2011, 04:28:15 PM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.
It doesn't seem to log anything, I am not sure why though.

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #24 on: November 08, 2011, 04:36:05 PM »
It doesn't seem to log anything, I am not sure why though.

A few questions/statements:
  • The logs are only created when the drawing is saved (so that there is no loss in performance).
  • Do you know where the CSV files are being stored?
  • The routine will only log 'LISP' command usage, not all commands (as per the thread)
  • The routine will not log macros (as these are not LISP expressions).

Krushert

  • Seagull
  • Posts: 13678
  • FREE BEER Tomorrow!!
Re: Are you logging your lisp routine usage?
« Reply #25 on: November 08, 2011, 04:49:59 PM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.
Just as my time is running out, you serve up this awesome code. **sigh**
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #26 on: November 08, 2011, 05:05:15 PM »
Just as my time is running out, you serve up this awesome code. **sigh**

Cheers Krush, hope you can use it  :-)

alanjt

  • Needs a day job
  • Posts: 5349
  • Standby for witty remark...
Re: Are you logging your lisp routine usage?
« Reply #27 on: November 08, 2011, 05:09:27 PM »
Logging is a good idea - should have thought about it sooner. What about something like this? It's been working successfully for a few days now.

You'll have to edit the folder path.

Code: [Select]
(vl-load-com)

  ;; LISP LOGGER
  ;; Alan J. Thompson

(or *Reactor:LISPLogger*
    (setq *Reactor:LISPLogger*
           (list (vlr-lisp-reactor nil '((:vlr-lispWillStart . Reactor:LISPLogger))))
    )
)



(defun Reactor:LISPLogger (a b / s f)
  (if
    (and (not (wcmatch (setq s (strcase (vl-princ-to-string (car b)))) "*DEFUN*,*VLIDE*,*LISPLOG*"))
         (wcmatch s "*(C:*")
    )
     (progn (write-line
              (strcat "(\""
                      (substr (vl-string-trim "()" s) 3)
                      "\" \""
                      (strcase (getvar 'LOGINNAME))
                      "\")"
              )
              (setq f (open
                        (strcat "U:\\LISPLog\\"
                                (menucmd (strcat "m=$(edtime,$(getvar," "DATE" ")," "MONTH_YYYY" ")"))
                                ".txt"
                        )
                        "A"
                      )
              )
            )
            (close f)
     )
  )
)




(defun c:LISPLog (/ AT:WriteToFile file item final cmd user)

  (defun AT:WriteToFile (file lst overwrite / fo)
    ;; Write list to file
    ;; file - file to write list to (must be in form "c:\\File.txt")
    ;; lst - list to write to file
    ;; overwrite - If T, will overwrite; nil to append
    ;; Alan J. Thompson, 04.28.09
    (if (and (vl-consp lst)
             (setq fo (open file
                            (if overwrite
                              "W"
                              "A"
                            )
                      )
             )
        )
      (progn (foreach x lst (write-line (vl-princ-to-string x) fo))
             (close fo)
             file
      )
    )
  )

  (if (and (setq file (getfiled "Select LISP Log text file:" "U:\\LISPLog\\" "TXT" 2))
           (setq file (open file "R"))
      )
    (progn
      (while (setq item (read-line file))
        (setq item  (read item)
              final (if (setq cmd (assoc (car item) final))
                      (subst (cons (car cmd)
                                   (if (setq user (assoc (cadr item) (cdr cmd)))
                                     (subst (cons (car user) (1+ (cdr user))) user (cdr cmd))
                                     (cons (cons (cadr item) 1) (cdr cmd))
                                   )
                             )
                             cmd
                             final
                      )
                      (cons (list (car item) (cons (cadr item) 1)) final)
                    )
        )
      )
      (vlax-invoke-method
        (setq shell (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application"))
        'Open
        (AT:WriteToFile
          (vl-filename-mktemp "" nil ".xls")
          (mapcar
            '(lambda (item)
               (strcat
                 (car item)
                 "\t"
                 (apply 'strcat
                        (apply 'append
                               (mapcar '(lambda (x) (list (vl-princ-to-string x) "\t"))
                                       (vl-sort (cdr item) '(lambda (a b) (< (car a) (car b))))
                               )
                        )
                 )
               )
             )
            (vl-sort final '(lambda (a b) (< (car a) (car b))))
          )
          T
        )
      )
      (vlax-release-object shell)
    )
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Are you logging your lisp routine usage?
« Reply #28 on: November 08, 2011, 05:36:45 PM »
It doesn't seem to log anything, I am not sure why though.

A few questions/statements:
  • The logs are only created when the drawing is saved (so that there is no loss in performance).
  • Do you know where the CSV files are being stored?
  • The routine will only log 'LISP' command usage, not all commands (as per the thread)
  • The routine will not log macros (as these are not LISP expressions).
I didn't quite realize that it was only when drawings were being saved, that works now, thank you. I made a few tweaks, such as I want it all saved in one file for each month and to save the username with each command, but that didn't take too much to accomplish.

This will definitely help with figuring out who needs more training. I know some people are not using our LISP routines, which are there to make work much faster, I just haven't been able to figure out who is not using them.

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #29 on: November 08, 2011, 06:04:00 PM »
Excellent to hear Chris, I'm glad the program is useful to you and that you were able to tailor it to your needs  :-)

mkweaver

  • Bull Frog
  • Posts: 346
Re: Are you logging your lisp routine usage?
« Reply #30 on: November 09, 2011, 07:27:16 AM »
I log lisp routine usage, but I also log errors.

Here is an example:
Code: [Select]
(progn
  (princ (strcat "\n\nProblem Title Block: " OLD_BLOCK_NAME))
  (princ (strcat "\nUn-Mapped attribute: " ATT_NAME "\n"))
  (setq LogMSG (strcat "Problem Title Block: " OLD_BLOCK_NAME ", Un-Mapped attribute: " ATT_NAME))
  (writetoerrorlog LogMSG "Title Swap routine")
  (setq PROBLEMS "YES")
        )

This particular routine has 19 calls to WriteToErrorLog, capturing different problems during data/input validation.

And the error log routine:
Code: [Select]
;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Routine: WriteToErrorLog
;;;  Purpose: Format and write data to the error log file
;;;  Arguments: ErrorMessage, string - the error message we're going to write
;;; ErrorSource, string - the name of the routine that produced the
;;; error.
;;;  Returns: nothing of value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;
(defun WriteToErrorLog( ErrorMessage ErrorSource / )
  (cond
    ((and
       (= 'STR (type
(setq Logerror
(WriteToLog
  (list
    (log:now)
    (log:unc)
    (getvar "loginname")
    ErrorMessage
    ErrorSource
    )
  (strcat Log:Folder Log:ErrorLog)
  )
       )
)
  )
       (wcmatch Logerror "ERROR|*")
       )
     (alert (strcat "ERROR|WriteToERRorLog - " Logerror))
     )
    )
  )


This allows me to capture the errors without interrupting the user.

2cook2

  • Guest
Re: Are you logging your lisp routine usage?
« Reply #31 on: February 07, 2012, 11:54:13 AM »
Hey cmwade77,

Can you post your modified version of the LISP logger?

Thanks

Simon B

  • Mosquito
  • Posts: 4
Re: Are you logging your lisp routine usage?
« Reply #32 on: August 20, 2015, 09:13:32 AM »
I know this is a very old post, however it's worth a try. I have only just started using LISPLogV1-0.lsp

Please can someone help me to modify the code for LISPLogV1-0 to create only one csv file, not a new one daily.

I'd like to monitor which lisps I am using & which I'm not, so after about 6 months I can archive the one's I use little or not at all.

The folder I keep lisps in now has about 300 files, some of which I'm sure have been supersueded

Simon


Code: [Select]
;;--------------------=={ Log LISP Usage }==------------------;;
;;                                                            ;;
;;  Automatically records daily LISP command usage to a CSV   ;;
;;  log file, stored in the folder indicated at the top of    ;;
;;  the code.                                                 ;;
;;                                                            ;;
;;  To enable automatic logging, load this LISP file on       ;;
;;  startup (recommend using the ACADDOC.lsp).                ;;
;;                                                            ;;
;;  To enable or disable LISP command logging at any time,    ;;
;;  type at the command-line 'LispLogON' or 'LispLogOFF'      ;;
;;  respectively.                                             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.0    -    07-11-2011                            ;;
;;------------------------------------------------------------;;

;;------------------------------------------------------------;;
;;  Log File Save Folder                                      ;;
;;------------------------------------------------------------;;
;;  LISP Log files will be saved to this folder.              ;;
;;  The folder will be created if it doesn't exist.           ;;
;;------------------------------------------------------------;;

(setq *lisp-log-folder* "C:\\AutoCAD\\LISPS\\Logs")

;;------------------------------------------------------------;;

(defun c:LispLogON nil
    (if (null *log-lisp-reactor*)
        (setq *log-lisp-reactor* (vlr-lisp-reactor "LISP-Log" '((:vlr-lispwillstart . lisplog:lispstarted))))
    )
    (if (null *log-save-reactor*)
        (setq *log-save-reactor* (vlr-editor-reactor "LISP-Log" '((:vlr-beginsave . lisplog:savelisplogs))))
    )
    (princ "\nLISP Logging Enabled.")
    (princ)
)

;;------------------------------------------------------------;;

(defun c:LispLogOFF nil
    (if *log-lisp-reactor*
        (progn (vlr-remove *log-lisp-reactor*) (setq *log-lisp-reactor* nil))
    )
    (if *log-save-reactor*
        (progn (vlr-remove *log-save-reactor*) (setq *log-save-reactor* nil))
    )
    (setq *lisp-log-list* nil)
    (vl-propagate '*lisp-log-list*)
    (princ "\nLISP Logging Disabled.")
    (princ)
)

;;------------------------------------------------------------;;

(defun lisplog:lispstarted ( reactor params )
    (if
        (and
            (wcmatch (setq params (strcase (car params))) "(C:*")
            (not (member params '("(C:LISPLOGON)" "(C:LISPLOGOFF)")))
        )
        (progn
            (setq *lisp-log-list*
                (LM:nAssoc++
                    (list
                        (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME))
                        (substr (vl-string-trim "()" params) 3)
                    )
                    *lisp-log-list*
                )
            )
            (vl-propagate '*lisp-log-list*)
        )
    )
    (princ)
)

;;------------------------------------------------------------;;

(defun lisplog:savelisplogs ( reactor params / *error* directory existing filename file )

    (defun *error* ( msg )
        (if (and file (eq 'FILE (type file))) (setq file (close file)))
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
   
    (if *lisp-log-list*
        (progn
            (if *lisp-log-folder*
                (setq *lisp-log-folder* (vl-string-right-trim "\\" (vl-string-translate "/" "\\" *lisp-log-folder*)))
                (setq *lisp-log-folder* (vl-string-right-trim "\\" (getvar 'DWGPREFIX)))
            )
            (setq directory (strcat *lisp-log-folder* "\\" (LM:Date "MONTH YYYY"))
                  filename  (strcat directory "\\Log_" (LM:Date "YYYYMODD") ".csv")
            )
            (if (null (vl-file-directory-p directory))
                (LM:CreateDirectory directory)
            )
            (if (findfile filename)
                (setq existing (LM:ReadLog filename))
            )
            (if (setq file (open filename "w"))
                (progn
                    (if existing
                        (setq *lisp-log-list* (LM:MergeLists *lisp-log-list* existing))
                    )
                    (foreach dwg (vl-sort *lisp-log-list* '(lambda ( a b ) (< (car a) (car b))))
                        (write-line (car dwg) file)
                        (foreach cmd (vl-sort (cdr dwg) '(lambda ( a b ) (> (cadr a) (cadr b))))
                            (write-line (strcat (car cmd) "," (itoa (cadr cmd))) file)
                        )
                        (write-line "" file)
                    )
                    (setq file (close file))
                    (setq *lisp-log-list* nil)
                    (vl-propagate '*lisp-log-list*)
                )
                (princ "\nUnable to write LISP Log - Check that the Log file is not in use.")
            )
        )
    )
    (princ)
)

;;------------------------------------------------------------;;

(defun LM:nAssoc++ ( key lst / pair )
    (if key
        (if (setq pair (assoc (car key) lst))
            (subst (cons (car key) (LM:nAssoc++ (cdr key) (cdr pair))) pair lst)
            (cons  (cons (car key) (LM:nAssoc++ (cdr key) nil)) lst)
        )
        (if lst (list (1+ (car lst))) '(1))
    )
)

;;------------------------------------------------------------;;

(defun LM:Date ( format )
    (menucmd (strcat "m=$(edtime,$(getvar,DATE)," format ")"))
)

;;------------------------------------------------------------;;

(defun LM:CreateDirectory ( dir / CreateDirectory folders )

    (defun CreateDirectory ( root folders )
        (if folders
            (   (lambda ( dir ) (vl-mkdir dir) (CreateDirectory dir (cdr folders)))
                (strcat root "\\" (car folders))
            )
        )
    )
 
    (if (setq folders (LM:str->lst (vl-string-translate "/" "\\" dir) "\\"))
        (CreateDirectory (car folders) (cdr folders))
    )
    (vl-file-directory-p dir)
)

;;------------------------------------------------------------;;

(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (vl-remove "" (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)))
        (list str)
    )
)

;;------------------------------------------------------------;;

(defun LM:ReadLog ( filename / file line lst sub1 sub2 )
    (if (setq file (open filename "r"))
        (progn
            (while (setq line (read-line file))
                (cond
                    (   (eq "" line)
                    )
                    (   (= 1 (length (setq line (LM:str->lst line ","))))
                        (if (and sub1 sub2)
                            (setq lst (cons (cons sub1 sub2) lst)
                                  sub1 nil
                                  sub2 nil
                            )
                        )
                        (setq sub1 (car line))
                    )
                    (   (= 2 (length line))
                        (setq sub2 (cons (list (car line) (atoi (cadr line))) sub2))
                    )
                )
            )
            (if (and sub1 sub2)
                (setq lst (cons (cons sub1 sub2) lst))
            )
            (setq file (close file))
            lst
        )
    )
)

;;------------------------------------------------------------;;

(defun LM:MergeLists ( l1 l2 / items item )
    (foreach group l2
        (if (setq items (cdr (assoc (car group) l1)))
            (progn
                (foreach pair (cdr group)
                    (if (setq item  (assoc (car pair) items))
                        (setq items (subst (list (car pair) (+ (cadr pair) (cadr item))) item items))
                        (setq items (cons pair items))
                    )
                )
                (setq l1 (subst (cons (car group) items) (assoc (car group) l1) l1))
            )
            (setq l1 (cons group l1))
        )
    )
    l1
)

;;------------------------------------------------------------;;

(vl-load-com) (c:LispLogON) (princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;

ronjonp

  • Needs a day job
  • Posts: 7409
Re: Are you logging your lisp routine usage?
« Reply #33 on: August 20, 2015, 09:57:17 AM »

Code - Auto/Visual Lisp: [Select]
  1. ;; Change this
  2. (setq directory (strcat *lisp-log-folder* "\\" (lm:date "MONTH YYYY"))
  3.       filename  (strcat directory "\\Log_" (lm:date "YYYYMODD") ".csv")
  4. )
  5. ;; To this
  6. (setq directory *lisp-log-folder*
  7.       filename  (strcat directory "\\LispLog.csv")
  8. )
Welcome to TheSwamp :)

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Simon B

  • Mosquito
  • Posts: 4
Re: Are you logging your lisp routine usage?
« Reply #34 on: August 20, 2015, 10:07:32 AM »
Thank you for your prompt reply ronjonp & your expertise.

I shall monitor it over the next week or so!

S

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #35 on: August 20, 2015, 12:18:34 PM »
Thank you for assisting in my absence Ron  :-)

I'm glad you find the program useful Simon!

chauhuh

  • Newt
  • Posts: 21
Re: Are you logging your lisp routine usage?
« Reply #36 on: August 20, 2015, 07:56:44 PM »
Been using this for awhile now Lee. Just wanted to say thanks!

Simon B

  • Mosquito
  • Posts: 4
Re: Are you logging your lisp routine usage?
« Reply #37 on: August 21, 2015, 01:51:32 AM »
I'd just like to echo what chauhuh said.

Guess who's lisps the log file records most often Mr Lee....

Thank you for your dedication

Simon

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #38 on: August 21, 2015, 04:01:43 AM »
Cheers guys!  :-)

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Are you logging your lisp routine usage?
« Reply #39 on: August 21, 2015, 12:19:46 PM »
I'd just like to echo what chauhuh said.

Guess who's lisps the log file records most often Mr Lee....

Thank you for your dedication

Simon
I don't think I have more than about 5 routines that don't use some of Lee's code.

romulo

  • Mosquito
  • Posts: 20
Re: Are you logging your lisp routine usage?
« Reply #40 on: February 28, 2018, 06:38:59 AM »
Very useful routine, but is possible to log not only "(defun c:" routines, but "(defun foo"?

I want log ALL "LISP" functions calls.

Thank you very much Lee !

Lee Mac

  • Seagull
  • Posts: 12659
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #41 on: February 28, 2018, 07:50:04 AM »
Comment/remove line 61.

You're welcome!  :-)


romulo

  • Mosquito
  • Posts: 20
Re: Are you logging your lisp routine usage?
« Reply #42 on: February 28, 2018, 07:47:15 PM »
Lee, thank you by your response.

But, not log all functions :: Log only first CALL, example:

(defun c:foo1 (/)
  (foo2)
  (foo3)
)

(defun foo2 (/)
  (princ "function 2")
)

(defun foo3 (/)
  (princ "function 3")
)


LOG wich I want:

*** (c:foo1)
------- (foo2)
------- (foo3)



« Last Edit: March 01, 2018, 06:50:18 AM by romulo »

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: Are you logging your lisp routine usage?
« Reply #43 on: October 22, 2021, 01:46:10 PM »
Hey cmwade77,

Can you post your modified version of the LISP logger?

Thanks
I know this is a REALLY old thread; however, I never did post it and I actually lost the version I had done, which meant I had to recreate the modifications and made a few more tweaks, such as adding a header, logging the date and time the save occurs, making the filename and path a separate column, removing blank lines between saves.

I have called mine LogTools so as to not be confused with Lee's version, although this is just a modification of his. Hopefully this still helps.