(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define std/logger#current-logger (make-parameter '#f))
  (define std/logger#start-logger!__%
    (lambda (_output481_)
      (let ((_$e483_ (std/logger#current-logger)))
        (if _$e483_
            (values _$e483_)
            (let ((_g4109_ (if (output-port? _output481_)
                               (values _output481_ '#f)
                               (if (string? _output481_)
                                   (values (open-output-file
                                            (cons 'path:
                                                  (cons _output481_
                                                        (cons 'append:
                                                              (cons '#t
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            '())))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                           '#t)
                                   (error '"Bad output; expected filename or port"
                                          _output481_)))))
              (begin
                (let ((_g4110_ (let ()
                                 (declare (not safe))
                                 (if (##values? _g4109_)
                                     (##vector-length _g4109_)
                                     1))))
                  (if (not (let () (declare (not safe)) (##fx= _g4110_ 2)))
                      (error "Context expects 2 values" _g4110_)))
                (let ((_port486_
                       (let () (declare (not safe)) (##vector-ref _g4109_ 0)))
                      (_own-port?487_
                       (let () (declare (not safe)) (##vector-ref _g4109_ 1))))
                  (let ((_srv489_
                         (gerbil/gambit/threads#spawn/name
                          'logger
                          std/logger#logger-server
                          _port486_
                          _own-port?487_)))
                    (std/logger#current-logger _srv489_)
                    _srv489_))))))))
  (define std/logger#start-logger!__0
    (lambda ()
      (let ((_output496_ (current-error-port)))
        (std/logger#start-logger!__% _output496_))))
  (define std/logger#start-logger!
    (lambda _g4112_
      (let ((_g4111_ (let () (declare (not safe)) (##length _g4112_))))
        (cond ((let () (declare (not safe)) (##fx= _g4111_ 0))
               (apply std/logger#start-logger!__0 _g4112_))
              ((let () (declare (not safe)) (##fx= _g4111_ 1))
               (apply std/logger#start-logger!__% _g4112_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/logger#start-logger!
                _g4112_))))))
  (define std/logger#!log-message::t
    (make-struct-type
     'std/logger#!log-message::t
     '#f
     '3
     '!log-message
     '()
     '#f
     '(source level e)))
  (define std/logger#!log-message?
    (make-struct-predicate std/logger#!log-message::t))
  (define std/logger#make-!log-message
    (lambda _$args477_
      (apply make-struct-instance std/logger#!log-message::t _$args477_)))
  (define std/logger#!log-message-source
    (make-struct-field-accessor std/logger#!log-message::t '0))
  (define std/logger#!log-message-level
    (make-struct-field-accessor std/logger#!log-message::t '1))
  (define std/logger#!log-message-e
    (make-struct-field-accessor std/logger#!log-message::t '2))
  (define std/logger#!log-message-source-set!
    (make-struct-field-mutator std/logger#!log-message::t '0))
  (define std/logger#!log-message-level-set!
    (make-struct-field-mutator std/logger#!log-message::t '1))
  (define std/logger#!log-message-e-set!
    (make-struct-field-mutator std/logger#!log-message::t '2))
  (define std/logger#logger-server
    (lambda (_port418_ _own-port?419_)
      (letrec ((_loop421_
                (lambda ()
                  (let* ((_g425436_ (thread-receive))
                         (_else428444_ (lambda () (_loop421_))))
                    (let ((_K431459_
                           (lambda (_message455_ _level456_ _source457_)
                             (std/format#fprintf
                              _port418_
                              '"~a [~a] ~a: ~a~n"
                              (std/srfi/19#date->string
                               (std/srfi/19#current-date)
                               '"~4")
                              _level456_
                              _source457_
                              _message455_)
                             (force-output _port418_)
                             (_loop421_)))
                          (_K430449_ (lambda () '#!void)))
                      (let ((_try-match427452_
                             (lambda ()
                               (if (let ()
                                     (declare (not safe))
                                     (##eq? _g425436_ 'shutdown))
                                   '#!void
                                   (_loop421_)))))
                        (if (let ()
                              (declare (not safe))
                              (##structure-instance-of?
                               _g425436_
                               'std/logger#!log-message::t))
                            (let* ((_e432462_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _g425436_ '1)))
                                   (_e433467_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _g425436_ '2)))
                                   (_e434472_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _g425436_ '3))))
                              (let ((_source465_ _e432462_)
                                    (_level470_ _e433467_)
                                    (_message475_ _e434472_))
                                (_K431459_
                                 _message475_
                                 _level470_
                                 _source465_)))
                            (_try-match427452_))))))))
        (with-unwind-protect
         (lambda () (_loop421_))
         (lambda () (if _own-port?419_ (close-port _port418_) '#!void))))))
  (define std/logger#debug
    (lambda (_fmt415_ . _args416_)
      (std/logger#log-message
       'debug
       (apply std/format#format _fmt415_ _args416_))))
  (define std/logger#warning
    (lambda (_fmt412_ . _args413_)
      (std/logger#log-message
       'warning
       (apply std/format#format _fmt412_ _args413_))))
  (define std/logger#log-error
    (lambda (_what407_ _exn408_)
      (let ((_outp410_ (open-output-string)))
        (std/format#fprintf _outp410_ '"~a: " _what407_)
        (display-exception _exn408_ _outp410_)
        (std/logger#log-message 'error (get-output-string _outp410_)))))
  (define std/logger#log-message
    (lambda (_level398_ _msg399_)
      (let ((_logger400402_ (std/logger#current-logger)))
        (if _logger400402_
            (let ((_logger405_ _logger400402_))
              (thread-send
               _logger405_
               (let ((__tmp4113 (current-thread)))
                 (declare (not safe))
                 (##structure
                  std/logger#!log-message::t
                  __tmp4113
                  _level398_
                  _msg399_))))
            '#f)))))
