]>
jfr.im git - irc/thales.git/blob - src/log_worker.c
4b119aa9627e5617abd67b51a6d2e6148628dc4a
1 /* Log worker of GNU Thales. Copyright (C)
2 2012 Free Software Foundation, Inc. This file is part of GNU Thales.
4 GNU Thales is free software; you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 3 of the License, or (at your option) any later
9 GNU Make is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16 #include "log_worker.h"
27 log_worker_process_message(const char *msg
, struct irc_meta
*meta
,
28 struct worker
*embed
, const char *name
)
30 struct log_worker
*logger
= worker_entry(embed
, struct log_worker
, worker
);
31 FILE *stream
= logger
->out_stream
? logger
->out_stream
: stdout
;
33 fprintf(stream
, "[%s]: %s\n", name
, msg
);
38 log_worker_free_worker(struct worker
*embed
)
40 struct log_worker
*logger
= worker_entry(embed
, struct log_worker
, worker
);
42 if (logger
->out_stream
)
43 fclose(logger
->out_stream
);
48 create_log_worker(const struct envz
*env
)
50 struct log_worker
*logger
;
51 const char *output_filename
= envz_get(env
->envz
, env
->envz_len
, "output");
52 FILE *out_stream
= NULL
;
53 if (output_filename
&& !(out_stream
= fopen(output_filename
, "a"))) {
54 fprintf(stderr
, "log worker: specified file `%s' can not be appended\n",
59 logger
= xmalloc(sizeof *logger
);
60 logger
->out_stream
= out_stream
;
61 return &logger
->worker
;