aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 19:15:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 19:15:45 +0000
commitfd52e10228bb147ac1a439bd02f0909c21f36439 (patch)
treea437b868880703dd592965c081d99cee9c3dbadc
parent4a5c88b7a4b94d26665cd840df5467e401dddcbe (diff)
downloadpaludis-fd52e10228bb147ac1a439bd02f0909c21f36439.tar.gz
paludis-fd52e10228bb147ac1a439bd02f0909c21f36439.tar.xz
Messages output handler
-rw-r--r--paludis/environments/paludis/default_output.conf8
-rw-r--r--paludis/environments/paludis/output_managers/Makefile.am8
-rw-r--r--paludis/environments/paludis/output_managers/keep_messages.conf5
-rw-r--r--paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf7
-rw-r--r--paludis/environments/paludis/output_managers/logged.conf5
-rw-r--r--paludis/environments/paludis/output_managers/logged_only.conf4
-rw-r--r--paludis/environments/paludis/output_managers/quiet.conf6
-rw-r--r--paludis/environments/paludis/output_managers/show_messages.conf5
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/messages_to_stdout_output_handler-fwd.hh28
-rw-r--r--paludis/messages_to_stdout_output_handler.cc105
-rw-r--r--paludis/messages_to_stdout_output_handler.hh63
-rw-r--r--paludis/output_manager_factory.cc2
-rw-r--r--paludis/util/discard_output_stream.cc40
-rw-r--r--paludis/util/discard_output_stream.hh59
-rw-r--r--paludis/util/files.m41
16 files changed, 341 insertions, 6 deletions
diff --git a/paludis/environments/paludis/default_output.conf b/paludis/environments/paludis/default_output.conf
index 9c8cf06..7c87df8 100644
--- a/paludis/environments/paludis/default_output.conf
+++ b/paludis/environments/paludis/default_output.conf
@@ -1 +1,9 @@
+# By default, output to stdout, keep logs of messages and keep output logs on
+# failure:
+
type = * : logged
+
+# But if we're being run in the background, display only messages to stdout, and
+# keep logs of messages and keep output logs on failure:
+
+type = * output_exclusivity = background : quiet
diff --git a/paludis/environments/paludis/output_managers/Makefile.am b/paludis/environments/paludis/output_managers/Makefile.am
index ed7a080..5137a58 100644
--- a/paludis/environments/paludis/output_managers/Makefile.am
+++ b/paludis/environments/paludis/output_managers/Makefile.am
@@ -12,9 +12,13 @@ DEFS= \
shareenvpaludisdir = $(sharedir)/paludis/environments/paludis/output_managers
dist_shareenvpaludis_DATA = \
- standard.conf \
+ keep_messages.conf \
+ keep_stdout_as_messages.conf \
logged.conf \
- logged_only.conf
+ logged_only.conf \
+ quiet.conf \
+ show_messages.conf \
+ standard.conf
logdir = /var/log/paludis
diff --git a/paludis/environments/paludis/output_managers/keep_messages.conf b/paludis/environments/paludis/output_managers/keep_messages.conf
new file mode 100644
index 0000000..9271243
--- /dev/null
+++ b/paludis/environments/paludis/output_managers/keep_messages.conf
@@ -0,0 +1,5 @@
+# Keep message logs
+
+handler = messages_to_stdout
+child = keep_stdout_as_messages
+
diff --git a/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf b/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf
new file mode 100644
index 0000000..67a2787
--- /dev/null
+++ b/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf
@@ -0,0 +1,7 @@
+# Keep message logs. For use by keep_messages; do not use directly.
+
+handler = file
+stdout = /var/log/paludis/%{time}-%{action}-%{id}.messages
+stderr = ${stdout}
+keep_on_success = true
+
diff --git a/paludis/environments/paludis/output_managers/logged.conf b/paludis/environments/paludis/output_managers/logged.conf
index 338d31b..bf7a5ba 100644
--- a/paludis/environments/paludis/output_managers/logged.conf
+++ b/paludis/environments/paludis/output_managers/logged.conf
@@ -1,5 +1,6 @@
-# Sends output to both standard and logged_only.
+# Output to stdout / stderr, keep logs of messages and keep output logs on
+# failure.
handler = tee
-children = standard logged_only
+children = standard logged_only keep_messages
diff --git a/paludis/environments/paludis/output_managers/logged_only.conf b/paludis/environments/paludis/output_managers/logged_only.conf
index 5884ea3..b8c8a0f 100644
--- a/paludis/environments/paludis/output_managers/logged_only.conf
+++ b/paludis/environments/paludis/output_managers/logged_only.conf
@@ -1,5 +1,5 @@
-# This output handler keeps logs in /var/log/paludis/, but removes them on
-# success.
+# Keep logs of output only, and discard on success. Used by logged and quiet,
+# but may be directly useful.
handler = file
stdout = /var/log/paludis/%{time}-%{action}-%{id}.out
diff --git a/paludis/environments/paludis/output_managers/quiet.conf b/paludis/environments/paludis/output_managers/quiet.conf
new file mode 100644
index 0000000..8998124
--- /dev/null
+++ b/paludis/environments/paludis/output_managers/quiet.conf
@@ -0,0 +1,6 @@
+# Messages only to stdout / stderr, keep logs of messages and keep output logs
+# on failure.
+
+handler = tee
+children = logged_only show_messages keep_messages
+
diff --git a/paludis/environments/paludis/output_managers/show_messages.conf b/paludis/environments/paludis/output_managers/show_messages.conf
new file mode 100644
index 0000000..a6981b0
--- /dev/null
+++ b/paludis/environments/paludis/output_managers/show_messages.conf
@@ -0,0 +1,5 @@
+# Show messages only.
+
+handler = messages_to_stdout
+child = standard
+
diff --git a/paludis/files.m4 b/paludis/files.m4
index 61a1b69..a3492e8 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -49,6 +49,7 @@ add(`mask', `hh', `cc', `fwd', `se')
add(`match_package', `hh', `cc', `se', `fwd')
add(`merger', `hh', `cc', `fwd', `se', `test', `testscript')
add(`merger_entry_type', `hh', `cc', `se')
+add(`messages_to_stdout_output_handler', `hh', `cc', `fwd')
add(`metadata_key', `hh', `cc', `se', `fwd')
add(`metadata_key_holder', `hh', `cc', `fwd')
add(`name', `hh', `cc', `fwd', `test')
diff --git a/paludis/messages_to_stdout_output_handler-fwd.hh b/paludis/messages_to_stdout_output_handler-fwd.hh
new file mode 100644
index 0000000..9e2ec56
--- /dev/null
+++ b/paludis/messages_to_stdout_output_handler-fwd.hh
@@ -0,0 +1,28 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_MESSAGES_TO_STDOUT_OUTPUT_HANDLER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_MESSAGES_TO_STDOUT_OUTPUT_HANDLER_FWD_HH 1
+
+namespace paludis
+{
+ struct MessagesToStdoutOutputManager;
+}
+
+#endif
diff --git a/paludis/messages_to_stdout_output_handler.cc b/paludis/messages_to_stdout_output_handler.cc
new file mode 100644
index 0000000..0a83359
--- /dev/null
+++ b/paludis/messages_to_stdout_output_handler.cc
@@ -0,0 +1,105 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/messages_to_stdout_output_handler.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/discard_output_stream.hh>
+#include <paludis/util/sequence-impl.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/exception.hh>
+#include <sstream>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<MessagesToStdoutOutputManager>
+ {
+ DiscardOutputStream output_stream;
+ const std::tr1::shared_ptr<OutputManager> child;
+
+ Implementation(const std::tr1::shared_ptr<OutputManager> & c) :
+ child(c)
+ {
+ }
+ };
+}
+
+MessagesToStdoutOutputManager::MessagesToStdoutOutputManager(
+ const std::tr1::shared_ptr<OutputManager> & s) :
+ PrivateImplementationPattern<MessagesToStdoutOutputManager>(new Implementation<MessagesToStdoutOutputManager>(s))
+{
+}
+
+MessagesToStdoutOutputManager::~MessagesToStdoutOutputManager()
+{
+}
+
+std::ostream &
+MessagesToStdoutOutputManager::stdout_stream()
+{
+ return _imp->output_stream;
+}
+
+std::ostream &
+MessagesToStdoutOutputManager::stderr_stream()
+{
+ return _imp->output_stream;
+}
+
+void
+MessagesToStdoutOutputManager::succeeded()
+{
+ _imp->child->succeeded();
+}
+
+void
+MessagesToStdoutOutputManager::message(const MessageType t, const std::string & s)
+{
+ std::ostringstream m;
+ m << t << " " << s << std::endl;
+ _imp->child->stdout_stream() << m.str();
+}
+
+const std::tr1::shared_ptr<const Set<std::string> >
+MessagesToStdoutOutputManager::factory_managers()
+{
+ std::tr1::shared_ptr<Set<std::string> > result(new Set<std::string>);
+ result->insert("messages_to_stdout");
+ return result;
+}
+
+const std::tr1::shared_ptr<OutputManager>
+MessagesToStdoutOutputManager::factory_create(
+ const OutputManagerFactory::KeyFunction & key_func,
+ const OutputManagerFactory::CreateChildFunction & create_child,
+ const OutputManagerFactory::ReplaceVarsFunc &)
+{
+ std::string child(key_func("child"));
+ if (child.empty())
+ throw ConfigurationError("No child specified for MessagesToStdoutOutputManager");
+
+ return make_shared_ptr(new MessagesToStdoutOutputManager(create_child(child)));
+}
+
+template class PrivateImplementationPattern<MessagesToStdoutOutputManager>;
+
diff --git a/paludis/messages_to_stdout_output_handler.hh b/paludis/messages_to_stdout_output_handler.hh
new file mode 100644
index 0000000..3766f9e
--- /dev/null
+++ b/paludis/messages_to_stdout_output_handler.hh
@@ -0,0 +1,63 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_MESSAGES_TO_STDOUT_OUTPUT_HANDLER_HH
+#define PALUDIS_GUARD_PALUDIS_MESSAGES_TO_STDOUT_OUTPUT_HANDLER_HH 1
+
+#include <paludis/messages_to_stdout_output_handler-fwd.hh>
+#include <paludis/output_manager.hh>
+#include <paludis/output_manager_factory.hh>
+#include <paludis/util/set-fwd.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+#include <tr1/memory>
+#include <tr1/functional>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE MessagesToStdoutOutputManager :
+ private PrivateImplementationPattern<MessagesToStdoutOutputManager>,
+ public OutputManager
+ {
+ public:
+ MessagesToStdoutOutputManager(const std::tr1::shared_ptr<OutputManager> &);
+ ~MessagesToStdoutOutputManager();
+
+ virtual std::ostream & stdout_stream() PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::ostream & stderr_stream() PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual void succeeded();
+ virtual void message(const MessageType, const std::string &);
+
+ static const std::tr1::shared_ptr<const Set<std::string> > factory_managers()
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ static const std::tr1::shared_ptr<OutputManager> factory_create(
+ const OutputManagerFactory::KeyFunction &,
+ const OutputManagerFactory::CreateChildFunction &,
+ const OutputManagerFactory::ReplaceVarsFunc &)
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
+ extern template class PrivateImplementationPattern<MessagesToStdoutOutputManager>;
+#endif
+}
+
+#endif
diff --git a/paludis/output_manager_factory.cc b/paludis/output_manager_factory.cc
index 1afed72..c5ad781 100644
--- a/paludis/output_manager_factory.cc
+++ b/paludis/output_manager_factory.cc
@@ -35,6 +35,7 @@
#include <list>
#include <paludis/file_output_manager.hh>
+#include <paludis/messages_to_stdout_output_handler.hh>
#include <paludis/standard_output_manager.hh>
#include <paludis/tee_output_manager.hh>
@@ -86,6 +87,7 @@ OutputManagerFactory::OutputManagerFactory() :
{
/* we might want to make this plugin loadable at some point */
add_manager(FileOutputManager::factory_managers(), FileOutputManager::factory_create);
+ add_manager(MessagesToStdoutOutputManager::factory_managers(), MessagesToStdoutOutputManager::factory_create);
add_manager(StandardOutputManager::factory_managers(), StandardOutputManager::factory_create);
add_manager(TeeOutputManager::factory_managers(), TeeOutputManager::factory_create);
}
diff --git a/paludis/util/discard_output_stream.cc b/paludis/util/discard_output_stream.cc
new file mode 100644
index 0000000..7386ee7
--- /dev/null
+++ b/paludis/util/discard_output_stream.cc
@@ -0,0 +1,40 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/util/discard_output_stream.hh>
+
+using namespace paludis;
+
+DiscardOutputStream::DiscardOutputStream() :
+ std::ostream(&buf)
+{
+}
+
+DiscardOutputStreamBuf::int_type
+DiscardOutputStreamBuf::overflow(int_type c)
+{
+ return c;
+}
+
+std::streamsize
+DiscardOutputStreamBuf::xsputn(const char *, std::streamsize num)
+{
+ return num;
+}
+
diff --git a/paludis/util/discard_output_stream.hh b/paludis/util/discard_output_stream.hh
new file mode 100644
index 0000000..a0577f8
--- /dev/null
+++ b/paludis/util/discard_output_stream.hh
@@ -0,0 +1,59 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_UTIL_DISCARD_OUTPUT_STREAM_HH
+#define PALUDIS_GUARD_PALUDIS_UTIL_DISCARD_OUTPUT_STREAM_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <ostream>
+
+namespace paludis
+{
+ class PALUDIS_VISIBLE DiscardOutputStreamBuf :
+ public std::streambuf
+ {
+ protected:
+ virtual int_type
+ overflow(int_type c);
+
+ virtual std::streamsize
+ xsputn(const char * s, std::streamsize num);
+ };
+
+ class PALUDIS_VISIBLE DiscardOutputStreamBase
+ {
+ protected:
+ DiscardOutputStreamBuf buf;
+ };
+
+ class PALUDIS_VISIBLE DiscardOutputStream :
+ protected DiscardOutputStreamBase,
+ public std::ostream
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ DiscardOutputStream();
+
+ ///\}
+ };
+}
+
+#endif
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index b4faa42..23d58fa 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -22,6 +22,7 @@ add(`damerau_levenshtein', `hh', `cc', `test')
add(`destringify', `hh', `cc', `test')
add(`deferred_construction_ptr', `hh', `cc', `fwd', `test')
add(`dir_iterator', `hh', `cc', `fwd', `se', `test', `testscript')
+add(`discard_output_stream', `hh', `cc')
add(`exception', `hh', `cc')
add(`fast_unique_copy', `hh', `test')
add(`forward_parallel_for_each', `hh', `test')