help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apache2 error messages


From: Felix Dietrich
Subject: Re: Apache2 error messages
Date: Mon, 03 Oct 2022 17:33:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)

Hello Jean,

Jean Louis <bugs@gnu.support> writes:

> I would like myself to be able to send messages to Apache log.
>
> Now this message is appearing in error.log, but it does not appear to
> be error.
>
> Wed Sep 28 06:31:32.023427 2022] [cgi:error] [pid 5706] [client 
> 102.83.37.37:54464] AH01215: Loading /var/www/.emacs.d/init.el (source)...: 
> /var/www/subscribe.example.com/doi.cgi

This appears to be one of Emacsʼ startup messages.  These are written to
the standard error stream.

> Never mind, I would like to send messages to error log.  Is the way to
> go to use `message' function?

With ‘message’ you can write to the standard output stream, when using
Emacs with the “--script” or “--batch” command line options.  Using an
Emacs Lisp file as a CGI script, I believe what is written to the
standard output is sent back to the client (if it is written after
correct headers).

Presumably, output on the standard error stream is written to Apacheʼs
error log.  From within Emacs, you can write to standard error using [1]:

#+begin_src emacs-lisp
  (print "This is the output" #'external-debugging-output)
#+end_src

Alternatively, you may want to look into other ways of logging.  For
example you could:

1. send messages to logging daemons (like journald or syslog) connecting
to their sockets directly and sending them messages formatted according
to their protocols [2][3][4],

2. use a command line tool like “logger” by wrapping the Emacs Lisp
script:

  #+NAME: posix-logger-wrapper
  #+begin_src sh
    {
      ./emacs-script 2>&1 1>&3 3>&- \
        | logger -t "EMACSCGI" >/dev/null 2>&1 3>&-
    } </dev/null 3>&1
  #+end_src


  #+NAME: bash-logger-wrapper
  #+begin_src sh
    # Using bashʼs process substitution:
    ./emacs-script > >(logger -t "EMACSCGI" >/dev/null 2>&1) </dev/null
  #+end_src


3. run a command line tool like “logger” directly from within Emacs:

  #+NAME: logger-within-emacs
  #+begin_src emacs-lisp
    (setq my/logger (start-process "logger" nil
                                   "logger"
                                   (format "--id=%s" (emacs-pid))
                                   "-t" "EMACSCGI"
                                   "--prio-prefix"))
    ;; <134> corresponds to facility “local0” with severity “info”.
    ;; See description of command line switch “--prio-prefix”.
    (process-send-string my/logger "<134>Hello World.\n")
  #+end_src emacs-lisp


4. write a log file with Emacs (‘append-to-file’, ‘write-file’,
‘write-region’).


Footnotes:
[1]  (info "(elisp) Output Streams")

[2]  Syslog Protocol: <https://datatracker.ietf.org/doc/rfc5424/>

[3]  BSD Syslog Protocol: <https://tools.ietf.org/html/rfc3164>

[4]  Journald Protocol: <https://systemd.io/JOURNAL_NATIVE_PROTOCOL/>


-- 
Felix Dietrich



reply via email to

[Prev in Thread] Current Thread [Next in Thread]