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
;
77 const char *syslog_prefix
= "INFO";
82 linemax
= sysconf(_SC_LINE_MAX
);
84 /* I'd like to know of this ever fires */
85 fprintf(stderr
, "%s %d: sysconf(_SC_LINE_MAX) returned error\n",
89 #else /* !HAVE_SYSCONF */
90 fprintf(stderr
, "%s %d: Your system does not have sysconf(3); "
91 "let wmaker-dev@windowmaker.org know.\n", __FILE__
, __LINE__
);
93 #endif /* HAVE_SYSCONF */
96 buf
= wmalloc(linemax
);
100 /* message format: <wings_progname>(function(file:line): <type?>: <message>"\n" */
101 strncat(buf
, _WINGS_progname
? _WINGS_progname
: "WINGs", linemax
- 1);
102 snprintf(buf
+ strlen(buf
), linemax
- strlen(buf
), "(%s(%s:%d))", func
, file
, line
);
103 strncat(buf
, ": ", linemax
- 1 - strlen(buf
));
106 case WMESSAGE_TYPE_FATAL
:
107 strncat(buf
, _("fatal: "), linemax
- 1 - strlen(buf
));
109 syslog_priority
= LOG_CRIT
;
110 syslog_prefix
= "FATAL";
113 case WMESSAGE_TYPE_ERROR
:
114 strncat(buf
, _("error: "), linemax
- 1 - strlen(buf
));
116 syslog_priority
= LOG_ERR
;
117 syslog_prefix
= "ERROR";
120 case WMESSAGE_TYPE_WARNING
:
121 strncat(buf
, _("warning: "), linemax
- 1 - strlen(buf
));
123 syslog_priority
= LOG_WARNING
;
124 syslog_prefix
= "WARNING";
127 case WMESSAGE_TYPE_MESSAGE
:
129 default: /* should not happen, but doesn't hurt either */
134 if (vsnprintf(buf
+ strlen(buf
), linemax
- strlen(buf
), msg
, args
) >= linemax
- strlen(buf
))
141 syslog_message(syslog_priority
, _WINGS_progname
? _WINGS_progname
: "WINGs", buf
);
145 fputs("*** message truncated ***", stderr
);