📄 patternformatter.h
字号:
//
// PatternFormatter.h
//
// $Id: //poco/Main/Foundation/include/Foundation/PatternFormatter.h#5 $
//
// Definition of the PatternFormatter class.
//
// Copyright (c) 2004, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Redistributions in any form must be accompanied by information on
// how to obtain complete source code for this software and any
// accompanying software that uses this software. The source code
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Foundation_PatternFormatter_INCLUDED
#define Foundation_PatternFormatter_INCLUDED
#ifndef Foundation_Foundation_INCLUDED
#include "Foundation/Foundation.h"
#endif
#ifndef Foundation_Formatter_INCLUDED
#include "Foundation/Formatter.h"
#endif
#ifndef Foundation_Message_INCLUDED
#include "Foundation/Message.h"
#endif
Foundation_BEGIN
class Foundation_API PatternFormatter: public Formatter
/// This Formatter allows for custom formatting of
/// log messages based on format patterns.
///
/// The format pattern is used as a template to format the message and
/// is copied character by character except for the following special characters,
/// which are replaced by the corresponding value.
///
/// * %s - message source
/// * %t - message text
/// * %l - message priority level (1 .. 7)
/// * %p - message priority (Fatal, Critical, Error, Warning, Notice, Information, Debug, Trace)
/// * %q - abbreviated message priority (F, C, E, W,N, I, D, T)
/// * %P - message process identifier
/// * %T - message thread identifier
/// * %N - node or host name
/// * %w - message date/time abbreviated weekday (Mon, Tue, ...)
/// * %W - message date/time full weekday (Monday, Tuesday, ...)
/// * %b - message date/time abbreviated month (Jan, Feb, ...)
/// * %B - message date/time full month (January, February, ...)
/// * %d - message date/time zero-padded day of month (01 .. 31)
/// * %e - message date/time day of month (1 .. 31)
/// * %f - message date/time space-padded day of month ( 1 .. 31)
/// * %m - message date/time zero-padded month (01 .. 12)
/// * %n - message date/time month (1 .. 12)
/// * %o - message date/time space-padded month ( 1 .. 12)
/// * %y - message date/time year without century (70)
/// * %Y - message date/time year with century (1970)
/// * %H - message date/time hour (00 .. 23)
/// * %h - message date/time hour (00 .. 12)
/// * %a - message date/time am/pm
/// * %A - message date/time AM/PM
/// * %M - message date/time minute (00 .. 59)
/// * %S - message date/time second (00 .. 59)
/// * %i - message date/time millisecond (000 .. 999)
/// * %c - message date/time centisecond (0 .. 9)
/// * %[name] - the value of the message parameter with the given name
/// * %% - percent sign
{
public:
PatternFormatter();
/// Creates a PatternFormatter.
/// The format pattern must be specified with
/// a call to setProperty.
PatternFormatter(const std::string& format);
/// Creates a PatternFormatter that uses the
/// given format pattern.
~PatternFormatter();
/// Destroys the PatternFormatter.
void format(const Message& msg, std::string& text);
/// Formats the message according to the specified
/// format pattern and places the result in text.
void setProperty(const std::string& name, const std::string& value);
/// Sets the property with the given name to the given value.
///
/// The following properties are supported:
///
/// * pattern: The format pattern. See the PatternFormatter class
/// for details.
/// * times: Specifies whether times are adjusted for local time
/// or taken as they are in UTC. Supported values are "local" and "UTC".
///
/// If any other property name is given, a PropertyNotSupported
/// exception is thrown.
std::string getProperty(const std::string& name) const;
/// Returns the value of the property with the given name or
/// throws a PropertyNotSupported exception if the given
/// name is not recognized.
static const std::string PROP_PATTERN;
static const std::string PROP_TIMES;
protected:
static const std::string& getPriorityName(int);
/// Returns a string for the given priority value.
private:
bool _localTime;
std::string _pattern;
};
Foundation_END
#endif // Foundation_PatternFormatter_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -