swish/commit
Added logging facility from upstream
author | Jan Wielemaker |
---|---|
Mon Mar 16 22:24:33 2015 +0100 | |
committer | Jan Wielemaker |
Mon Mar 16 22:24:33 2015 +0100 | |
commit | 1ee19239d547c7e177eb5ede5c5687124b367bbb |
tree | cf5c0a07636d80b87485033f3a2476971597e19d |
parent | 100a00c08dbe376c906f10044143c0e4268e689d |
Diff style: patch stat
diff --git a/Makefile b/Makefile index 410a2af..b3bef26 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ FONTDIR=web/bower_components/bootstrap/dist/fonts DIRS=lib/swish lib/swish/render web/icons web/help client $(FONTDIR) SWISHLIB=storage.pl page.pl help.pl examples.pl config.pl gitty.pl \ highlight.pl render.pl template_hint.pl search.pl form.pl \ - include.pl csv.pl + include.pl csv.pl logging.pl RENDER=table.pl LIBS= $(addprefix lib/swish/, $(SWISHLIB)) \ $(addprefix lib/swish/render/, $(RENDER)) diff --git a/config-available/swish.pl b/config-available/swish.pl index 418fc61..8aeb017 100644 --- a/config-available/swish.pl +++ b/config-available/swish.pl @@ -19,6 +19,8 @@ user:file_search_path(example, examples). % Load the authentication hook. When loaded, ClioPatria users with admin % rights can use SWISH without sandboxing security :- use_module(library(swish/cp_authenticate)). +% Enable logging of SWISH queries and sources if HTTP logging is enabled +:- use_module(library(swish/logging)). %% cliopatria:menu_item(-Item, -Label) is nondet. % diff --git a/lib/swish/gitty.pl b/lib/swish/gitty.pl index 8768661..8c0932e 100644 --- a/lib/swish/gitty.pl +++ b/lib/swish/gitty.pl @@ -509,7 +509,8 @@ heads_input_stream(Store, Stream) :- create_heads_file(Store) :- call_cleanup( heads_output_stream(Store, Out), - close(Out)). + close(Out)), + fail. % always fail! heads_file(Store, HeadsFile) :- directory_file_path(Store, ref, RefDir), diff --git a/lib/swish/logging.pl b/lib/swish/logging.pl new file mode 100644 index 0000000..f3b2706 --- /dev/null +++ b/lib/swish/logging.pl @@ -0,0 +1,71 @@ +/* Part of SWI-Prolog + + Author: Jan Wielemaker + E-mail: J.Wielemaker@cs.vu.nl + WWW: http://www.swi-prolog.org + Copyright (C): 2015, VU University Amsterdam + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + As a special exception, if you link this library with other files, + compiled with a Free Software compiler, to produce an executable, this + library does not by itself cause the resulting executable to be covered + by the GNU General Public License. This exception does not however + invalidate any other reasons why the executable file might be covered by + the GNU General Public License. +*/ + +:- module(swish_logging, + [ + ]). +:- use_module(library(http/http_log)). +:- use_module(library(broadcast)). +:- use_module(library(settings)). +:- use_module(library(apply)). + +/** <module> Add SWISH query execution to the HTTP log file + +Add a line of the format below to the HTTP log file. The src_text(Text) +option of Options is replaced by `Hash-Text` for the first occurrence +and just `Hash` for subsequent occurrences. + + == + pengine(Time, create(Pengine, Application, Options)) + == +*/ + +:- setting(swish:logging, boolean, true, + "Enable/disable logging of SWISH query execution"). + +:- listen(pengine(Action), swish_log(Action)). + +swish_log(create(Pengine, Application, Options0)) :- + maplist(hash_option, Options0, Options), + get_time(Now), + format_time(string(HDate), '%+', Now), + http_log('/*~s*/ pengine(~3f, ~q).~n', + [HDate, Now, create(Pengine, Application, Options)]). + +:- dynamic + text_hash/2. + +hash_option(src_text(Text), src_text(Result)) :- !, + ( text_hash(Text, Hash) + -> Result = Hash + ; variant_sha1(Text, Hash), + assert(text_hash(Text, Hash)), + Result = Hash-Text + ). +hash_option(Option, Option).