2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by
7 * the Free Software Foundation with the addition of the following permission
8 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
10 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program; if not, see http://www.gnu.org/licenses or write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
23 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License
30 * version 3, these Appropriate Legal Notices must retain the display of the
31 * "Powered by Funambol" logo. If the display of the logo is not reasonably
32 * feasible for technical reasons, the Appropriate Legal Notices must display
33 * the words "Powered by Funambol".
36 #ifndef INCL_POSIX_LOG
37 # define INCL_POSIX_LOG
40 #include <base/fscapi.h>
42 #include "base/util/StringBuffer.h"
46 #include "base/globalsdef.h"
51 * extended API, can only be used if it is certain that
52 * Log::instance() returns a POSIXLog
54 class POSIXLog : public Log {
61 * Opens the specified file for logging of messages.
63 * By default the LOG instance of the Log class will
64 * create the file specified via its set methods
65 * as soon as the first message needs to be printed or
66 * when explicitly asking for a reset.
68 * By calling this function instead one gets more detailed
69 * control over logging and avoids the (currently) insecurely
70 * implemented handling of file name strings in the Log class.
72 * @param path directory where file is to be created, can be NULL
73 * @param name file name relative to path or "-" when asking for
75 * @param redirectStderr if true, then file descriptor 2 (stderr)
76 * will also be redirected into the log file;
77 * the original stderr is preserved and will be
78 * restored when turning this redirection off
80 virtual void setLogFile(const char *path, const char* name, bool redirectStderr = false);
83 * returns active log file or NULL if none set (e.g. if logging to stdout directly)
85 virtual FILE *getLogFile() { return logFile; }
88 * if a client developer wants to ignore the prefix, he can
89 * derive his own Log implementation from POSIXLog, override this
90 * call and then install his implementation via Log::setLogger()
92 virtual void setPrefix(const char *prefix) { this->prefix = prefix ? prefix : ""; }
93 virtual const StringBuffer &getPrefix() const { return prefix; }
95 virtual void setLogPath(const char* configLogPath);
96 virtual void setLogName(const char* configLogName);
97 virtual void error(const char* msg, ...);
98 virtual void info(const char* msg, ...);
99 virtual void developer(const char* msg, ...);
100 virtual void debug(const char* msg, ...);
101 virtual void reset(const char* title = NULL);
102 virtual size_t getLogSize();
106 * Prints a single line to the current log file.
107 * Can be overridden by derived class to also print
108 * in a different way.
110 * @param firstLine true if this is the first line of a new message
111 * @param time unformatted time stamp for line
112 * @param fullTime a time string including date and GMT offset
113 * @param shortTime a time string including just the local time of day in
114 * the preferred time format according to the current locale
115 * @param utcTime a time string including just the UTC time of day in "hh:mm:ss UTC" format
116 * @param level the severity of the report
117 * @param levelPrefix a string representing the severity (may differ from level, e.g. for Log::developer())
118 * @param line the actual message string
120 virtual void printLine(bool firstLine,
122 const char *fullTime,
123 const char *shortTime,
126 const char *levelPrefix,
132 StringBuffer logName;
133 StringBuffer logPath;
134 bool logRedirectStderr;
136 /** a copy of stderr before it was redirected */
140 * additional prefix for each line
144 void printMessage(LogLevel level, const char* levelPrefix, const char* msg, va_list argList);
147 #define POSIX_LOG ((POSIXLog &)Log::instance())