3 This file is taken from nfsim (http://ozlabs.org/~jk/projects/nfsim/)
5 Copyright (c) 2003,2004 Jeremy Kerr & Rusty Russell
7 This file is part of nfsim.
9 nfsim is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 nfsim 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
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with nfsim; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 { LOG_WRITE, "write" },
37 { LOG_VERBOSE, "verbose" },
40 static FILE *logstream;
41 static int typemask = ~LOG_VERBOSE;
43 bool log_line(enum log_type type, const char *format, ...)
50 line = talloc_vasprintf(NULL, format, ap);
53 if (!type || (type & typemask))
54 fprintf(logstream ?: stderr, "%s\n", line);
56 ret = expect_log_hook(line);
61 static void log_partial_v(enum log_type type,
68 int len = strlen(buf);
70 /* write to the end of buffer */
71 if (vsnprintf(buf + len, bufsize - len - 1, format, ap)
73 log_line(LOG_ALWAYS, "log_line_partial buffer is full!");
77 /* print each bit that ends in a newline */
78 for (len = strcspn(ptr, "\n"); *(ptr + len);
79 ptr += len, len = strcspn(ptr, "\n")) {
80 log_line(type, "%.*s", len++, ptr);
83 /* if we've printed, copy any remaining (non-newlined)
84 parts (including the \0) to the front of buf */
85 memmove(buf, ptr, strlen(ptr) + 1);
88 void log_partial(enum log_type type, char *buf, unsigned bufsize,
89 const char *format, ...)
94 log_partial_v(type, buf, bufsize, format, ap);
98 static inline int parsetype(const char *type)
102 for (i = 0; i < ARRAY_SIZE(log_names); i++)
103 if (streq(log_names[i].name, type))
104 return log_names[i].type;
109 static bool log_admin(int argc, char **argv)
115 log_line(LOG_UI, "current log types:", typemask);
117 for (i = 0; i < ARRAY_SIZE(log_names); i++) {
118 if (typemask & log_names[i].type)
119 log_line(LOG_UI, "\t%s", log_names[i].name);
125 log_line(LOG_ALWAYS, "Expected =, + or - then args");
129 for (i = 2; i < argc; i++) {
132 if (!(type = parsetype(argv[i]))) {
133 log_line(LOG_ALWAYS, "no such type %s", argv[i]);
141 typemask = newtypemask;
144 typemask &= ~newtypemask;
147 typemask |= newtypemask;
150 log_line(LOG_ALWAYS, "unknown modifer: %c", *argv[1]);
157 static void log_admin_help(int agc, char **argv)
159 #include "generated-log-help:log"
162 <title><command>log</command></title>
163 <para>Manage logging settings</para>
165 <command>log</command>
167 <arg choice="plain">=</arg>
168 <arg choice="plain">+</arg>
169 <arg choice="plain">-</arg>
171 <arg choice="req"><replaceable>type, ...</replaceable></arg>
173 <para>Each log message is classified into one of the following
178 <para>Normal response from command lines.</para>
184 <para>Logging output from libctdb</para>
191 <para>Messages from ctdbd</para>
197 <para>Messages to ctdbd</para>
203 <para>Verbose debug output</para>
208 <para>The <command>log</command> command allows you to select
209 which messages are displayed. By default, all messages except
210 debug will be shown.</para>
212 <para>Without any arguments, the current logged types are listed.</para>
214 <para>With +, - or = character, those types will be added,
215 removed or set as the current types of messages to be logged
216 (repectively).</para>
218 <para>Messages generated as a result of user input are always
219 logged. </para> </section>
223 static void log_init(void)
228 tui_register_command("log", log_admin, log_admin_help);