/usr/include/Wt/WLogger is in libwt-dev 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WLOGGER_H_
#define WLOGGER_H_
#include <Wt/WDllDefs.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
namespace Wt {
class WLogEntry;
/*! \class WLogger Wt/WLogger Wt/WLogger
* \brief A simple logging class.
*
* This class logs events to a stream in a flexible way. It allows to
* create log files using the commonly used <a
* href="http://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format">Common
* Log Format</a> or <a
* href="http://httpd.apache.org/docs/1.3/logs.html#combined">Combined
* Log Format</a>, but provides a general way for logging entries that
* consists of a fixed number of fields.
*
* It is used by %Wt to create the application log
* (WApplication::log()), and built-in httpd access log.
*
* To use this class for custom logging, you should instantiate a
* logger, add one or more field definitions using addField(), and set
* an output stream using setStream() or setFile(). To stream data to
* the logger, use entry() to start formatting a new entry.
*
* Usage example:
* \code
* // Setup the logger
* Wt::WLogger logger;
* logger.addField("datetime", false);
* logger.addField("session", false);
* logger.addField("type", false);
* logger.addField("message", true);
*
* logger.setFile("/tmp/mylog.txt");
*
* // Add an entry
* Wt::WLogEntry entry = logger.entry();
* entry << Wt::WLogger::timestamp << Wt::WLogger::sep
* << '[' << wApp->sessionId() << ']' << Wt::WLogger::sep
* << '[' << "notice" << ']' << Wt::WLogger::sep
* << "Succesfully started.";
* \endcode
*
* \sa WApplication::log()
*/
class WT_API WLogger
{
public:
/*! \brief Class that indicates a field separator.
*
* \sa sep
*/
struct Sep { };
/*! \brief %Field separator constant.
*
* \sa WLogEntry::operator<<(const WLogger::Sep&)
*/
static const Sep sep;
/*! \brief Class that indicates a time stamp.
*
* \sa timestamp
*/
struct TimeStamp { };
/*! \brief Timestamp field constant.
*
* \sa WLogEntry::operator<<(const WLogger::TimeStamp&)
*/
static const TimeStamp timestamp;
/*! \brief Class that holds the configuration for a single field.
*
* \sa addField()
*/
class Field {
public:
/*! \brief Returns the field name.
*/
std::string name() const { return name_; }
/*! \brief Returns if the field is a quoted string.
*
* String fields can contain white-space, and are therefore quoted
* in the log.
*/
bool isString() const { return string_; }
private:
std::string name_;
bool string_;
Field(const std::string& name, bool isString);
friend class WLogger;
};
/*! \brief Create a new logger.
*/
WLogger();
/*! \brief Destructor.
*/
~WLogger();
/*! \brief Set the output stream.
*
* \sa setFile()
*/
void setStream(std::ostream& o);
/*! \brief Set the output file.
*
* Opens a file output stream for \p path.
*
* \sa setStream()
*/
void setFile(const std::string& path);
/*! \brief Add a field.
*
* Add a field to the logger. When \p isString is \p true, values
* will be quoted.
*/
void addField(const std::string& name, bool isString);
/*! \brief Returns the field list.
*/
const std::vector<Field>& fields() const { return fields_; }
/*! \brief Start a new log entry.
*
* Returns a new entry. The entry is logged in the destructor of
* the entry (i.e. when the entry goes out of scope).
*/
WLogEntry entry() const;
private:
std::ostream* o_;
bool ownStream_;
std::vector<Field> fields_;
void addLine(const std::string& s) const;
friend class WLogEntry;
};
/*! \class WLogEntry Wt/WLogger Wt/WLogger
* \brief A stream-like object for creating an entry in a log file.
*
* This class is returned by WLogger::entry() and creates a log entry using
* a stream-like interface.
*/
class WT_API WLogEntry
{
public:
/*! \brief Copy constructor.
*
* Only the new object can be used, the original object is no longer
* valid.
*/
WLogEntry(const WLogEntry& from);
/*! \brief Destructor.
*/
~WLogEntry();
/*! \brief Writes a field separator.
*
* You must separate fields in a single entry using the WLogger::sep
* constant.
*/
WLogEntry& operator<< (const WLogger::Sep&);
/*! \brief Writes a time stamp in the current field.
*
* Formats a timestamp (date+time) to the current field.
*/
WLogEntry& operator<< (const WLogger::TimeStamp&);
/*! \brief Writes a string in the current field.
*/
WLogEntry& operator<< (const char *);
/*! \brief Writes a string in the current field.
*/
WLogEntry& operator<< (const std::string&);
/*! \brief Writes a number value in the current field.
*/
template <typename T>
WLogEntry& operator<< (T t) {
startField();
impl_->currentLine_ << t;
return *this;
}
private:
struct Impl {
const WLogger& logger_;
std::stringstream currentLine_;
int currentField_;
bool fieldStarted_;
Impl(const WLogger& logger);
bool quote() const;
void finish();
void finishField();
void nextField();
void startField();
};
mutable Impl *impl_;
WLogEntry(const WLogger& logger);
void checkImpl();
void startField();
friend class WLogger;
};
}
#endif // WLOGGER_H_
|