2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
36 static Bool syslog_initialized
= False
;
39 static void syslog_open(const char *prog_name
)
47 openlog(prog_name
, options
, LOG_DAEMON
);
48 syslog_initialized
= True
;
51 static void syslog_message(int prio
, const char *prog_name
, const char *msg
)
53 if (!syslog_initialized
)
54 syslog_open(prog_name
);
56 //jump over the program name cause syslog is already displaying it
57 syslog(prio
, "%s", msg
+ strlen(prog_name
));
60 void w_syslog_close(void)
62 if (syslog_initialized
) {
64 syslog_initialized
= False
;
69 void __wmessage(const char *func
, const char *file
, int line
, int type
, const char *msg
, ...)
73 static int linemax
= 0;
76 int syslog_priority
= LOG_INFO
;
81 linemax
= sysconf(_SC_LINE_MAX
);
83 /* I'd like to know of this ever fires */
84 fprintf(stderr
, "%s %d: sysconf(_SC_LINE_MAX) returned error\n",
88 #else /* !HAVE_SYSCONF */
89 fprintf(stderr
, "%s %d: Your system does not have sysconf(3); "
90 "let wmaker-dev@windowmaker.org know.\n", __FILE__
, __LINE__
);
92 #endif /* HAVE_SYSCONF */
95 buf
= wmalloc(linemax
);
99 /* message format: <wings_progname>(function(file:line): <type?>: <message>"\n" */
100 strncat(buf
, _WINGS_progname
? _WINGS_progname
: "WINGs", linemax
- 1);
101 snprintf(buf
+ strlen(buf
), linemax
- strlen(buf
), "(%s(%s:%d))", func
, file
, line
);
102 strncat(buf
, ": ", linemax
- 1 - strlen(buf
));
105 case WMESSAGE_TYPE_FATAL
:
106 strncat(buf
, _("fatal: "), linemax
- 1 - strlen(buf
));
108 syslog_priority
= LOG_CRIT
;
111 case WMESSAGE_TYPE_ERROR
:
112 strncat(buf
, _("error: "), linemax
- 1 - strlen(buf
));
114 syslog_priority
= LOG_ERR
;
117 case WMESSAGE_TYPE_WARNING
:
118 strncat(buf
, _("warning: "), linemax
- 1 - strlen(buf
));
120 syslog_priority
= LOG_WARNING
;
123 case WMESSAGE_TYPE_MESSAGE
:
125 default: /* should not happen, but doesn't hurt either */
130 if (vsnprintf(buf
+ strlen(buf
), linemax
- strlen(buf
), msg
, args
) >= linemax
- strlen(buf
))
137 syslog_message(syslog_priority
, _WINGS_progname
? _WINGS_progname
: "WINGs", buf
);
141 fputs("*** message truncated ***", stderr
);