2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,2018,2019,2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declares functionality for initializing logging.
39 * See \ref page_logging for an overview of the functionality.
42 * \ingroup module_utility
44 #ifndef GMX_UTILITY_LOGGERBUILDER_H
45 #define GMX_UTILITY_LOGGERBUILDER_H
50 #include "gromacs/utility/logger.h"
55 class TextOutputStream;
57 class LoggerFormatterBuilder;
60 /*! \libinternal \brief
61 * Initializes loggers.
63 * This class provides methods for specifying logging targets for a logger and
64 * building the logger after all targets have been specified. Having this
65 * separate from the logger allows using different internal data structures
66 * during initialization and operation, and simplifies the responsibilities of
67 * the involved classes.
69 * \ingroup module_utility
78 * Adds a stream to which log output is written.
80 * All output at level \p level or above it is written to \p stream.
81 * The caller is responsible of closing and freeing \p stream once the
82 * logger is discarded.
84 void addTargetStream(MDLogger::LogLevel level, TextOutputStream* stream);
86 * Adds a file to which log output is written.
88 * All output at level \p level or above it is written to \p fp.
89 * The caller is responsible of closing \p fp once the logger is
92 void addTargetFile(MDLogger::LogLevel level, FILE* fp);
95 * Builds the logger with the targets set for this builder.
97 * After this function has been called, the builder can (and should) be
105 std::unique_ptr<Impl> impl_;
108 /*! \libinternal \brief
109 * Manages memory for a logger built with LoggerBuilder.
111 * This class is responsible of managing all memory allocated by LoggerBuilder
112 * that is needed for operation of the actual logger. Also the actual logger
113 * instance is owned by this class. This allows keeping the actual logger simple
116 * This class supports move construction and assignment, which allows
117 * initializing it on the stack and assigning a new instance if the targets
118 * need to be changed.
120 * \ingroup module_utility
125 //! Move-constructs the owner.
126 LoggerOwner(LoggerOwner&& other) noexcept;
129 //! Move-assings the owner.
130 LoggerOwner& operator=(LoggerOwner&& other) noexcept;
132 //! Returns the logger for writing the logs.
133 const MDLogger& logger() const { return *logger_; }
138 LoggerOwner(std::unique_ptr<Impl> impl);
140 std::unique_ptr<Impl> impl_;
141 const MDLogger* logger_;
143 friend class LoggerBuilder;