|
24 | 24 | #include"miscadmin.h"
|
25 | 25 | #include"utils/trace.h"
|
26 | 26 |
|
| 27 | +#include<ctype.h> |
| 28 | + |
| 29 | +#ifdefMULTIBYTE |
| 30 | +#include"mb/pg_wchar.h" |
| 31 | +#endif |
| 32 | + |
27 | 33 | /*
|
28 | 34 | * We could support trace messages of indefinite length, as elog() does,
|
29 | 35 | * but it's probably not worth the trouble. Instead limit trace message
|
@@ -204,16 +210,90 @@ eprintf(const char *fmt,...)
|
204 | 210 | void
|
205 | 211 | write_syslog(intlevel,char*line)
|
206 | 212 | {
|
| 213 | +#ifndefPG_SYSLOG_LIMIT |
| 214 | +#definePG_SYSLOG_LIMIT 128 |
| 215 | +#endif/* PG_SYSLOG_LIMIT */ |
| 216 | + |
207 | 217 | staticintopenlog_done=0;
|
| 218 | +staticcharbuf[PG_SYSLOG_LIMIT+1]; |
| 219 | +staticintlogid=0; |
208 | 220 |
|
209 | 221 | if (UseSyslog >=1)
|
210 | 222 | {
|
| 223 | +intlen=strlen(line); |
| 224 | +intbuflen; |
| 225 | +intseq=0; |
| 226 | +intl; |
| 227 | +inti; |
| 228 | + |
211 | 229 | if (!openlog_done)
|
212 | 230 | {
|
213 | 231 | openlog_done=1;
|
214 | 232 | openlog(PG_LOG_IDENT,LOG_PID |LOG_NDELAY,PG_LOG_FACILITY);
|
215 | 233 | }
|
216 |
| -syslog(level,"%s",line); |
| 234 | + |
| 235 | +/* divide into multiple syslog() calls if message is |
| 236 | + * too long |
| 237 | + */ |
| 238 | +if (len>PG_SYSLOG_LIMIT) |
| 239 | +{ |
| 240 | +logid++; |
| 241 | + |
| 242 | +while (len>0) |
| 243 | +{ |
| 244 | +strncpy(buf,line,PG_SYSLOG_LIMIT); |
| 245 | +buf[PG_SYSLOG_LIMIT]='\0'; |
| 246 | + |
| 247 | +l=strlen(buf); |
| 248 | +#ifdefMULTIBYTE |
| 249 | +/* trim to multibyte letter boundary */ |
| 250 | +buflen=pg_mbcliplen(buf,l,l); |
| 251 | +buf[buflen]='\0'; |
| 252 | +l=strlen(buf); |
| 253 | +#endif |
| 254 | +/* already word boundary? */ |
| 255 | +if (isspace(line[l])||line[l]=='\0') |
| 256 | +{ |
| 257 | +buflen=l; |
| 258 | +} |
| 259 | +else |
| 260 | +{ |
| 261 | +/* try to divide in word boundary */ |
| 262 | +i=l-1; |
| 263 | +while(i>0&& !isspace(buf[i])) |
| 264 | +{ |
| 265 | +i--; |
| 266 | +} |
| 267 | +if (i <=0)/* couldn't divide word boundary */ |
| 268 | +{ |
| 269 | +buflen=l; |
| 270 | +} |
| 271 | +else |
| 272 | +{ |
| 273 | +buflen=i; |
| 274 | +buf[i]='\0'; |
| 275 | +} |
| 276 | +} |
| 277 | + |
| 278 | +seq++; |
| 279 | +/* |
| 280 | + * Here we actually call syslog(). |
| 281 | + * For segmented messages, we add logid |
| 282 | + * (incremented at each write_syslog call), |
| 283 | + * and seq (incremented at each syslog call |
| 284 | + * within a write_syslog call). |
| 285 | + * This will prevent syslog to surpress |
| 286 | + * "same" messages... |
| 287 | + */ |
| 288 | +syslog(level,"[%d-%d] %s",logid,seq,buf); |
| 289 | +line+=buflen; |
| 290 | +len-=buflen; |
| 291 | +} |
| 292 | +} |
| 293 | +else |
| 294 | +{ |
| 295 | +syslog(level,"%s",line); |
| 296 | +} |
217 | 297 | }
|
218 | 298 | }
|
219 | 299 |
|
|