<commit_before>
(cl:in-package :cl-log)

(defgeneric wrap-with-logger-name (definer forms logger-name))

(defgeneric create-logger-name (definer)
  (:documentation "Generate automatic logger name for the definer.")
  (:method ((definer definer))
    (let ((symb (demacs::name-of definer)))
      (format nil "~a.~a" 
              (shortest-package-name *package*)
              (symbol-name symb))))
  ;; for methods, append the types of non-T specializers after the method name
  (:method ((definer demacs:method-definer))
    (multiple-value-bind
          (specs quals)
        (if (keywordp (demacs::lambda-list-of definer))
            ;; handle the case of (def method foo :after
            ;; (&lambda-list)) in above case demacs should have given
            ;; an error but instead it has lambda-list as :after and
            ;; the actual lambda list is CAR of the body.
            ;;
            ;; Since I defined a lot of my after methods with above technically
            ;; invalid syntax, support it here
            (values
             (first (demacs::body-of definer))
             (list (demacs::lambda-list-of definer)))
            (values
             (demacs::lambda-list-of definer)
             (demacs::qualifiers-of definer)))
      (let ((specializers
             (loop for spec in specs
                if (and (consp spec)
                        (not (eq (second spec) t)))
                collect (if (eq (second spec) 'eql) (third spec)
                            (second spec)))))
        ;; the method qualifiers will be appended with : after method name
        ;; ie logger for initialize-instance :around ((foo bar) &key) will be
        ;; package.initialize-instance:around.bar
        (format nil "~a~{:~a~}~{.~a~}"
                (call-next-method)
                (mapcar #'string quals)
                (mapcar
                 #'string
                 (or specializers '(t))))))))

;; default method do not do anything
(defmethod wrap-with-logger-name ((definer definer) forms logger-name)
  (declare (ignore definer logger-name))
  forms)

;; for clisp wrapping into compiler-let works as intented
;; (ie very well)
#+clisp
(defmethod wrap-with-logger-name ((definer definer) forms logger-name)
  `(cl-user::compiler-let ((*default-logger-name* ,logger-name))
     ,forms))

;; In SBCL the compiler-let seems to be broken a bit.. Putting defclass/defstruct
;; defmacro/defconstant inside of (compiler-let) or (let) causes the corresponding
;; object to be only defined after the whole file is loaded. Its not to say that<commit_msg>Fix generating automatic logger name for eql methods<commit_after>
(cl:in-package :cl-log)

(defgeneric wrap-with-logger-name (definer forms logger-name))

(defgeneric create-logger-name (definer)
  (:documentation "Generate automatic logger name for the definer.")
  (:method ((definer definer))
    (let ((symb (demacs::name-of definer)))
      (format nil "~a.~a" 
              (shortest-package-name *package*)
              (symbol-name symb))))
  ;; for methods, append the types of non-T specializers after the method name
  (:method ((definer demacs:method-definer))
    (multiple-value-bind
          (specs quals)
        (if (keywordp (demacs::lambda-list-of definer))
            ;; handle the case of (def method foo :after
            ;; (&lambda-list)) in above case demacs should have given
            ;; an error but instead it has lambda-list as :after and
            ;; the actual lambda list is CAR of the body.
            ;;
            ;; Since I defined a lot of my after methods with above technically
            ;; invalid syntax, support it here
            (values
             (first (demacs::body-of definer))
             (list (demacs::lambda-list-of definer)))
            (values
             (demacs::lambda-list-of definer)
             (demacs::qualifiers-of definer)))
      (let ((specializers
             (loop for spec in specs
                if (and (consp spec)
                        (not (eq (second spec) t)))
                collect (let ((val (if (and (consp (second spec))
                                            (eq (first (second spec)) 'eql))
                                       (eval (second (second spec)))
                                       (second spec))))
                          val))))
        ;; the method qualifiers will be appended with : after method name
        ;; ie logger for initialize-instance :around ((foo bar) &key) will be
        ;; package.initialize-instance:around.bar
        (format nil "~a~{:~a~}~{.~a~}"
                (call-next-method)
                (mapcar #'string quals)
                (mapcar
                 #'string
                 (or specializers '(t))))))))

;; default method do not do anything
(defmethod wrap-with-logger-name ((definer definer) forms logger-name)
  (declare (ignore definer logger-name))
  forms)

;; for clisp wrapping into compiler-let works as intented
;; (ie very well)
#+clisp
(defmethod wrap-with-logger-name ((definer definer) forms logger-name)
  `(cl-user::compiler-let ((*default-logger-name* ,logger-name))
     ,forms))

;; In SBCL the compiler-let seems to be broken a bit.. Putting defclass/defstruct
;; defmacro/defconstant inside of (compiler-let) or (let) causes the corresponding
;; object to be only defined after the whole file is loaded. Its not to say that
{'fraction_non_alphanumeric': 0.11394746577876434, 'fraction_numerical': 0.0, 'mean_word_length': 2.1436046511627906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5795588', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1443, 'n_words': 524}