From 81e0c4dbba7aae4b8ec8b2f140361283dc66677d Mon Sep 17 00:00:00 2001
From: David Hummel <6109326+hummeltech@users.noreply.github.com>
Date: Thu, 3 Dec 2020 14:48:26 -0700
Subject: [PATCH] Logging Improvements
* Using [`GLib Logging Framework`](https://developer.gnome.org/programming-guidelines/stable/logging.html.en) for logging
* Created new `g_logger` function for logging
* Outputs to `stdout`/`stderr` only when running in `foreground`
* `stderr` for `message`, `warning`, `critical` & `error` levels
* `stdout` for `debug` & `info` levels
* Use `G_MESSAGES_DEBUG=all` environment to enable `debug` to print
* Otherwise, output will be to `syslog` or `systemd journal` (when appropriate)
* Standardized usage of `{LOG_PRIORITY}: ` prefix in log messages
* Only when using `syslog`, otherwise `GLib Logging` will take care of it
* Changed `fprintf(stderr`, `printf` & `perror` calls to `g_logger` calls
* You might want to check them out closely to make sure I chose the right levels
* No changes to `logging/output` were made to "`foreground`" programs (I.E. `render_*`)
* Changed `0`,`1` to `no_argument`,`required_argument` in `getopt_long`'s `long_options`
* Fixed `renderd`'s `foreground` opt (should be `no_argument` [0] rather than `reguired_argument` [1])
* Basic test for `mod_tile` module
* ~~Extended `renderd` log priority onto Mapnik's logger~~
---
.dockerignore | 62 ++++++++
.gitignore | 28 ++--
.travis.yml | 13 +-
Dockerfile | 38 +++++
Makefile.am | 34 +++--
README.rst | 8 +-
configure.ac | 11 +-
includes/g_logger.h | 35 +++++
includes/store.h | 7 -
src/cache_expire.c | 9 +-
src/daemon.c | 282 ++++++++++++++++++-------------------
src/g_logger.c | 142 +++++++++++++++++++
src/gen_tile.cpp | 66 ++++-----
src/gen_tile_test.cpp | 1 -
src/metatile.cpp | 10 +-
src/mod_tile.c | 3 +-
src/parameterize_style.cpp | 9 +-
src/protocol_helper.c | 24 ++--
src/render_expired.c | 24 ++--
src/render_list.c | 32 +++--
src/render_old.c | 24 ++--
src/request_queue.c | 11 +-
src/speedtest.cpp | 12 +-
src/store.c | 59 ++------
src/store_file.c | 11 +-
src/store_file_utils.c | 13 +-
src/store_memcached.c | 9 +-
src/store_null.c | 4 +-
src/store_rados.c | 35 ++---
src/store_ro_composite.c | 25 ++--
src/store_ro_http_proxy.c | 37 ++---
src/sys_utils.c | 4 +-
32 files changed, 678 insertions(+), 404 deletions(-)
create mode 100644 .dockerignore
create mode 100644 Dockerfile
create mode 100644 includes/g_logger.h
create mode 100644 src/g_logger.c
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..bb54e185
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,62 @@
+Dockerfile
+
+.git
+
+_libs
+.deps/
+.dirstamp
+.libs
+.libs/
+*.la
+*.lo
+*.o
+*.slo
+*.tab.c
+aclocal.m4
+autom4te.cache/*
+compile
+config.cache
+config.guess
+config.guess~
+config.h
+config.h.in
+config.h.in~
+config.log
+config.lt
+config.status
+config.status.lineno
+config.sub
+config.sub~
+configure
+configure.lineno
+configure~
+depcomp
+gen_tile_test
+includes/config.h
+includes/stamp-h1
+install-sh
+libtool
+ltmain.sh
+m4/libtool.m4
+m4/lt~obsolete.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4
+Makefile
+Makefile.in
+missing
+mod_tile.la
+render_expired
+render_list
+render_old
+render_speedtest
+renderd
+renderd.sock
+renderd.stats
+src/.libs/*
+src/*.la
+src/*.lo
+src/*.o
+src/*.slo
+stamp-h1
+stderr.out
diff --git a/.gitignore b/.gitignore
index 156d366b..a45f0875 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,36 +1,42 @@
-Makefile*
-*.o
+.deps/
+.dirstamp
+.libs/
*.la
*.lo
+*.o
*.slo
-.dirstamp
-.deps/
-.libs/
+aclocal.m4
autom4te.cache/
compile
config.guess
+config.guess~
config.h
config.h.in
config.h.in~
config.log
config.status
config.sub
+config.sub~
configure
+configure~
depcomp
gen_tile_test
install-sh
libtool
ltmain.sh
+m4/libtool.m4
+m4/lt~obsolete.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4
+Makefile*
missing
render_expired
render_list
render_old
render_speedtest
renderd
+renderd.sock
+renderd.stats
stamp-h1
-aclocal.m4
-m4/libtool.m4
-m4/ltoptions.m4
-m4/ltsugar.m4
-m4/ltversion.m4
-m4/lt~obsolete.m4
+stderr.out
diff --git a/.travis.yml b/.travis.yml
index 330d19c4..3d03ecb0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,13 @@
+---
dist: focal
language: cpp
compiler:
- clang
+services:
+ - docker
+
before_install:
- sudo apt update -y
@@ -23,9 +27,16 @@ jobs:
fi
- stage: tests
install:
- - sudo apt -y install apache2-dev libcairo2-dev libcurl4-gnutls-dev libiniparser-dev libmapnik-dev
+ - sudo apt -y install apache2-dev libcairo2-dev libcurl4-gnutls-dev libglib2.0-dev libiniparser-dev libmapnik-dev
script:
- ./autogen.sh
- ./configure
- make
- make test
+ - stage: mod_tile test
+ install:
+ - docker build -t mod_tile .
+ - docker run --detach --publish 8080:80 mod_tile
+ script:
+ - docker run --rm --entrypoint /bin/bash mod_tile -c "make test"
+ - curl --silent http://localhost:8080/renderd-example/tiles/9/297/191.png | sha256sum - | grep dbf26531286e844a3a9735cdd193598dca78d22f77cafe5824bcaf17f88cbb08
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..f963cfc9
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,38 @@
+FROM ubuntu:focal
+EXPOSE 80
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update --yes \
+ && apt-get install --yes \
+ apache2 apache2-dev \
+ build-essential curl libcairo2-dev \
+ libcurl4-gnutls-dev libglib2.0-dev \
+ libiniparser-dev libmapnik-dev \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /usr/src/mod_tile
+
+COPY . ${PWD}
+
+RUN ./autogen.sh \
+ && ./configure --bindir=/usr/bin \
+ && make \
+ && make install \
+ && make install-mod_tile
+
+RUN ln -s "${PWD}/examples/config/renderd/renderd.conf.dist" /etc/renderd.conf \
+ && mkdir -p /run/renderd /var/cache/renderd/tiles
+
+RUN mkdir -p examples/example-map/leaflet \
+ && curl "https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" > examples/example-map/leaflet/leaflet.min.js \
+ && curl "https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" > examples/example-map/leaflet/leaflet.css \
+ && ln -s "${PWD}/examples/example-map" /var/www/ \
+ && ln -s "${PWD}/examples/config/apache2/renderd.conf.dist" /etc/apache2/conf-enabled/renderd.conf \
+ && ln -s "${PWD}/examples/config/apache2/renderd-example-map.conf.dist" /etc/apache2/conf-enabled/renderd-example-map.conf \
+ && echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" > /etc/apache2/mods-enabled/mod_tile.load
+
+RUN printf "#!/bin/bash\nrenderd\nexec apache2ctl -D FOREGROUND" > /docker-entrypoint.sh \
+ && chmod +x /docker-entrypoint.sh
+
+ENTRYPOINT ["/docker-entrypoint.sh"]
diff --git a/Makefile.am b/Makefile.am
index 9047d31a..45a9153f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
-AM_CPPFLAGS = $(PTHREAD_CFLAGS)
+AM_CPPFLAGS = $(PTHREAD_CFLAGS) $(GLIB_CFLAGS)
STORE_SOURCES = \
src/store.c \
@@ -12,8 +12,9 @@ STORE_SOURCES = \
src/store_rados.c \
src/store_ro_http_proxy.c \
src/store_ro_composite.c \
- src/store_null.c
-STORE_LDFLAGS = $(LIBMEMCACHED_LDFLAGS) $(LIBRADOS_LDFLAGS) $(LIBCURL)
+ src/store_null.c \
+ src/g_logger.c
+STORE_LDFLAGS = $(LIBMEMCACHED_LDFLAGS) $(LIBRADOS_LDFLAGS) $(LIBCURL) $(GLIB_LIBS)
STORE_CPPFLAGS =
@@ -53,14 +54,16 @@ render_speedtest_SOURCES = \
src/speedtest.cpp \
src/protocol_helper.c \
src/render_submit_queue.c \
- src/sys_utils.c
-render_speedtest_LDADD = $(PTHREAD_CFLAGS)
+ src/sys_utils.c \
+ src/g_logger.c
+render_speedtest_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS)
render_list_SOURCES = \
src/render_list.c \
src/sys_utils.c \
src/protocol_helper.c \
- src/render_submit_queue.c $(STORE_SOURCES)
+ src/render_submit_queue.c \
+ $(STORE_SOURCES)
render_list_LDADD = $(PTHREAD_CFLAGS) $(STORE_LDFLAGS)
render_expired_SOURCES = \
@@ -76,8 +79,9 @@ render_old_SOURCES = \
src/render_old.c \
src/sys_utils.c \
src/protocol_helper.c \
- src/render_submit_queue.c
-render_old_LDADD = $(PTHREAD_CFLAGS)
+ src/render_submit_queue.c \
+ src/g_logger.c
+render_old_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS)
#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c
@@ -93,7 +97,7 @@ gen_tile_test_SOURCES = \
src/cache_expire.c \
src/parameterize_style.cpp \
$(STORE_SOURCES)
-gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED $(PTHREAD_CFLAGS)
+gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED $(PTHREAD_CFLAGS) $(GLIB_CFLAGS)
gen_tile_test_CXXFLAGS = $(MAPNIK_CFLAGS)
gen_tile_test_LDADD = $(PTHREAD_CFLAGS) $(MAPNIK_LDFLAGS) $(STORE_LDFLAGS) -liniparser
@@ -103,7 +107,7 @@ test: gen_tile_test
./gen_tile_test
all-local:
- $(APXS) -c $(DEF_LDLIBS) $(AM_CFLAGS) \
+ $(APXS) -c $(DEF_LDLIBS) $(AM_CFLAGS) $(GLIB_CFLAGS) \
-I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) \
@srcdir@/src/mod_tile.c \
@srcdir@/src/sys_utils.c \
@@ -114,12 +118,13 @@ all-local:
@srcdir@/src/store_rados.c \
@srcdir@/src/store_ro_http_proxy.c \
@srcdir@/src/store_ro_composite.c \
- @srcdir@/src/store_null.c
+ @srcdir@/src/store_null.c \
+ @srcdir@/src/g_logger.c
-install-mod_tile:
+install-mod_tile:
mkdir -p $(DESTDIR)`$(APXS) -q LIBEXECDIR`
$(APXS) -S LIBEXECDIR=$(DESTDIR)`$(APXS) \
- -q LIBEXECDIR` -c -i $(DEF_LDLIBS) $(AM_CFLAGS) \
+ -q LIBEXECDIR` -c -i $(DEF_LDLIBS) $(AM_CFLAGS) $(GLIB_CFLAGS) \
-I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) \
@srcdir@/src/mod_tile.c \
@srcdir@/src/sys_utils.c \
@@ -130,4 +135,5 @@ install-mod_tile:
@srcdir@/src/store_rados.c \
@srcdir@/src/store_ro_http_proxy.c \
@srcdir@/src/store_ro_composite.c \
- @srcdir@/src/store_null.c
+ @srcdir@/src/store_null.c \
+ @srcdir@/src/g_logger.c
diff --git a/README.rst b/README.rst
index e79178ec..57d01edb 100644
--- a/README.rst
+++ b/README.rst
@@ -27,6 +27,7 @@ Requirements
* `Cairo 2D graphics library `__
* `Curl library (SSL variant) `__
* `Iniparser library `__
+* `GLib library `__
Compilation
-----------
@@ -42,6 +43,7 @@ slightly.
apache2-dev \
libcairo2-dev \
libcurl4-gnutls-dev \
+ libglib2.0-dev \
libiniparser-dev \
libmapnik-dev
@@ -64,7 +66,7 @@ Packages
If you don't want to compile the software yourself. Precompiled
software packages for **Debian** and **Ubuntu** are being maintained by
-the `Debian GIS Team `__ in the respective
+the `Debian GIS Team `__ in the respective
`repository `__.
They are in the pipeline and expected to be included in the next releases of
those two distributions.
@@ -127,7 +129,7 @@ Restart apache2:
$ sudo a2enconf renderd
-And run the rendering daemon
+And run the rendering daemon
::
@@ -161,7 +163,7 @@ probably see a 404 error. Wait for the disk activity to
cease and then reload the tile. With a bit of luck you
should see a tile of the world in your browser window.
-If this fails to happen check the http error log. You can
+If this fails to happen check the http error log. You can
increase the level of debugging using the LogLevel apache
directive. If no log messages are shown check that you
are accessing the correct virtual host - the new version
diff --git a/configure.ac b/configure.ac
index 5a572eb2..7d173c2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,14 +15,15 @@ AC_PROG_CXX
AC_PROG_CC
AC_PROG_CC_C99
-dnl Find C++ compiler
-AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
-if test "$HAVE_CXX" = "no"
-then
- AC_MSG_ERROR([Could not find a c++ compiler]);
+dnl Find C++ compiler
+AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
+if test "$HAVE_CXX" = "no"
+then
+ AC_MSG_ERROR([Could not find a c++ compiler]);
fi
# Checks for libraries.
+PKG_CHECK_MODULES([GLIB], [glib-2.0])
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h utime.h paths.h sys/cdefs.h sys/loadavg.h])
diff --git a/includes/g_logger.h b/includes/g_logger.h
new file mode 100644
index 00000000..d35bee39
--- /dev/null
+++ b/includes/g_logger.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007 - 2020 by mod_tile contributors (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see http://www.gnu.org/licenses/.
+ */
+
+#ifndef GLOGGER_H
+#define GLOGGER_H
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void g_logger(int log_level, const char *format, ...);
+
+const char *g_logger_level_name(int log_level);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/includes/store.h b/includes/store.h
index be8c3e45..ae1b1061 100644
--- a/includes/store.h
+++ b/includes/store.h
@@ -26,11 +26,6 @@ extern "C" {
#include
#include "render_config.h"
-#define STORE_LOGLVL_DEBUG 0
-#define STORE_LOGLVL_INFO 1
-#define STORE_LOGLVL_WARNING 2
-#define STORE_LOGLVL_ERR 3
-
struct stat_info {
off_t size; /* total size, in bytes */
time_t atime; /* time of last access */
@@ -51,8 +46,6 @@ struct storage_backend {
void * storage_ctx;
};
-void log_message(int log_lvl, const char *format, ...);
-
struct storage_backend * init_storage_backend(const char * options);
#ifdef __cplusplus
diff --git a/src/cache_expire.c b/src/cache_expire.c
index c386fd06..057adea3 100644
--- a/src/cache_expire.c
+++ b/src/cache_expire.c
@@ -16,7 +16,6 @@
*/
#include
-#include
#include
#include
#include
@@ -24,6 +23,7 @@
#include
#include "cache_expire.h"
+#include "g_logger.h"
/**
* This function sends a HTCP cache clr request for a given
* URL.
@@ -101,7 +101,7 @@ static void cache_expire_url(int sock, char * url)
*((uint16_t *)(&buf[idx])) = htons(0);
if (send(sock, (void *) buf, (12 + 22 + url_len), 0) < (12 + 22 + url_len)) {
- syslog(LOG_ERR, "Failed to send HTCP purge for %s\n", url);
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to send HTCP purge for %s", url);
};
free(buf);
@@ -137,7 +137,7 @@ int init_cache_expire(char * htcphost)
s = getaddrinfo(htcphost, HTCP_EXPIRE_CACHE_PORT, &hints, &result);
if (s != 0) {
- syslog(LOG_ERR, "Failed to lookup HTCP cache host: %s", gai_strerror(s));
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to lookup HTCP cache host: %s", gai_strerror(s));
return -1;
}
@@ -161,7 +161,7 @@ int init_cache_expire(char * htcphost)
}
if (rp == NULL) { /* No address succeeded */
- syslog(LOG_ERR, "Failed to create HTCP cache socket");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to create HTCP cache socket");
return -1;
}
@@ -170,4 +170,3 @@ int init_cache_expire(char * htcphost)
return sfd;
}
-
diff --git a/src/daemon.c b/src/daemon.c
index 0aa25223..8858f3f3 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -32,7 +32,6 @@
#include
#include
#include
-#include
#include
#include "render_config.h"
@@ -41,6 +40,7 @@
#include "protocol.h"
#include "protocol_helper.h"
#include "request_queue.h"
+#include "g_logger.h"
// extern "C" {
#include
@@ -65,6 +65,8 @@ static renderd_config config;
int noSlaveRenders;
+int foreground = 0;
+
struct request_queue * render_request_queue;
static const char *cmdStr(enum protoCmd c)
@@ -114,7 +116,7 @@ void send_response(struct item *item, enum protoCmd rsp, int render_time)
if ((item->fd != FD_INVALID) && ((req->cmd == cmdRender) || (req->cmd == cmdRenderPrio) || (req->cmd == cmdRenderLow) || (req->cmd == cmdRenderBulk))) {
req->cmd = rsp;
- //fprintf(stderr, "Sending message %s to %d\n", cmdStr(rsp), item->fd);
+ g_logger(G_LOG_LEVEL_DEBUG, "Sending message %s to %d", cmdStr(rsp), item->fd);
send_cmd(req, item->fd);
@@ -139,23 +141,23 @@ enum protoCmd rx_request(struct protocol *req, int fd)
strcpy(req->mimetype, "image/png");
strcpy(req->options, "");
} else if (req->ver != 3) {
- syslog(LOG_ERR, "Bad protocol version %d", req->ver);
+ g_logger(G_LOG_LEVEL_ERROR, "Bad protocol version %d", req->ver);
return cmdNotDone;
}
- syslog(LOG_DEBUG, "DEBUG: Got command %s fd(%d) xml(%s), z(%d), x(%d), y(%d), mime(%s), options(%s)",
- cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y, req->mimetype, req->options);
+ g_logger(G_LOG_LEVEL_DEBUG, "Got command %s fd(%d) xml(%s), z(%d), x(%d), y(%d), mime(%s), options(%s)",
+ cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y, req->mimetype, req->options);
if ((req->cmd != cmdRender) && (req->cmd != cmdRenderPrio) && (req->cmd != cmdRenderLow) && (req->cmd != cmdDirty) && (req->cmd != cmdRenderBulk)) {
- syslog(LOG_WARNING, "WARNING: Ignoring unknown command %s fd(%d) xml(%s), z(%d), x(%d), y(%d)",
- cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y);
+ g_logger(G_LOG_LEVEL_WARNING, "Ignoring unknown command %s fd(%d) xml(%s), z(%d), x(%d), y(%d)",
+ cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y);
return cmdNotDone;
}
item = (struct item *)malloc(sizeof(*item));
if (!item) {
- syslog(LOG_ERR, "malloc failed");
+ g_logger(G_LOG_LEVEL_ERROR, "malloc failed");
return cmdNotDone;
}
@@ -184,7 +186,7 @@ void request_exit(void)
char c = 0;
if (write(exit_pipe_fd, &c, sizeof(c)) < 0) {
- fprintf(stderr, "Failed to write to the exit pipe: %s\n", strerror(errno));
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to write to the exit pipe: %s", strerror(errno));
}
}
@@ -200,7 +202,7 @@ void process_loop(int listen_fd)
// A pipe is used to allow the render threads to request an exit by the main process
if (pipe(pipefds)) {
- fprintf(stderr, "Failed to create pipe\n");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to create pipe");
return;
}
@@ -222,19 +224,20 @@ void process_loop(int listen_fd)
num = poll(pfd, num_cslots + PFD_SPECIAL_COUNT, -1);
if (num == -1) {
- perror("poll()");
+ g_logger(G_LOG_LEVEL_ERROR, "poll(): %s", strerror(errno));
} else if (num) {
if (pfd[PFD_EXIT_PIPE].revents & POLLIN) {
// A render thread wants us to exit
break;
}
- //printf("Data is available now on %d fds\n", num);
+ g_logger(G_LOG_LEVEL_DEBUG, "Data is available now on %d fds", num);
+
if (pfd[PFD_LISTEN].revents & POLLIN) {
incoming = accept(listen_fd, (struct sockaddr *) &in_addr, &in_addrlen);
if (incoming < 0) {
- perror("accept()");
+ g_logger(G_LOG_LEVEL_ERROR, "accept(): %s", strerror(errno));
} else {
int add = 0;
@@ -249,7 +252,7 @@ void process_loop(int listen_fd)
// No unused slot found, add at end if space available
if (!add) {
if (num_cslots == MAX_CONNECTIONS) {
- syslog(LOG_WARNING, "Connection limit(%d) reached. Dropping connection\n", MAX_CONNECTIONS);
+ g_logger(G_LOG_LEVEL_WARNING, "Connection limit(%d) reached. Dropping connection", MAX_CONNECTIONS);
close(incoming);
} else {
i = num_cslots;
@@ -262,7 +265,7 @@ void process_loop(int listen_fd)
pfd[i + PFD_SPECIAL_COUNT].fd = incoming;
pfd[i + PFD_SPECIAL_COUNT].events = POLLIN;
num_conns ++;
- syslog(LOG_DEBUG, "DEBUG: Got incoming connection, fd %d, number %d, total conns %d, total slots %d\n", incoming, i, num_conns, num_cslots);
+ g_logger(G_LOG_LEVEL_DEBUG, "Got incoming connection, fd %d, number %d, total conns %d, total slots %d", incoming, i, num_conns, num_cslots);
}
}
}
@@ -280,7 +283,7 @@ void process_loop(int listen_fd)
if (ret < 1) {
num_conns--;
- syslog(LOG_DEBUG, "DEBUG: Connection %d, fd %d closed, now %d left, total slots %d\n", i, fd, num_conns, num_cslots);
+ g_logger(G_LOG_LEVEL_DEBUG, "Connection %d, fd %d closed, now %d left, total slots %d", i, fd, num_conns, num_cslots);
request_queue_clear_requests_by_fd(render_request_queue, fd);
close(fd);
pfd[i + PFD_SPECIAL_COUNT].fd = -1;
@@ -289,14 +292,14 @@ void process_loop(int listen_fd)
if (rsp == cmdNotDone) {
cmd.cmd = rsp;
- syslog(LOG_DEBUG, "DEBUG: Sending NotDone response(%d)\n", rsp);
+ g_logger(G_LOG_LEVEL_DEBUG, "Sending NotDone response(%d)", rsp);
ret = send_cmd(&cmd, fd);
}
}
}
}
} else {
- syslog(LOG_ERR, "poll timeout");
+ g_logger(G_LOG_LEVEL_ERROR, "Poll timeout");
}
}
}
@@ -320,7 +323,7 @@ void *stats_writeout_thread(void * arg)
snprintf(tmpName, sizeof(tmpName), "%s.tmp", config.stats_filename);
- syslog(LOG_DEBUG, "Starting stats thread");
+ g_logger(G_LOG_LEVEL_DEBUG, "Starting stats thread");
while (1) {
request_queue_copy_stats(render_request_queue, &lStats);
@@ -334,11 +337,11 @@ void *stats_writeout_thread(void * arg)
FILE * statfile = fopen(tmpName, "w");
if (statfile == NULL) {
- syslog(LOG_WARNING, "Failed to open stats file: %i", errno);
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to open stats file: %i", errno);
noFailedAttempts++;
if (noFailedAttempts > 3) {
- syslog(LOG_ERR, "ERROR: Failed repeatedly to write stats, giving up");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed repeatedly to write stats, giving up");
break;
}
@@ -373,11 +376,11 @@ void *stats_writeout_thread(void * arg)
fclose(statfile);
if (rename(tmpName, config.stats_filename)) {
- syslog(LOG_WARNING, "Failed to overwrite stats file: %i", errno);
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to overwrite stats file: %i", errno);
noFailedAttempts++;
if (noFailedAttempts > 3) {
- syslog(LOG_ERR, "ERROR: Failed repeatedly to overwrite stats, giving up");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed repeatedly to overwrite stats, giving up");
break;
}
@@ -401,7 +404,7 @@ int client_socket_init(renderd_config * sConfig)
char ipstring[INET6_ADDRSTRLEN];
if (sConfig->ipport > 0) {
- syslog(LOG_INFO, "Initialising TCP/IP client socket to %s:%i", sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_INFO, "Initialising TCP/IP client socket to %s:%i", sConfig->iphostname, sConfig->ipport);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
@@ -416,7 +419,7 @@ int client_socket_init(renderd_config * sConfig)
s = getaddrinfo(sConfig->iphostname, portnum, &hints, &result);
if (s != 0) {
- syslog(LOG_INFO, "failed to resolve hostname of rendering slave");
+ g_logger(G_LOG_LEVEL_INFO, "failed to resolve hostname of rendering slave");
return FD_INVALID;
}
@@ -437,7 +440,7 @@ int client_socket_init(renderd_config * sConfig)
break;
}
- syslog(LOG_DEBUG, "Connecting TCP socket to rendering daemon at %s", ipstring);
+ g_logger(G_LOG_LEVEL_DEBUG, "Connecting TCP socket to rendering daemon at %s", ipstring);
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (fd < 0) {
@@ -445,7 +448,7 @@ int client_socket_init(renderd_config * sConfig)
}
if (connect(fd, rp->ai_addr, rp->ai_addrlen) != 0) {
- syslog(LOG_INFO, "failed to connect to rendering daemon (%s), trying next ip", ipstring);
+ g_logger(G_LOG_LEVEL_INFO, "failed to connect to rendering daemon (%s), trying next ip", ipstring);
close(fd);
fd = -1;
continue;
@@ -457,19 +460,19 @@ int client_socket_init(renderd_config * sConfig)
freeaddrinfo(result);
if (fd < 0) {
- syslog(LOG_WARNING, "failed to connect to %s:%i", sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_WARNING, "failed to connect to %s:%i", sConfig->iphostname, sConfig->ipport);
return FD_INVALID;
}
- syslog(LOG_INFO, "socket %s:%i initialised to fd %i", sConfig->iphostname, sConfig->ipport, fd);
+ g_logger(G_LOG_LEVEL_INFO, "socket %s:%i initialised to fd %i", sConfig->iphostname, sConfig->ipport, fd);
} else {
- syslog(LOG_INFO, "Initialising unix client socket on %s",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_INFO, "Initialising unix client socket on %s",
+ sConfig->socketname);
addrU = (struct sockaddr_un *)malloc(sizeof(struct sockaddr_un));
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- syslog(LOG_WARNING, "Could not obtain socket: %i", fd);
+ g_logger(G_LOG_LEVEL_WARNING, "Could not obtain socket: %i", fd);
free(addrU);
return FD_INVALID;
}
@@ -479,16 +482,16 @@ int client_socket_init(renderd_config * sConfig)
strncpy(addrU->sun_path, sConfig->socketname, sizeof(addrU->sun_path) - 1);
if (connect(fd, (struct sockaddr *) addrU, sizeof(struct sockaddr_un)) < 0) {
- syslog(LOG_WARNING, "socket connect failed for: %s",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_WARNING, "socket connect failed for: %s",
+ sConfig->socketname);
close(fd);
free(addrU);
return FD_INVALID;
}
free(addrU);
- syslog(LOG_INFO, "socket %s initialised to fd %i", sConfig->socketname,
- fd);
+ g_logger(G_LOG_LEVEL_INFO, "socket %s initialised to fd %i", sConfig->socketname,
+ fd);
}
return fd;
@@ -502,12 +505,12 @@ int server_socket_init(renderd_config *sConfig)
int fd;
if (sConfig->ipport > 0) {
- syslog(LOG_INFO, "Initialising TCP/IP server socket on %s:%i",
- sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_INFO, "Initialising TCP/IP server socket on %s:%i",
+ sConfig->iphostname, sConfig->ipport);
fd = socket(PF_INET6, SOCK_STREAM, 0);
if (fd < 0) {
- fprintf(stderr, "failed to create IP socket\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "failed to create IP socket");
exit(2);
}
@@ -517,19 +520,19 @@ int server_socket_init(renderd_config *sConfig)
addrI.sin6_port = htons(sConfig->ipport);
if (bind(fd, (struct sockaddr *) &addrI, sizeof(addrI)) < 0) {
- fprintf(stderr, "socket bind failed for: %s:%i\n",
- sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_CRITICAL, "socket bind failed for: %s:%i",
+ sConfig->iphostname, sConfig->ipport);
close(fd);
exit(3);
}
} else {
- syslog(LOG_INFO, "Initialising unix server socket on %s",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_INFO, "Initialising unix server socket on %s",
+ sConfig->socketname);
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- fprintf(stderr, "failed to create unix socket\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "failed to create unix socket");
exit(2);
}
@@ -542,7 +545,7 @@ int server_socket_init(renderd_config *sConfig)
old = umask(0); // Need daemon socket to be writeable by apache
if (bind(fd, (struct sockaddr *) &addrU, sizeof(addrU)) < 0) {
- fprintf(stderr, "socket bind failed for: %s\n", sConfig->socketname);
+ g_logger(G_LOG_LEVEL_CRITICAL, "socket bind failed for: %s", sConfig->socketname);
close(fd);
exit(3);
}
@@ -551,12 +554,12 @@ int server_socket_init(renderd_config *sConfig)
}
if (listen(fd, QUEUE_MAX) < 0) {
- fprintf(stderr, "socket listen failed for %d\n", QUEUE_MAX);
+ g_logger(G_LOG_LEVEL_CRITICAL, "socket listen failed for %d", QUEUE_MAX);
close(fd);
exit(4);
}
- syslog(LOG_DEBUG, "Created server socket %i", fd);
+ g_logger(G_LOG_LEVEL_DEBUG, "Created server socket %i", fd);
return fd;
@@ -593,13 +596,13 @@ void *slave_thread(void * arg)
if (pfd == FD_INVALID) {
if (sConfig->ipport > 0) {
- syslog(LOG_ERR,
- "Failed to connect to render slave %s:%i, trying again in 30 seconds",
- sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Failed to connect to render slave %s:%i, trying again in 30 seconds",
+ sConfig->iphostname, sConfig->ipport);
} else {
- syslog(LOG_ERR,
- "Failed to connect to render slave %s, trying again in 30 seconds",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Failed to connect to render slave %s, trying again in 30 seconds",
+ sConfig->socketname);
}
sleep(30);
@@ -623,8 +626,8 @@ void *slave_thread(void * arg)
/*Dispatch request to slave renderd*/
retry = 2;
- syslog(LOG_INFO,
- "Dispatching request to slave thread on fd %i", pfd);
+ g_logger(G_LOG_LEVEL_INFO,
+ "Dispatching request to slave thread on fd %i", pfd);
do {
ret_size = send_cmd(req_slave, pfd);
@@ -635,21 +638,21 @@ void *slave_thread(void * arg)
}
if (errno != EPIPE) {
- syslog(LOG_ERR,
- "Failed to send cmd to render slave, shutting down thread");
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Failed to send cmd to render slave, shutting down thread");
free(resp);
free(req_slave);
close(pfd);
return NULL;
}
- syslog(LOG_WARNING, "Failed to send cmd to render slave, retrying");
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to send cmd to render slave, retrying");
close(pfd);
pfd = client_socket_init(sConfig);
if (pfd == FD_INVALID) {
- syslog(LOG_ERR,
- "Failed to re-connect to render slave, dropping request");
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Failed to re-connect to render slave, dropping request");
ret = cmdNotDone;
send_response(item, ret, -1);
break;
@@ -671,7 +674,7 @@ void *slave_thread(void * arg)
close(pfd);
pfd = FD_INVALID;
ret_size = 0;
- syslog(LOG_ERR, "Pipe to render slave closed");
+ g_logger(G_LOG_LEVEL_ERROR, "Pipe to render slave closed");
break;
}
@@ -680,13 +683,13 @@ void *slave_thread(void * arg)
if (ret_size < sizeof(struct protocol)) {
if (sConfig->ipport > 0) {
- syslog(LOG_ERR,
- "Invalid reply from render slave %s:%i, trying again in 30 seconds",
- sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Invalid reply from render slave %s:%i, trying again in 30 seconds",
+ sConfig->iphostname, sConfig->ipport);
} else {
- syslog(LOG_ERR,
- "Invalid reply render slave %s, trying again in 30 seconds",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Invalid reply render slave %s, trying again in 30 seconds",
+ sConfig->socketname);
}
ret = cmdNotDone;
@@ -698,13 +701,13 @@ void *slave_thread(void * arg)
if (resp->cmd != cmdDone) {
if (sConfig->ipport > 0) {
- syslog(LOG_ERR,
- "Request from render slave %s:%i did not complete correctly",
- sConfig->iphostname, sConfig->ipport);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Request from render slave %s:%i did not complete correctly",
+ sConfig->iphostname, sConfig->ipport);
} else {
- syslog(LOG_ERR,
- "Request from render slave %s did not complete correctly",
- sConfig->socketname);
+ g_logger(G_LOG_LEVEL_ERROR,
+ "Request from render slave %s did not complete correctly",
+ sConfig->socketname);
}
//Sleep for a while to make sure we don't overload the renderer
@@ -730,18 +733,16 @@ int main(int argc, char **argv)
int fd, i, j, k;
int c;
- int foreground = 0;
int active_slave = 0;
- int log_options;
char config_file_name[PATH_MAX] = RENDERD_CONFIG;
while (1) {
int option_index = 0;
static struct option long_options[] = {
- {"config", 1, 0, 'c'},
- {"foreground", 1, 0, 'f'},
- {"slave", 1, 0, 's'},
- {"help", 0, 0, 'h'},
+ {"config", required_argument, 0, 'c'},
+ {"foreground", no_argument, 0, 'f'},
+ {"slave", required_argument, 0, 's'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -763,7 +764,7 @@ int main(int argc, char **argv)
case 's':
if (sscanf(optarg, "%i", &active_slave) != 1) {
- fprintf(stderr, "--slave needs to be nummeric (%s)\n", optarg);
+ fprintf(stderr, "--slave needs to be numeric (%s)\n", optarg);
active_slave = 0;
}
@@ -772,9 +773,9 @@ int main(int argc, char **argv)
case 'h':
fprintf(stderr, "Usage: renderd [OPTION] ...\n");
fprintf(stderr, "Mapnik rendering daemon\n");
- fprintf(stderr, " -f, --foreground run in foreground\n");
- fprintf(stderr, " -h, --help display this help and exit\n");
- fprintf(stderr, " -c, --config=CONFIG set location of config file (default /etc/renderd.conf)\n");
+ fprintf(stderr, " -f, --foreground run in foreground\n");
+ fprintf(stderr, " -h, --help display this help and exit\n");
+ fprintf(stderr, " -c, --config=CONFIG set location of config file (default %s)\n", RENDERD_CONFIG);
fprintf(stderr, " -s, --slave=CONFIG_NR set which render slave this is (default 0)\n");
exit(0);
@@ -784,26 +785,21 @@ int main(int argc, char **argv)
}
}
- log_options = LOG_PID;
-#ifdef LOG_PERROR
-
- if (foreground) {
- log_options |= LOG_PERROR;
+ if (access(config_file_name, F_OK) != 0) {
+ fprintf(stderr, "Config file '%s' does not exist, please specify a valid file with -c/--config\n", config_file_name);
+ exit(1);
}
-#endif
- openlog("renderd", log_options, LOG_DAEMON);
-
- syslog(LOG_INFO, "Rendering daemon started");
+ g_logger(G_LOG_LEVEL_INFO, "Rendering daemon started");
render_request_queue = request_queue_init();
if (render_request_queue == NULL) {
- syslog(LOG_ERR, "Failed to initialise request queue");
+ g_logger(G_LOG_LEVEL_CRITICAL, "Failed to initialise request queue");
exit(1);
}
- syslog(LOG_ERR, "Initiating request_queue");
+ g_logger(G_LOG_LEVEL_INFO, "Initialising request_queue");
xmlconfigitem maps[XMLCONFIGS_MAX];
bzero(maps, sizeof(xmlconfigitem) * XMLCONFIGS_MAX);
@@ -825,11 +821,11 @@ int main(int argc, char **argv)
for (int section = 0; section < iniparser_getnsec(ini); section++) {
char *name = iniparser_getsecname(ini, section);
- syslog(LOG_INFO, "Parsing section %s\n", name);
+ g_logger(G_LOG_LEVEL_INFO, "Parsing section %s", name);
if (strncmp(name, "renderd", 7) && strcmp(name, "mapnik")) {
if (config.tile_dir == NULL) {
- fprintf(stderr, "No valid (active) renderd config section available\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "No valid (active) renderd config section available");
exit(7);
}
@@ -837,12 +833,12 @@ int main(int argc, char **argv)
iconf++;
if (iconf >= XMLCONFIGS_MAX) {
- fprintf(stderr, "Config: more than %d configurations found\n", XMLCONFIGS_MAX);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Config: more than %d configurations found", XMLCONFIGS_MAX);
exit(7);
}
if (strlen(name) >= (XMLCONFIG_MAX - 1)) {
- fprintf(stderr, "XML name too long: %s\n", name);
+ g_logger(G_LOG_LEVEL_CRITICAL, "XML name too long: %s", name);
exit(7);
}
@@ -852,7 +848,7 @@ int main(int argc, char **argv)
char *ini_uri = iniparser_getstring(ini, buffer, (char *)"");
if (strlen(ini_uri) >= (PATH_MAX - 1)) {
- fprintf(stderr, "URI too long: %s\n", ini_uri);
+ g_logger(G_LOG_LEVEL_CRITICAL, "URI too long: %s", ini_uri);
exit(7);
}
@@ -862,7 +858,7 @@ int main(int argc, char **argv)
char *ini_xmlpath = iniparser_getstring(ini, buffer, (char *)"");
if (strlen(ini_xmlpath) >= (PATH_MAX - 1)) {
- fprintf(stderr, "XML path too long: %s\n", ini_xmlpath);
+ g_logger(G_LOG_LEVEL_CRITICAL, "XML path too long: %s", ini_xmlpath);
exit(7);
}
@@ -872,7 +868,7 @@ int main(int argc, char **argv)
char *ini_hostname = iniparser_getstring(ini, buffer, (char *) "");
if (strlen(ini_hostname) >= (PATH_MAX - 1)) {
- fprintf(stderr, "Host name too long: %s\n", ini_hostname);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Host name too long: %s", ini_hostname);
exit(7);
}
@@ -882,7 +878,7 @@ int main(int argc, char **argv)
char *ini_htcpip = iniparser_getstring(ini, buffer, (char *) "");
if (strlen(ini_htcpip) >= (PATH_MAX - 1)) {
- fprintf(stderr, "HTCP host name too long: %s\n", ini_htcpip);
+ g_logger(G_LOG_LEVEL_CRITICAL, "HTCP host name too long: %s", ini_htcpip);
exit(7);
}
@@ -893,7 +889,7 @@ int main(int argc, char **argv)
maps[iconf].tile_px_size = atoi(ini_tilesize);
if (maps[iconf].tile_px_size < 1) {
- fprintf(stderr, "Tile size is invalid: %s\n", ini_tilesize);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Tile size is invalid: %s", ini_tilesize);
exit(7);
}
@@ -902,7 +898,7 @@ int main(int argc, char **argv)
maps[iconf].scale_factor = atof(ini_scale);
if (maps[iconf].scale_factor < 0.1 || maps[iconf].scale_factor > 8.0) {
- fprintf(stderr, "Scale factor is invalid: %s\n", ini_scale);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Scale factor is invalid: %s", ini_scale);
exit(7);
}
@@ -910,7 +906,7 @@ int main(int argc, char **argv)
char *ini_tiledir = iniparser_getstring(ini, buffer, (char *) config.tile_dir);
if (strlen(ini_tiledir) >= (PATH_MAX - 1)) {
- fprintf(stderr, "Tiledir too long: %s\n", ini_tiledir);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Tiledir too long: %s", ini_tiledir);
exit(7);
}
@@ -921,7 +917,7 @@ int main(int argc, char **argv)
maps[iconf].max_zoom = atoi(ini_maxzoom);
if (maps[iconf].max_zoom > MAX_ZOOM) {
- fprintf(stderr, "Specified max zoom (%i) is to large. Renderd currently only supports up to zoom level %i\n", maps[iconf].max_zoom, MAX_ZOOM);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Specified max zoom (%i) is to large. Renderd currently only supports up to zoom level %i", maps[iconf].max_zoom, MAX_ZOOM);
exit(7);
}
@@ -930,12 +926,12 @@ int main(int argc, char **argv)
maps[iconf].min_zoom = atoi(ini_minzoom);
if (maps[iconf].min_zoom < 0) {
- fprintf(stderr, "Specified min zoom (%i) is to small. Minimum zoom level has to be greater or equal to 0\n", maps[iconf].min_zoom);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is to small. Minimum zoom level has to be greater or equal to 0", maps[iconf].min_zoom);
exit(7);
}
if (maps[iconf].min_zoom > maps[iconf].max_zoom) {
- fprintf(stderr, "Specified min zoom (%i) is larger than max zoom (%i).\n", maps[iconf].min_zoom, maps[iconf].max_zoom);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is larger than max zoom (%i).", maps[iconf].min_zoom, maps[iconf].max_zoom);
exit(7);
}
@@ -943,7 +939,7 @@ int main(int argc, char **argv)
char *ini_parameterize = iniparser_getstring(ini, buffer, "");
if (strlen(ini_parameterize) >= (PATH_MAX - 1)) {
- fprintf(stderr, "Parameterize_style too long: %s\n", ini_parameterize);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Parameterize_style too long: %s", ini_parameterize);
exit(7);
}
@@ -961,11 +957,11 @@ int main(int argc, char **argv)
render_sec = 0;
}
- syslog(LOG_INFO, "Parsing render section %i\n", render_sec);
+ g_logger(G_LOG_LEVEL_INFO, "Parsing render section %i", render_sec);
if (render_sec >= MAX_SLAVES) {
- syslog(LOG_ERR, "Can't handle more than %i render sections\n",
- MAX_SLAVES);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Can't handle more than %i render sections",
+ MAX_SLAVES);
exit(7);
}
@@ -1008,22 +1004,22 @@ int main(int argc, char **argv)
}
if (config.ipport > 0) {
- syslog(LOG_INFO, "config renderd: ip socket=%s:%i\n", config.iphostname, config.ipport);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: ip socket=%s:%i", config.iphostname, config.ipport);
} else {
- syslog(LOG_INFO, "config renderd: unix socketname=%s\n", config.socketname);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: unix socketname=%s", config.socketname);
}
- syslog(LOG_INFO, "config renderd: num_threads=%d\n", config.num_threads);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: num_threads=%d", config.num_threads);
if (active_slave == 0) {
- syslog(LOG_INFO, "config renderd: num_slaves=%d\n", noSlaveRenders);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: num_slaves=%d", noSlaveRenders);
}
- syslog(LOG_INFO, "config renderd: tile_dir=%s\n", config.tile_dir);
- syslog(LOG_INFO, "config renderd: stats_file=%s\n", config.stats_filename);
- syslog(LOG_INFO, "config mapnik: plugins_dir=%s\n", config.mapnik_plugins_dir);
- syslog(LOG_INFO, "config mapnik: font_dir=%s\n", config.mapnik_font_dir);
- syslog(LOG_INFO, "config mapnik: font_dir_recurse=%d\n", config.mapnik_font_dir_recurse);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: tile_dir=%s", config.tile_dir);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd: stats_file=%s", config.stats_filename);
+ g_logger(G_LOG_LEVEL_INFO, "config mapnik: plugins_dir=%s", config.mapnik_plugins_dir);
+ g_logger(G_LOG_LEVEL_INFO, "config mapnik: font_dir=%s", config.mapnik_font_dir);
+ g_logger(G_LOG_LEVEL_INFO, "config mapnik: font_dir_recurse=%d", config.mapnik_font_dir_recurse);
for (i = 0; i < MAX_SLAVES; i++) {
if (config_slaves[i].num_threads == 0) {
@@ -1031,30 +1027,30 @@ int main(int argc, char **argv)
}
if (i == active_slave) {
- syslog(LOG_INFO, "config renderd(%i): Active\n", i);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): Active", i);
}
if (config_slaves[i].ipport > 0) {
- syslog(LOG_INFO, "config renderd(%i): ip socket=%s:%i\n", i,
- config_slaves[i].iphostname, config_slaves[i].ipport);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): ip socket=%s:%i", i,
+ config_slaves[i].iphostname, config_slaves[i].ipport);
} else {
- syslog(LOG_INFO, "config renderd(%i): unix socketname=%s\n", i,
- config_slaves[i].socketname);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): unix socketname=%s", i,
+ config_slaves[i].socketname);
}
- syslog(LOG_INFO, "config renderd(%i): num_threads=%d\n", i,
- config_slaves[i].num_threads);
- syslog(LOG_INFO, "config renderd(%i): tile_dir=%s\n", i,
- config_slaves[i].tile_dir);
- syslog(LOG_INFO, "config renderd(%i): stats_file=%s\n", i,
- config_slaves[i].stats_filename);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): num_threads=%d", i,
+ config_slaves[i].num_threads);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): tile_dir=%s", i,
+ config_slaves[i].tile_dir);
+ g_logger(G_LOG_LEVEL_INFO, "config renderd(%i): stats_file=%s", i,
+ config_slaves[i].stats_filename);
}
for (iconf = 0; iconf < XMLCONFIGS_MAX; ++iconf) {
if (maps[iconf].xmlname[0] != 0) {
- syslog(LOG_INFO, "config map %d: name(%s) file(%s) uri(%s) htcp(%s) host(%s)",
- iconf, maps[iconf].xmlname, maps[iconf].xmlfile, maps[iconf].xmluri,
- maps[iconf].htcpip, maps[iconf].host);
+ g_logger(G_LOG_LEVEL_INFO, "config map %d: name(%s) file(%s) uri(%s) htcp(%s) host(%s)",
+ iconf, maps[iconf].xmlname, maps[iconf].xmlfile, maps[iconf].xmluri,
+ maps[iconf].htcpip, maps[iconf].host);
}
}
@@ -1062,7 +1058,7 @@ int main(int argc, char **argv)
#if 0
if (fcntl(fd, F_SETFD, O_RDWR | O_NONBLOCK) < 0) {
- fprintf(stderr, "setting socket non-block failed\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "setting socket non-block failed");
close(fd);
exit(5);
}
@@ -1073,7 +1069,7 @@ int main(int argc, char **argv)
sigPipeAction.sa_handler = SIG_IGN;
if (sigaction(SIGPIPE, &sigPipeAction, NULL) < 0) {
- fprintf(stderr, "failed to register signal handler\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "failed to register signal handler");
close(fd);
exit(6);
}
@@ -1082,10 +1078,10 @@ int main(int argc, char **argv)
/* unless the command line said to run in foreground mode, fork and detach from terminal */
if (foreground) {
- fprintf(stderr, "Running in foreground mode...\n");
+ g_logger(G_LOG_LEVEL_INFO, "Running in foreground mode...");
} else {
if (daemon(0, 0) != 0) {
- fprintf(stderr, "can't daemonize: %s\n", strerror(errno));
+ g_logger(G_LOG_LEVEL_ERROR, "can't daemonize: %s", strerror(errno));
}
/* write pid file */
@@ -1099,17 +1095,17 @@ int main(int argc, char **argv)
if (config.stats_filename != NULL) {
if (pthread_create(&stats_thread, NULL, stats_writeout_thread, NULL)) {
- syslog(LOG_WARNING, "Could not create stats writeout thread");
+ g_logger(G_LOG_LEVEL_WARNING, "Could not create stats writeout thread");
}
} else {
- syslog(LOG_INFO, "No stats file specified in config. Stats reporting disabled");
+ g_logger(G_LOG_LEVEL_INFO, "No stats file specified in config. Stats reporting disabled");
}
render_threads = (pthread_t *) malloc(sizeof(pthread_t) * config.num_threads);
for (i = 0; i < config.num_threads; i++) {
if (pthread_create(&render_threads[i], NULL, render_thread, (void *)maps)) {
- fprintf(stderr, "error spawning render thread\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "error spawning render thread");
close(fd);
exit(7);
}
@@ -1125,7 +1121,7 @@ int main(int argc, char **argv)
for (j = 0; j < config_slaves[i].num_threads; j++) {
if (pthread_create(&slave_threads[k++], NULL, slave_thread,
(void *) &config_slaves[i])) {
- fprintf(stderr, "error spawning render thread\n");
+ g_logger(G_LOG_LEVEL_CRITICAL, "error spawning render thread");
close(fd);
exit(7);
}
diff --git a/src/g_logger.c b/src/g_logger.c
new file mode 100644
index 00000000..a984783d
--- /dev/null
+++ b/src/g_logger.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2007 - 2020 by mod_tile contributors (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see http://www.gnu.org/licenses/.
+ */
+
+#define _GNU_SOURCE 1
+#define G_LOG_USE_STRUCTURED 1
+
+#include
+#include
+#include
+
+extern int foreground;
+
+const char *g_logger_level_name(int log_level)
+{
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ return "ERROR";
+
+ case G_LOG_LEVEL_CRITICAL:
+ return "CRITICAL";
+
+ case G_LOG_LEVEL_WARNING:
+ return "WARNING";
+
+ case G_LOG_LEVEL_MESSAGE:
+ return "MESSAGE";
+
+ case G_LOG_LEVEL_INFO:
+ return "INFO";
+
+ case G_LOG_LEVEL_DEBUG:
+ return "DEBUG";
+
+ default:
+ return "UNKNOWN";
+ }
+}
+
+void g_logger(int log_level, const char *format, ...)
+{
+ int size;
+ char *log_message, *log_message_prefixed;
+
+ va_list args;
+
+ va_start(args, format);
+
+ size = vasprintf(&log_message, format, args);
+
+ if (size == -1) {
+ g_error("ERROR: vasprintf failed in g_logger");
+ }
+
+ const GLogField log_fields[] = {{"MESSAGE", log_message, -1}};
+
+ size = asprintf(&log_message_prefixed, "%s: %s", g_logger_level_name(log_level), log_message);
+
+ if (size == -1) {
+ g_error("ERROR: asprintf failed in g_logger");
+ }
+
+ const GLogField log_fields_prefixed[] = {{"MESSAGE", log_message_prefixed, -1}};
+
+ if (foreground == 1) {
+ switch (log_level) {
+ // Levels >= G_LOG_LEVEL_ERROR will terminate the program
+ case G_LOG_LEVEL_ERROR:
+ g_log_writer_standard_streams(log_level, log_fields, 1, NULL);
+ break;
+
+ // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG
+ case G_LOG_LEVEL_INFO:
+ g_log_writer_standard_streams(log_level, log_fields, 1, NULL);
+ break;
+
+ default:
+ g_log_writer_default(log_level, log_fields, 1, NULL);
+ }
+ } else if (g_log_writer_is_journald(fileno(stderr))) {
+ switch (log_level) {
+ // Levels >= G_LOG_LEVEL_ERROR will terminate the program
+ case G_LOG_LEVEL_ERROR:
+ g_log_writer_journald(log_level, log_fields, 1, NULL);
+ break;
+
+ // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG
+ case G_LOG_LEVEL_INFO:
+ g_log_writer_journald(log_level, log_fields, 1, NULL);
+ break;
+
+ default:
+ g_log_writer_default(log_level, log_fields, 1, NULL);
+ }
+ } else {
+ setlogmask(LOG_UPTO(LOG_INFO));
+
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ syslog(LOG_ERR, log_message_prefixed, NULL);
+ break;
+
+ case G_LOG_LEVEL_CRITICAL:
+ syslog(LOG_CRIT, log_message_prefixed, NULL);
+ break;
+
+ case G_LOG_LEVEL_WARNING:
+ syslog(LOG_WARNING, log_message_prefixed, NULL);
+ break;
+
+ case G_LOG_LEVEL_MESSAGE:
+ syslog(LOG_INFO, log_message_prefixed, NULL);
+ break;
+
+ case G_LOG_LEVEL_INFO:
+ syslog(LOG_INFO, log_message_prefixed, NULL);
+ break;
+
+ case G_LOG_LEVEL_DEBUG:
+ syslog(LOG_DEBUG, log_message_prefixed, NULL);
+ break;
+ }
+ }
+
+ va_end(args);
+
+ free(log_message_prefixed);
+ free(log_message);
+}
diff --git a/src/gen_tile.cpp b/src/gen_tile.cpp
index 248e471c..2c49f0b9 100644
--- a/src/gen_tile.cpp
+++ b/src/gen_tile.cpp
@@ -32,7 +32,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -47,6 +46,7 @@
#include "request_queue.h"
#include "cache_expire.h"
#include "parameterize_style.hpp"
+#include "g_logger.h"
#ifdef HTCP_EXPIRE_CACHE
#include
@@ -86,6 +86,8 @@ using namespace mapnik;
#define RENDER_SIZE (512)
#endif
+extern int foreground;
+
struct projectionconfig {
double bound_x0;
double bound_y0;
@@ -121,7 +123,7 @@ struct projectionconfig * get_projection(const char * srs)
struct projectionconfig * prj;
if (strstr(srs, "+proj=merc +a=6378137 +b=6378137") != NULL) {
- syslog(LOG_DEBUG, "Using web mercator projection settings");
+ g_logger(G_LOG_LEVEL_DEBUG, "Using web mercator projection settings");
prj = (struct projectionconfig *)malloc(sizeof(struct projectionconfig));
prj->bound_x0 = -20037508.3428;
prj->bound_x1 = 20037508.3428;
@@ -130,7 +132,7 @@ struct projectionconfig * get_projection(const char * srs)
prj->aspect_x = 1;
prj->aspect_y = 1;
} else if (strcmp(srs, "+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs") == 0) {
- syslog(LOG_DEBUG, "Using plate carree projection settings");
+ g_logger(G_LOG_LEVEL_DEBUG, "Using plate carree projection settings");
prj = (struct projectionconfig *)malloc(sizeof(struct projectionconfig));
prj->bound_x0 = -20037508.3428;
prj->bound_x1 = 20037508.3428;
@@ -139,7 +141,7 @@ struct projectionconfig * get_projection(const char * srs)
prj->aspect_x = 2;
prj->aspect_y = 1;
} else if (strcmp(srs, "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs") == 0) {
- syslog(LOG_DEBUG, "Using bng projection settings");
+ g_logger(G_LOG_LEVEL_DEBUG, "Using bng projection settings");
prj = (struct projectionconfig *)malloc(sizeof(struct projectionconfig));
prj->bound_x0 = 0;
prj->bound_y0 = 0;
@@ -148,7 +150,7 @@ struct projectionconfig * get_projection(const char * srs)
prj->aspect_x = 1;
prj->aspect_y = 2;
} else {
- syslog(LOG_WARNING, "Unknown projection string, using web mercator as never the less. %s", srs);
+ g_logger(G_LOG_LEVEL_WARNING, "Unknown projection string, using web mercator as never the less. %s", srs);
prj = (struct projectionconfig *)malloc(sizeof(struct projectionconfig));
prj->bound_x0 = -20037508.3428;
prj->bound_x1 = 20037508.3428;
@@ -168,7 +170,7 @@ static void load_fonts(const char *font_dir, int recurse)
char path[PATH_MAX]; // FIXME: Eats lots of stack space when recursive
if (!fonts) {
- syslog(LOG_CRIT, "Unable to open font directory: %s", font_dir);
+ g_logger(G_LOG_LEVEL_CRITICAL, "Unable to open font directory: %s", font_dir);
return;
}
@@ -197,7 +199,7 @@ static void load_fonts(const char *font_dir, int recurse)
p = strrchr(path, '.');
if (p && (!strcmp(p, ".ttf") || !strcmp(p, ".otf") || !strcmp(p, ".ttc"))) {
- syslog(LOG_DEBUG, "DEBUG: Loading font: %s", path);
+ g_logger(G_LOG_LEVEL_DEBUG, "Loading font: %s", path);
freetype_engine::register_font(path);
}
}
@@ -252,7 +254,7 @@ static int check_xyz(int x, int y, int z, struct xmlmapconfig * map)
}
if (oob) {
- syslog(LOG_INFO, "got bad co-ords: x(%d) y(%d) z(%d)\n", x, y, z);
+ g_logger(G_LOG_LEVEL_INFO, "got bad co-ords: x(%d) y(%d) z(%d)", x, y, z);
}
return !oob;
@@ -270,7 +272,7 @@ mapnik::box2d tile2prjbounds(struct projectionconfig * prj, int x, int y
double p1x = prj->bound_x0 + (prj->bound_x1 - prj->bound_x0) * (((double)x + render_size_tx) / (double)(prj->aspect_x * 1 << z));
double p1y = (prj->bound_y1 - (prj->bound_y1 - prj->bound_y0) * ((double)y / (double)(prj->aspect_y * 1 << z)));
- syslog(LOG_DEBUG, "Rendering projected coordinates %i %i %i -> %f|%f %f|%f to a %i x %i tile\n", z, x, y, p0x, p0y, p1x, p1y, render_size_tx, render_size_ty);
+ g_logger(G_LOG_LEVEL_DEBUG, "Rendering projected coordinates %i %i %i -> %f|%f %f|%f to a %i x %i tile", z, x, y, p0x, p0y, p1x, p1y, render_size_tx, render_size_ty);
mapnik::box2d bbox(p0x, p0y, p1x, p1y);
return bbox;
@@ -302,8 +304,8 @@ static enum protoCmd render(struct xmlmapconfig * map, int x, int y, int z, char
mapnik::agg_renderer ren(map_parameterized, buf, map->scale);
ren.apply();
} catch (std::exception const& ex) {
- syslog(LOG_ERR, "ERROR: failed to render TILE %s %d %d-%d %d-%d", map->xmlname, z, x, x + render_size_tx - 1, y, y + render_size_ty - 1);
- syslog(LOG_ERR, " reason: %s", ex.what());
+ g_logger(G_LOG_LEVEL_ERROR, "failed to render TILE %s %d %d-%d %d-%d", map->xmlname, z, x, x + render_size_tx - 1, y, y + render_size_ty - 1);
+ g_logger(G_LOG_LEVEL_ERROR, " reason: %s", ex.what());
return cmdNotDone;
}
@@ -358,7 +360,7 @@ static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, project
snprintf(tmp, sizeof(tmp), "%s.tmp", filename);
mapnik::image_view vw(128, 128, 256, 256, buf.data());
- //std::cout << "Render " << z << " " << x << " " << y << " " << filename << "\n";
+ g_logger(G_LOG_LEVEL_DEBUG, "Render %i %i %i %s", z, x, y, filename)
mapnik::save_to_file(vw, tmp, "png256");
if (rename(tmp, filename)) {
@@ -373,7 +375,8 @@ static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, project
void render_init(const char *plugins_dir, const char* font_dir, int font_dir_recurse)
{
- syslog(LOG_INFO, "Renderd is using mapnik version %i.%i.%i", ((MAPNIK_VERSION) / 100000), (((MAPNIK_VERSION) / 100) % 1000), ((MAPNIK_VERSION) % 100));
+ g_logger(G_LOG_LEVEL_INFO, "Renderd is using mapnik version %i.%i.%i", ((MAPNIK_VERSION) / 100000), (((MAPNIK_VERSION) / 100) % 1000), ((MAPNIK_VERSION) % 100));
+
#if MAPNIK_VERSION >= 200200
mapnik::datasource_cache::instance().register_datasources(plugins_dir);
#else
@@ -416,16 +419,16 @@ void *render_thread(void * arg)
* up the mapnik datasources to support larger postgres connection pools
*/
if (parentxmlconfig[iMaxConfigs].num_threads > 10) {
- syslog(LOG_INFO, "Updating max_connection parameter for mapnik layers to reflect thread count");
+ g_logger(G_LOG_LEVEL_INFO, "Updating max_connection parameter for mapnik layers to reflect thread count");
parameterize_map_max_connections(maps[iMaxConfigs].map, parentxmlconfig[iMaxConfigs].num_threads);
}
maps[iMaxConfigs].prj = get_projection(maps[iMaxConfigs].map.srs().c_str());
} catch (std::exception const& ex) {
- syslog(LOG_ERR, "An error occurred while loading the map layer '%s': %s", maps[iMaxConfigs].xmlname, ex.what());
+ g_logger(G_LOG_LEVEL_ERROR, "An error occurred while loading the map layer '%s': %s", maps[iMaxConfigs].xmlname, ex.what());
maps[iMaxConfigs].ok = 0;
} catch (...) {
- syslog(LOG_ERR, "An unknown error occurred while loading the map layer '%s'", maps[iMaxConfigs].xmlname);
+ g_logger(G_LOG_LEVEL_ERROR, "An unknown error occurred while loading the map layer '%s'", maps[iMaxConfigs].xmlname);
maps[iMaxConfigs].ok = 0;
}
@@ -439,9 +442,9 @@ void *render_thread(void * arg)
maps[iMaxConfigs].htcphost);
if (maps[iMaxConfigs].htcpsock > 0) {
- syslog(LOG_INFO, "Successfully opened socket for HTCP cache expiry");
+ g_logger(G_LOG_LEVEL_INFO, "Successfully opened socket for HTCP cache expiry");
} else {
- syslog(LOG_ERR, "Failed to opened socket for HTCP cache expiry");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to open socket for HTCP cache expiry");
}
} else {
maps[iMaxConfigs].htcpsock = -1;
@@ -478,20 +481,20 @@ void *render_thread(void * arg)
struct stat_info sinfo = maps[i].store->tile_stat(maps[i].store, req->xmlname, req->options, item->mx, item->my, req->z);
if (sinfo.size > 0)
- syslog(LOG_DEBUG, "DEBUG: START TILE %s %d %d-%d %d-%d, age %.2f days",
- req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1,
- (tim.tv_sec - sinfo.mtime) / 86400.0);
+ g_logger(G_LOG_LEVEL_DEBUG, "START TILE %s %d %d-%d %d-%d, age %.2f days",
+ req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1,
+ (tim.tv_sec - sinfo.mtime) / 86400.0);
else
- syslog(LOG_DEBUG, "DEBUG: START TILE %s %d %d-%d %d-%d, new metatile",
- req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1);
+ g_logger(G_LOG_LEVEL_DEBUG, "START TILE %s %d %d-%d %d-%d, new metatile",
+ req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1);
ret = render(&(maps[i]), item->mx, item->my, req->z, req->options, tiles);
gettimeofday(&tim, NULL);
long t2 = tim.tv_sec * 1000 + (tim.tv_usec / 1000);
- syslog(LOG_DEBUG, "DEBUG: DONE TILE %s %d %d-%d %d-%d in %.3lf seconds",
- req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1, (t2 - t1) / 1000.0);
+ g_logger(G_LOG_LEVEL_DEBUG, "DONE TILE %s %d %d-%d %d-%d in %.3lf seconds",
+ req->xmlname, req->z, item->mx, item->mx + size - 1, item->my, item->my + size - 1, (t2 - t1) / 1000.0);
render_time = t2 - t1;
@@ -503,11 +506,11 @@ void *render_thread(void * arg)
#endif
} catch (std::exception const& ex) {
- syslog(LOG_ERR, "Received exception when writing metatile to disk: %s", ex.what());
+ g_logger(G_LOG_LEVEL_ERROR, "Received exception when writing metatile to disk: %s", ex.what());
ret = cmdNotDone;
} catch (...) {
// Treat any error as fatal and request end of processing
- syslog(LOG_ERR, "Failed writing metatile to disk with unknown error, requesting exit.");
+ g_logger(G_LOG_LEVEL_CRITICAL, "Failed writing metatile to disk with unknown error, requesting exit.");
ret = cmdNotDone;
request_exit();
}
@@ -520,12 +523,12 @@ void *render_thread(void * arg)
#endif
#endif //METATILE
} else {
- syslog(LOG_WARNING, "Received request for map layer %s is outside of acceptable bounds z(%i), x(%i), y(%i)",
- req->xmlname, req->z, req->x, req->y);
+ g_logger(G_LOG_LEVEL_WARNING, "Received request for map layer %s is outside of acceptable bounds z(%i), x(%i), y(%i)",
+ req->xmlname, req->z, req->x, req->y);
ret = cmdIgnore;
}
} else {
- syslog(LOG_ERR, "Received request for map layer '%s' which failed to load", req->xmlname);
+ g_logger(G_LOG_LEVEL_ERROR, "Received request for map layer '%s' which failed to load", req->xmlname);
ret = cmdNotDone;
}
@@ -540,7 +543,7 @@ void *render_thread(void * arg)
}
if (i == iMaxConfigs) {
- syslog(LOG_ERR, "No map for: %s", req->xmlname);
+ g_logger(G_LOG_LEVEL_ERROR, "No map for: %s", req->xmlname);
}
} else {
sleep(1); // TODO: Use an event to indicate there are new requests
@@ -549,4 +552,3 @@ void *render_thread(void * arg)
return NULL;
}
-
diff --git a/src/gen_tile_test.cpp b/src/gen_tile_test.cpp
index b1a80368..063a6513 100644
--- a/src/gen_tile_test.cpp
+++ b/src/gen_tile_test.cpp
@@ -989,4 +989,3 @@ int main(int argc, char* const argv[])
pthread_mutex_destroy(&item_counter_lock);
return result;
}
-
diff --git a/src/metatile.cpp b/src/metatile.cpp
index 1e040f69..832fe015 100644
--- a/src/metatile.cpp
+++ b/src/metatile.cpp
@@ -19,7 +19,6 @@
#include
#include
-#include
#include
#include "render_config.h"
@@ -27,6 +26,7 @@
#include "store.h"
#include "cache_expire.h"
#include "request_queue.h"
+#include "g_logger.h"
metaTile::metaTile(const std::string &xmlconfig, const std::string &options, int x, int y, int z):
@@ -97,7 +97,7 @@ void metaTile::save(struct storage_backend * store)
metatilebuffer = (char *) malloc(offset);
if (metatilebuffer == 0) {
- syslog(LOG_WARNING, "Failed to write metatile. Out of memory");
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to write metatile. Out of memory");
return;
}
@@ -114,7 +114,7 @@ void metaTile::save(struct storage_backend * store)
if (store->metatile_write(store, xmlconfig_.c_str(), options_.c_str(), x_, y_, z_, metatilebuffer, offset) != offset) {
tmp = (char *)malloc(sizeof(char) * PATH_MAX);
- syslog(LOG_WARNING, "Failed to write metatile to %s", store->tile_storage_id(store, xmlconfig_.c_str(), options_.c_str(), x_, y_, z_, tmp));
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to write metatile to %s", store->tile_storage_id(store, xmlconfig_.c_str(), options_.c_str(), x_, y_, z_, tmp));
free(tmp);
}
@@ -128,7 +128,7 @@ void metaTile::expire_tiles(int sock, char * host, char * uri)
return;
}
- syslog(LOG_INFO, "Purging metatile via HTCP cache expiry");
+ g_logger(G_LOG_LEVEL_INFO, "Purging metatile via HTCP cache expiry");
int ox, oy;
int limit = (1 << z_);
limit = MIN(limit, METATILE);
@@ -140,5 +140,3 @@ void metaTile::expire_tiles(int sock, char * host, char * uri)
}
}
}
-
-
diff --git a/src/mod_tile.c b/src/mod_tile.c
index 65ec74b8..cc583c01 100644
--- a/src/mod_tile.c
+++ b/src/mod_tile.c
@@ -95,6 +95,8 @@ char *mutexfilename;
int layerCount = 0;
int global_max_zoom = 0;
+int foreground = 0;
+
struct storage_backends {
struct storage_backend ** stores;
int noBackends;
@@ -2887,4 +2889,3 @@ merge_tile_config, /* merge server config */
tile_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
-
diff --git a/src/parameterize_style.cpp b/src/parameterize_style.cpp
index a0a61f2e..b0976faf 100644
--- a/src/parameterize_style.cpp
+++ b/src/parameterize_style.cpp
@@ -22,11 +22,10 @@
#include
#include
-#include
-
#include
#include "parameterize_style.hpp"
+#include "g_logger.h"
static void parameterize_map_language(mapnik::Map &m, char * parameter)
@@ -37,7 +36,7 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
char name_replace[256];
name_replace[0] = 0;
- syslog(LOG_DEBUG, "Internationalizing map to language parameter: %s", parameter);
+ g_logger(G_LOG_LEVEL_DEBUG, "Internationalizing map to language parameter: %s", parameter);
tok = strtok(data, ",");
if (!tok) {
@@ -93,14 +92,14 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
parameterize_function_ptr init_parameterization_function(char * function_name)
{
- syslog(LOG_INFO, "Loading parameterization function for %s", function_name);
+ g_logger(G_LOG_LEVEL_INFO, "Loading parameterization function for %s", function_name);
if (strcmp(function_name, "") == 0) {
return NULL;
} else if (strcmp(function_name, "language") == 0) {
return parameterize_map_language;
} else {
- syslog(LOG_INFO, "WARNING: unknown parameterization function for %s", function_name);
+ g_logger(G_LOG_LEVEL_WARNING, "unknown parameterization function for %s", function_name);
}
return NULL;
diff --git a/src/protocol_helper.c b/src/protocol_helper.c
index 5e5f2c70..5c899a72 100644
--- a/src/protocol_helper.c
+++ b/src/protocol_helper.c
@@ -18,17 +18,19 @@
#include "protocol.h"
#include
#include
-#include
#include
#include
+#include
+
+#include "g_logger.h"
int send_cmd(struct protocol * cmd, int fd)
{
int ret;
- syslog(LOG_DEBUG, "DEBUG: Sending render cmd(%i %s %i/%i/%i) with protocol version %i to fd %i\n", cmd->cmd, cmd->xmlname, cmd->z, cmd->x, cmd->y, cmd->ver, fd);
+ g_logger(G_LOG_LEVEL_DEBUG, "Sending render cmd(%i %s %i/%i/%i) with protocol version %i to fd %i", cmd->cmd, cmd->xmlname, cmd->z, cmd->x, cmd->y, cmd->ver, fd);
if ((cmd->ver > 3) || (cmd->ver < 1)) {
- syslog(LOG_WARNING, "WARNING: Failed to send render cmd with unknown protocol version %i on fd %d\n", cmd->ver, fd);
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to send render cmd with unknown protocol version %i on fd %d", cmd->ver, fd);
return -1;
}
@@ -47,8 +49,8 @@ int send_cmd(struct protocol * cmd, int fd)
}
if ((ret != sizeof(struct protocol)) && (ret != sizeof(struct protocol_v2)) && (ret != sizeof(struct protocol_v1))) {
- syslog(LOG_WARNING, "WARNING: Failed to send render cmd on fd %i\n", fd);
- perror("send error");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to send render cmd on fd %i", fd);
+ g_logger(G_LOG_LEVEL_ERROR, "send error: %s", strerror(errno));
}
return ret;
@@ -61,19 +63,19 @@ int recv_cmd(struct protocol * cmd, int fd, int block)
ret = recv(fd, cmd, sizeof(struct protocol_v1), block ? MSG_WAITALL : MSG_DONTWAIT);
if (ret < 1) {
- syslog(LOG_INFO, "DEBUG: Failed to read cmd on fd %i", fd);
+ g_logger(G_LOG_LEVEL_DEBUG, "Failed to read cmd on fd %i", fd);
return -1;
} else if (ret < sizeof(struct protocol_v1)) {
- syslog(LOG_INFO, "DEBUG: Read incomplete cmd on fd %i", fd);
+ g_logger(G_LOG_LEVEL_DEBUG, "Read incomplete cmd on fd %i", fd);
return 0;
}
if ((cmd->ver > 3) || (cmd->ver < 1)) {
- syslog(LOG_WARNING, "WARNING: Failed to receive render cmd with unknown protocol version %i\n", cmd->ver);
+ g_logger(G_LOG_LEVEL_WARNING, "Failed to receive render cmd with unknown protocol version %i", cmd->ver);
return -1;
}
- syslog(LOG_DEBUG, "DEBUG: Got incoming request with protocol version %i\n", cmd->ver);
+ g_logger(G_LOG_LEVEL_DEBUG, "Got incoming request with protocol version %i", cmd->ver);
switch (cmd->ver) {
case 1:
@@ -90,7 +92,7 @@ int recv_cmd(struct protocol * cmd, int fd, int block)
}
if ((cmd->ver > 1) && (ret2 < 1)) {
- syslog(LOG_WARNING, "WARNING: Socket prematurely closed: %i\n", fd);
+ g_logger(G_LOG_LEVEL_WARNING, "Socket prematurely closed: %i", fd);
return -1;
}
@@ -100,6 +102,6 @@ int recv_cmd(struct protocol * cmd, int fd, int block)
return ret;
}
- syslog(LOG_WARNING, "WARNING: Socket read wrong number of bytes: %i -> %li, %li\n", ret, sizeof(struct protocol_v2), sizeof(struct protocol));
+ g_logger(G_LOG_LEVEL_WARNING, "Socket read wrong number of bytes: %i -> %li, %li", ret, sizeof(struct protocol_v2), sizeof(struct protocol));
return 0;
}
diff --git a/src/render_expired.c b/src/render_expired.c
index 0a84b3ae..a606229c 100644
--- a/src/render_expired.c
+++ b/src/render_expired.c
@@ -73,6 +73,8 @@ static int maxZoom = 18;
static int verbose = 0;
static int maxLoad = MAX_LOAD_OLD;
+int foreground = 1;
+
void display_rate(struct timeval start, struct timeval end, int num)
{
int d_s, d_us;
@@ -122,17 +124,17 @@ int main(int argc, char **argv)
while (1) {
int option_index = 0;
static struct option long_options[] = {
- {"min-zoom", 1, 0, 'z'},
- {"max-zoom", 1, 0, 'Z'},
- {"socket", 1, 0, 's'},
- {"num-threads", 1, 0, 'n'},
- {"delete-from", 1, 0, 'd'},
- {"touch-from", 1, 0, 'T'},
- {"tile-dir", 1, 0, 't'},
- {"max-load", 1, 0, 'l'},
- {"map", 1, 0, 'm'},
- {"verbose", 0, 0, 'v'},
- {"help", 0, 0, 'h'},
+ {"min-zoom", required_argument, 0, 'z'},
+ {"max-zoom", required_argument, 0, 'Z'},
+ {"socket", required_argument, 0, 's'},
+ {"num-threads", required_argument, 0, 'n'},
+ {"delete-from", required_argument, 0, 'd'},
+ {"touch-from", required_argument, 0, 'T'},
+ {"tile-dir", required_argument, 0, 't'},
+ {"max-load", required_argument, 0, 'l'},
+ {"map", required_argument, 0, 'm'},
+ {"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
diff --git a/src/render_list.c b/src/render_list.c
index d1b92055..cb75e7be 100644
--- a/src/render_list.c
+++ b/src/render_list.c
@@ -57,6 +57,8 @@ static int maxZoom = MAX_ZOOM;
static int verbose = 0;
static int maxLoad = MAX_LOAD_OLD;
+int foreground = 1;
+
void display_rate(struct timeval start, struct timeval end, int num)
{
@@ -93,21 +95,21 @@ int main(int argc, char **argv)
while (1) {
int option_index = 0;
static struct option long_options[] = {
- {"min-zoom", 1, 0, 'z'},
- {"max-zoom", 1, 0, 'Z'},
- {"min-x", 1, 0, 'x'},
- {"max-x", 1, 0, 'X'},
- {"min-y", 1, 0, 'y'},
- {"max-y", 1, 0, 'Y'},
- {"socket", 1, 0, 's'},
- {"num-threads", 1, 0, 'n'},
- {"max-load", 1, 0, 'l'},
- {"tile-dir", 1, 0, 't'},
- {"map", 1, 0, 'm'},
- {"verbose", 0, 0, 'v'},
- {"force", 0, 0, 'f'},
- {"all", 0, 0, 'a'},
- {"help", 0, 0, 'h'},
+ {"min-zoom", required_argument, 0, 'z'},
+ {"max-zoom", required_argument, 0, 'Z'},
+ {"min-x", required_argument, 0, 'x'},
+ {"max-x", required_argument, 0, 'X'},
+ {"min-y", required_argument, 0, 'y'},
+ {"max-y", required_argument, 0, 'Y'},
+ {"socket", required_argument, 0, 's'},
+ {"num-threads", required_argument, 0, 'n'},
+ {"max-load", required_argument, 0, 'l'},
+ {"tile-dir", required_argument, 0, 't'},
+ {"map", required_argument, 0, 'm'},
+ {"verbose", no_argument, 0, 'v'},
+ {"force", no_argument, 0, 'f'},
+ {"all", no_argument, 0, 'a'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
diff --git a/src/render_old.c b/src/render_old.c
index 1a7827be..900a5a39 100644
--- a/src/render_old.c
+++ b/src/render_old.c
@@ -63,6 +63,8 @@ static int max_load = MAX_LOAD_OLD;
static time_t planetTime;
static struct timeval start, end;
+int foreground = 1;
+
void display_rate(struct timeval start, struct timeval end, int num)
@@ -200,17 +202,17 @@ int main(int argc, char **argv)
while (1) {
int option_index = 0;
static struct option long_options[] = {
- {"config", 1, 0, 'c'},
- {"min-zoom", 1, 0, 'z'},
- {"max-zoom", 1, 0, 'Z'},
- {"max-load", 1, 0, 'l'},
- {"socket", 1, 0, 's'},
- {"num-threads", 1, 0, 'n'},
- {"tile-dir", 1, 0, 't'},
- {"timestamp", 1, 0, 'T'},
- {"map", 1, 0, 'm'},
- {"verbose", 0, 0, 'v'},
- {"help", 0, 0, 'h'},
+ {"config", required_argument, 0, 'c'},
+ {"min-zoom", required_argument, 0, 'z'},
+ {"max-zoom", required_argument, 0, 'Z'},
+ {"max-load", required_argument, 0, 'l'},
+ {"socket", required_argument, 0, 's'},
+ {"num-threads", required_argument, 0, 'n'},
+ {"tile-dir", required_argument, 0, 't'},
+ {"timestamp", required_argument, 0, 'T'},
+ {"map", required_argument, 0, 'm'},
+ {"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
diff --git a/src/request_queue.c b/src/request_queue.c
index 18c773a8..89b9afcf 100644
--- a/src/request_queue.c
+++ b/src/request_queue.c
@@ -21,9 +21,10 @@
#include
#include
#include
-#include
+
#include "render_config.h"
#include "request_queue.h"
+#include "g_logger.h"
static int calcHashKey(struct request_queue *queue, struct item *item)
{
@@ -282,7 +283,7 @@ enum protoCmd request_queue_add_request(struct request_queue * queue, struct ite
req = &(item->req);
if (queue == NULL) {
- printf("queue os NULL");
+ g_logger(G_LOG_LEVEL_CRITICAL, "queue os NULL");
exit(3);
}
@@ -364,7 +365,7 @@ void request_queue_remove_request(struct request_queue * queue, struct item * re
pthread_mutex_lock(&(queue->qLock));
if (request->inQueue != queueRender) {
- syslog(LOG_WARNING, "Removing request from queue, even though not on rendering queue");
+ g_logger(G_LOG_LEVEL_WARNING, "Removing request from queue, even though not on rendering queue");
}
if (render_time > 0) {
@@ -455,7 +456,7 @@ struct request_queue * request_queue_init()
res = pthread_mutex_init(&(queue->qLock), NULL);
if (res != 0) {
- syslog(LOG_ERR, "Failed to create mutex for request_queue");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to create mutex for request_queue");
free(queue);
return NULL;
}
@@ -463,7 +464,7 @@ struct request_queue * request_queue_init()
res = pthread_cond_init(&(queue->qCond), NULL);
if (res != 0) {
- syslog(LOG_ERR, "Failed to create condition variable for request_queue");
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to create condition variable for request_queue");
pthread_mutex_destroy(&(queue->qLock));
free(queue);
return NULL;
diff --git a/src/speedtest.cpp b/src/speedtest.cpp
index 3b89aad1..b9678a35 100644
--- a/src/speedtest.cpp
+++ b/src/speedtest.cpp
@@ -73,6 +73,8 @@ static double boundx1 = 3.2;
static double boundy1 = 58.8;
#endif
+int foreground = 1;
+
static double minmax(double a, double b, double c)
{
@@ -209,11 +211,11 @@ int main(int argc, char **argv)
while (1) {
int option_index = 0;
static struct option long_options[] = {
- {"socket", 1, 0, 's'},
- {"num-threads", 1, 0, 'n'},
- {"map", 1, 0, 'm'},
- {"verbose", 0, 0, 'v'},
- {"help", 0, 0, 'h'},
+ {"socket", required_argument, 0, 's'},
+ {"num-threads", required_argument, 0, 'n'},
+ {"map", required_argument, 0, 'm'},
+ {"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
diff --git a/src/store.c b/src/store.c
index a944b0ab..f1a7fedb 100644
--- a/src/store.c
+++ b/src/store.c
@@ -22,44 +22,9 @@
#include "store_ro_http_proxy.h"
#include "store_ro_composite.h"
#include "store_null.h"
+#include "g_logger.h"
-//TODO: Make this function handle different logging backends, depending on if on compiles it from apache or something else
-void log_message(int log_lvl, const char *format, ...)
-{
- va_list ap;
- char *msg = malloc(1000 * sizeof(char));
-
- va_start(ap, format);
-
-
-
- if (msg) {
- vsnprintf(msg, 1000, format, ap);
-
- switch (log_lvl) {
- case STORE_LOGLVL_DEBUG:
- fprintf(stderr, "debug: %s\n", msg);
- break;
-
- case STORE_LOGLVL_INFO:
- fprintf(stderr, "info: %s\n", msg);
- break;
-
- case STORE_LOGLVL_WARNING:
- fprintf(stderr, "WARNING: %s\n", msg);
- break;
-
- case STORE_LOGLVL_ERR:
- fprintf(stderr, "ERROR: %s\n", msg);
- break;
- }
-
- free(msg);
- fflush(stderr);
- }
-
- va_end(ap);
-}
+extern int foreground;
/**
* In Apache 2.2, we call the init_storage_backend once per process. For mpm_worker and mpm_event multiple threads therefore use the same
@@ -74,57 +39,57 @@ struct storage_backend * init_storage_backend(const char * options)
//Determine the correct storage backend based on the options string
if (strlen(options) == 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_backend: Options string was empty");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_backend: Options string was empty");
return NULL;
}
if (options[0] == '/') {
if (stat(options, &st) != 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_backend: Failed to stat %s with error: %s", options, strerror(errno));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_backend: Failed to stat %s with error: %s", options, strerror(errno));
return NULL;
}
if (S_ISDIR(st.st_mode)) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising file storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising file storage backend at: %s", options);
store = init_storage_file(options);
return store;
} else {
- log_message(STORE_LOGLVL_ERR, "init_storage_backend: %s is not a directory", options, strerror(errno));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_backend: %s is not a directory", options, strerror(errno));
return NULL;
}
}
if (strstr(options, "rados://") == options) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising rados storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising rados storage backend at: %s", options);
store = init_storage_rados(options);
return store;
}
if (strstr(options, "memcached://") == options) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising memcached storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising memcached storage backend at: %s", options);
store = init_storage_memcached(options);
return store;
}
if (strstr(options, "ro_http_proxy://") == options) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising ro_http_proxy storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising ro_http_proxy storage backend at: %s", options);
store = init_storage_ro_http_proxy(options);
return store;
}
if (strstr(options, "composite:{") == options) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising ro_composite storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising ro_composite storage backend at: %s", options);
store = init_storage_ro_composite(options);
return store;
}
if (strstr(options, "null://") == options) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_backend: initialising null storage backend at: %s", options);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_backend: initialising null storage backend at: %s", options);
store = init_storage_null();
return store;
}
- log_message(STORE_LOGLVL_ERR, "init_storage_backend: No valid storage backend found for options: %s", options);
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_backend: No valid storage backend found for options: %s", options);
return store;
}
diff --git a/src/store_file.c b/src/store_file.c
index 36277fe2..2a19255f 100644
--- a/src/store_file.c
+++ b/src/store_file.c
@@ -42,6 +42,7 @@
#include "store_file.h"
#include "store_file_utils.h"
#include "protocol.h"
+#include "g_logger.h"
static time_t getPlanetTime(const char * tile_dir, const char * xmlname)
@@ -215,7 +216,7 @@ static int file_metatile_write(struct storage_backend * store, const char *xmlco
int res;
xyzo_to_meta(meta_path, sizeof(meta_path), (char *)(store->storage_ctx), xmlconfig, options, x, y, z);
- log_message(STORE_LOGLVL_DEBUG, "Creating and writing a metatile to %s\n", meta_path);
+ g_logger(G_LOG_LEVEL_DEBUG, "Creating and writing a metatile to %s", meta_path);
tmp = malloc(sizeof(char) * strlen(meta_path) + 24);
snprintf(tmp, strlen(meta_path) + 24, "%s.%lu", meta_path, pthread_self());
@@ -229,7 +230,7 @@ static int file_metatile_write(struct storage_backend * store, const char *xmlco
fd = open(tmp, O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (fd < 0) {
- log_message(STORE_LOGLVL_WARNING, "Error creating file %s: %s\n", meta_path, strerror(errno));
+ g_logger(G_LOG_LEVEL_WARNING, "Error creating file %s: %s", meta_path, strerror(errno));
free(tmp);
return -1;
}
@@ -237,7 +238,7 @@ static int file_metatile_write(struct storage_backend * store, const char *xmlco
res = write(fd, buf, sz);
if (res != sz) {
- log_message(STORE_LOGLVL_WARNING, "Error writing file %s: %s\n", meta_path, strerror(errno));
+ g_logger(G_LOG_LEVEL_WARNING, "Error writing file %s: %s", meta_path, strerror(errno));
close(fd);
free(tmp);
return -1;
@@ -256,7 +257,7 @@ static int file_metatile_delete(struct storage_backend * store, const char *xmlc
//TODO: deal with options
xyz_to_meta(meta_path, sizeof(meta_path), (char *)(store->storage_ctx), xmlconfig, x, y, z);
- log_message(STORE_LOGLVL_DEBUG, "Deleting metatile from %s\n", meta_path);
+ g_logger(G_LOG_LEVEL_DEBUG, "Deleting metatile from %s", meta_path);
return unlink(meta_path);
}
@@ -308,7 +309,7 @@ struct storage_backend * init_storage_file(const char * tile_dir)
struct storage_backend * store = malloc(sizeof(struct storage_backend));
if (store == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_file: Failed to allocate memory for storage backend");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_file: Failed to allocate memory for storage backend");
return NULL;
}
diff --git a/src/store_file_utils.c b/src/store_file_utils.c
index b745202b..b7e6b2c8 100644
--- a/src/store_file_utils.c
+++ b/src/store_file_utils.c
@@ -28,6 +28,7 @@
#include "render_config.h"
#include "store_file.h"
#include "store_file_utils.h"
+#include "g_logger.h"
// Build parent directories for the specified file name
// Note: the part following the trailing / is ignored
@@ -69,7 +70,7 @@ int mkdirp(const char *path)
if (!stat(tmp, &s)) {
if (!S_ISDIR(s.st_mode)) {
- fprintf(stderr, "Error, is not a directory: %s\n", tmp);
+ g_logger(G_LOG_LEVEL_ERROR, "Error, not a directory: %s", tmp);
return 1;
}
} else if (mkdir(tmp, 0777)) {
@@ -110,7 +111,7 @@ static int check_xyz(int x, int y, int z)
}
if (oob) {
- fprintf(stderr, "got bad co-ords: x(%d) y(%d) z(%d)\n", x, y, z);
+ g_logger(G_LOG_LEVEL_ERROR, "got bad co-ords: x(%d) y(%d) z(%d)", x, y, z);
}
return oob;
@@ -146,21 +147,21 @@ int path_to_xyz(const char *tilepath, const char *path, char *xmlconfig, int *px
;
if (tilepath[i]) {
- fprintf(stderr, "Tile path does not match settings (%s): %s\n", tilepath, path);
+ g_logger(G_LOG_LEVEL_ERROR, "Tile path does not match settings (%s): %s", tilepath, path);
return 1;
}
n = sscanf(path + i, "/%40[^/]/%d/%d/%d/%d/%d/%d", xmlconfig, pz, &hash[0], &hash[1], &hash[2], &hash[3], &hash[4]);
if (n != 7) {
- fprintf(stderr, "Failed to parse tile path: %s\n", path);
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to parse tile path: %s", path);
return 1;
} else {
x = y = 0;
for (i = 0; i < 5; i++) {
if (hash[i] < 0 || hash[i] > 255) {
- fprintf(stderr, "Failed to parse tile path (invalid %d): %s\n", hash[i], path);
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to parse tile path (invalid %d): %s", hash[i], path);
return 2;
}
@@ -181,7 +182,7 @@ int path_to_xyz(const char *tilepath, const char *path, char *xmlconfig, int *px
n = sscanf(path, TILE_PATH "/%40[^/]/%d/%d/%d", xmlconfig, pz, px, py);
if (n != 4) {
- fprintf(stderr, "Failed to parse tile path: %s\n", path);
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to parse tile path: %s", path);
return 1;
} else {
return check_xyz(*px, *py, *pz);
diff --git a/src/store_memcached.c b/src/store_memcached.c
index 9601e5cb..9a59bb89 100644
--- a/src/store_memcached.c
+++ b/src/store_memcached.c
@@ -40,6 +40,7 @@
#include "metatile.h"
#include "render_config.h"
#include "protocol.h"
+#include "g_logger.h"
#ifdef HAVE_LIBMEMCACHED
@@ -194,7 +195,7 @@ static int memcached_metatile_write(struct storage_backend * store, const char *
memcpy(buf2, &tile_stat, sizeof(tile_stat));
memcpy(buf2 + sizeof(tile_stat), buf, sz);
- log_message(STORE_LOGLVL_DEBUG, "Trying to create and write a metatile to %s\n", memcached_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
+ g_logger(G_LOG_LEVEL_DEBUG, "Trying to create and write a metatile to %s", memcached_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
snprintf(meta_path, PATH_MAX - 1, "%s/%d/%d/%d.meta", xmlconfig, x, y, z);
@@ -271,7 +272,7 @@ struct storage_backend * init_storage_memcached(const char * connection_string)
{
#ifndef HAVE_LIBMEMCACHED
- log_message(STORE_LOGLVL_ERR, "init_storage_memcached: Support for memcached has not been compiled into this program");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Support for memcached has not been compiled into this program");
return NULL;
#else
struct storage_backend * store = malloc(sizeof(struct storage_backend));
@@ -279,14 +280,14 @@ struct storage_backend * init_storage_memcached(const char * connection_string)
char * connection_str = "--server=localhost";
if (store == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_memcached: Failed to allocate memory for storage backend");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Failed to allocate memory for storage backend");
return NULL;
}
ctx = memcached(connection_str, strlen(connection_str));
if (ctx == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_memcached: Failed to create memcached ctx");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Failed to create memcached ctx");
free(store);
return NULL;
}
diff --git a/src/store_null.c b/src/store_null.c
index 1aa5bf95..9329bde8 100644
--- a/src/store_null.c
+++ b/src/store_null.c
@@ -21,6 +21,8 @@
#include
#include
+#include "g_logger.h"
+
static int tile_read(struct storage_backend * store,
const char *xmlconfig,
const char *options,
@@ -90,7 +92,7 @@ struct storage_backend *init_storage_null()
struct storage_backend *store = malloc(sizeof * store);
if (store == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_null: Failed to allocate memory for storage backend");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_null: Failed to allocate memory for storage backend");
return NULL;
}
diff --git a/src/store_rados.c b/src/store_rados.c
index 1d089a5b..4333682e 100644
--- a/src/store_rados.c
+++ b/src/store_rados.c
@@ -43,6 +43,7 @@
#include "metatile.h"
#include "render_config.h"
#include "protocol.h"
+#include "g_logger.h"
#ifdef HAVE_LIBRADOS
@@ -92,18 +93,18 @@ static char * read_meta_data(struct storage_backend * store, const char *xmlconf
y &= ~mask;
if ((ctx->metadata_cache.x == x) && (ctx->metadata_cache.y == y) && (ctx->metadata_cache.z == z) && (strcmp(ctx->metadata_cache.xmlname, xmlconfig) == 0)) {
- //log_message(STORE_LOGLVL_DEBUG, "Returning cached data for %s %i %i %i", ctx->metadata_cache.xmlname, ctx->metadata_cache.x, ctx->metadata_cache.y, ctx->metadata_cache.z);
+ g_logger(G_LOG_LEVEL_DEBUG, "Returning cached data for %s %i %i %i", ctx->metadata_cache.xmlname, ctx->metadata_cache.x, ctx->metadata_cache.y, ctx->metadata_cache.z);
return ctx->metadata_cache.data;
} else {
- //log_message(STORE_LOGLVL_DEBUG, "Retrieving fresh metadata");
+ g_logger(G_LOG_LEVEL_DEBUG, "Retrieving fresh metadata");
rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path);
err = rados_read(ctx->io, meta_path, ctx->metadata_cache.data, header_len, 0);
if (err < 0) {
if (-err == ENOENT) {
- log_message(STORE_LOGLVL_DEBUG, "cannot read data from rados pool %s: %s\n", ctx->pool, strerror(-err));
+ g_logger(G_LOG_LEVEL_DEBUG, "cannot read data from rados pool %s: %s", ctx->pool, strerror(-err));
} else {
- log_message(STORE_LOGLVL_ERR, "cannot read data from rados pool %s: %s\n", ctx->pool, strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "cannot read data from rados pool %s: %s", ctx->pool, strerror(-err));
}
ctx->metadata_cache.x = -1;
@@ -243,12 +244,12 @@ static int rados_metatile_write(struct storage_backend * store, const char *xmlc
memcpy(buf2 + sizeof(tile_stat), buf, sz);
rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path);
- log_message(STORE_LOGLVL_DEBUG, "Trying to create and write a tile to %s\n", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
+ g_logger(G_LOG_LEVEL_DEBUG, "Trying to create and write a tile to %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
err = rados_write_full(((struct rados_ctx *)store->storage_ctx)->io, meta_path, buf2, sz2);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "cannot write %s: %s\n", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "cannot write %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
free(buf2);
return -1;
}
@@ -273,7 +274,7 @@ static int rados_metatile_delete(struct storage_backend * store, const char *xml
err = rados_remove(ctx->io, meta_path);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "failed to delete %s: %s\n", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "failed to delete %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
return -1;
}
@@ -296,10 +297,10 @@ static int rados_metatile_expire(struct storage_backend * store, const char *xml
if (err < 0) {
if (-err == ENOENT) {
- log_message(STORE_LOGLVL_DEBUG, "Tile %s does not exist, can't expire", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
+ g_logger(G_LOG_LEVEL_DEBUG, "Tile %s does not exist, can't expire", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp));
return -1;
} else {
- log_message(STORE_LOGLVL_ERR, "Failed to read tile metadata for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "Failed to read tile metadata for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
}
return -2;
@@ -310,7 +311,7 @@ static int rados_metatile_expire(struct storage_backend * store, const char *xml
err = rados_write(ctx->io, meta_path, (char *)&tile_stat, sizeof(struct stat_info), 0);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "failed to write expiry data for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "failed to write expiry data for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err));
return -3;
}
@@ -324,7 +325,7 @@ static int rados_close_storage(struct storage_backend * store)
rados_ioctx_destroy(ctx->io);
rados_shutdown(ctx->cluster);
- log_message(STORE_LOGLVL_DEBUG, "rados_close_storage: Closed rados backend");
+ g_logger(G_LOG_LEVEL_DEBUG, "rados_close_storage: Closed rados backend");
free(ctx->metadata_cache.data);
free(ctx->pool);
free(ctx);
@@ -340,7 +341,7 @@ struct storage_backend * init_storage_rados(const char * connection_string)
{
#ifndef HAVE_LIBRADOS
- log_message(STORE_LOGLVL_ERR, "init_storage_rados: Support for rados has not been compiled into this program");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: Support for rados has not been compiled into this program");
return NULL;
#else
struct rados_ctx * ctx = malloc(sizeof(struct rados_ctx));
@@ -368,7 +369,7 @@ struct storage_backend * init_storage_rados(const char * connection_string)
err = rados_create(&(ctx->cluster), NULL);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_rados: cannot create a cluster handle: %s", strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: cannot create a cluster handle: %s", strerror(-err));
free(ctx);
free(store);
return NULL;
@@ -377,7 +378,7 @@ struct storage_backend * init_storage_rados(const char * connection_string)
err = rados_conf_read_file(ctx->cluster, conf);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_rados: failed to read rados config file %s: %s", conf, strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: failed to read rados config file %s: %s", conf, strerror(-err));
free(ctx);
free(store);
return NULL;
@@ -388,7 +389,7 @@ struct storage_backend * init_storage_rados(const char * connection_string)
pthread_mutex_unlock(&qLock);
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_rados: failed to connect to rados cluster: %s", strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: failed to connect to rados cluster: %s", strerror(-err));
free(ctx);
free(store);
return NULL;
@@ -397,14 +398,14 @@ struct storage_backend * init_storage_rados(const char * connection_string)
err = rados_ioctx_create(ctx->cluster, ctx->pool, &(ctx->io));
if (err < 0) {
- log_message(STORE_LOGLVL_ERR, "init_storage_rados: failed to initialise rados io context to pool %s: %s", ctx->pool, strerror(-err));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: failed to initialise rados io context to pool %s: %s", ctx->pool, strerror(-err));
rados_shutdown(ctx->cluster);
free(ctx);
free(store);
return NULL;
}
- log_message(STORE_LOGLVL_DEBUG, "init_storage_rados: Initialised rados backend for pool %s with config %s", ctx->pool, conf);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_rados: Initialised rados backend for pool %s with config %s", ctx->pool, conf);
ctx->metadata_cache.data = malloc(sizeof(struct stat_info) + sizeof(struct meta_layout) + METATILE * METATILE * sizeof(struct entry));
diff --git a/src/store_ro_composite.c b/src/store_ro_composite.c
index fb6e5762..0badf890 100644
--- a/src/store_ro_composite.c
+++ b/src/store_ro_composite.c
@@ -34,6 +34,7 @@
#include "store_ro_composite.h"
#include "render_config.h"
#include "protocol.h"
+#include "g_logger.h"
#ifdef WANT_STORE_COMPOSITE
@@ -64,7 +65,7 @@ static cairo_status_t write_png_stream_to_byte_array(void *in_closure, const uns
{
png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *) in_closure;
- //log_message(STORE_LOGLVL_DEBUG, "ro_composite_tile: writing to byte array: pos: %i, length: %i", closure->pos, length);
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_composite_tile: writing to byte array: pos: %i, length: %i", closure->pos, length);
if ((closure->pos + length) > (closure->max_size)) {
return CAIRO_STATUS_WRITE_ERROR;
@@ -80,7 +81,7 @@ static cairo_status_t read_png_stream_from_byte_array(void *in_closure, unsigned
{
png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *) in_closure;
- //log_message(STORE_LOGLVL_DEBUG, "ro_composite_tile: reading from byte array: pos: %i, length: %i", closure->pos, length);
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_composite_tile: reading from byte array: pos: %i, length: %i", closure->pos, length);
if ((closure->pos + length) > (closure->max_size)) {
return CAIRO_STATUS_READ_ERROR;
@@ -179,21 +180,21 @@ static char * ro_composite_tile_storage_id(struct storage_backend * store, const
static int ro_composite_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz)
{
- log_message(STORE_LOGLVL_ERR, "ro_composite_metatile_write: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_write: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
static int ro_composite_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z)
{
- log_message(STORE_LOGLVL_ERR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
static int ro_composite_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z)
{
- log_message(STORE_LOGLVL_ERR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
@@ -221,7 +222,7 @@ struct storage_backend * init_storage_ro_composite(const char * connection_strin
{
#ifndef WANT_STORE_COMPOSITE
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_coposite: Support for compositing storage has not been compiled into this program");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_coposite: Support for compositing storage has not been compiled into this program");
return NULL;
#else
struct storage_backend * store = malloc(sizeof(struct storage_backend));
@@ -230,10 +231,10 @@ struct storage_backend * init_storage_ro_composite(const char * connection_strin
char * connection_string_secondary;
char * tmp;
- log_message(STORE_LOGLVL_DEBUG, "init_storage_ro_composite: initialising compositing storage backend for %s", connection_string);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_composite: initialising compositing storage backend for %s", connection_string);
if (!store || !ctx) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_composite: failed to allocate memory for context");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_composite: failed to allocate memory for context");
if (store) {
free(store);
@@ -253,8 +254,8 @@ struct storage_backend * init_storage_ro_composite(const char * connection_strin
connection_string_secondary = strdup(connection_string_secondary + 2);
connection_string_secondary[strlen(connection_string_secondary) - 1] = 0;
- log_message(STORE_LOGLVL_DEBUG, "init_storage_ro_composite: Primary storage backend: %s", connection_string_primary);
- log_message(STORE_LOGLVL_DEBUG, "init_storage_ro_composite: Secondary storage backend: %s", connection_string_secondary);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_composite: Primary storage backend: %s", connection_string_primary);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_composite: Secondary storage backend: %s", connection_string_secondary);
tmp = strstr(connection_string_primary, ",");
memcpy(ctx->xmlconfig_primary, connection_string_primary, tmp - connection_string_primary);
@@ -262,7 +263,7 @@ struct storage_backend * init_storage_ro_composite(const char * connection_strin
ctx->store_primary = init_storage_backend(tmp + 1);
if (ctx->store_primary == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_composite: failed to initialise primary storage backend");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_composite: failed to initialise primary storage backend");
free(ctx);
free(store);
return NULL;
@@ -274,7 +275,7 @@ struct storage_backend * init_storage_ro_composite(const char * connection_strin
ctx->store_secondary = init_storage_backend(tmp + 1);
if (ctx->store_secondary == NULL) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_composite: failed to initialise secondary storage backend");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_composite: failed to initialise secondary storage backend");
ctx->store_primary->close_storage(ctx->store_primary);
free(ctx);
free(store);
diff --git a/src/store_ro_http_proxy.c b/src/store_ro_http_proxy.c
index 8a5b3fbd..9a162120 100644
--- a/src/store_ro_http_proxy.c
+++ b/src/store_ro_http_proxy.c
@@ -33,6 +33,7 @@
#include "store_ro_http_proxy.h"
#include "render_config.h"
#include "protocol.h"
+#include "g_logger.h"
#ifdef HAVE_LIBCURL
@@ -70,7 +71,7 @@ static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, v
chunk->memory = malloc(realsize);
}
- //log_message(STORE_LOGLVL_DEBUG, "ro_http_proxy_tile_read: writing a chunk: Position %i, size %i", chunk->size, realsize);
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_read: writing a chunk: Position %i, size %i", chunk->size, realsize);
memcpy(&(chunk->memory[chunk->size]), contents, realsize);
chunk->size += realsize;
@@ -94,17 +95,17 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha
//TODO: Deal with options
if ((ctx->cache.x == x) && (ctx->cache.y == y) && (ctx->cache.z == z) && (strcmp(ctx->cache.xmlname, xmlconfig) == 0)) {
- log_message(STORE_LOGLVL_DEBUG, "ro_http_proxy_tile_fetch: Got a cached tile");
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_fetch: Got a cached tile");
return 1;
} else {
- log_message(STORE_LOGLVL_DEBUG, "ro_http_proxy_tile_fetch: Fetching tile");
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_fetch: Fetching tile");
chunk.memory = NULL;
chunk.size = 0;
path = malloc(PATH_MAX);
ro_http_proxy_xyz_to_storagekey(store, x, y, z, path);
- log_message(STORE_LOGLVL_DEBUG, "ro_http_proxy_tile_fetch: proxing file %s", path);
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_fetch: proxing file %s", path);
curl_easy_setopt(ctx->ctx, CURLOPT_URL, path);
curl_easy_setopt(ctx->ctx, CURLOPT_WRITEFUNCTION, write_memory_callback);
@@ -114,7 +115,7 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha
free(path);
if (res != CURLE_OK) {
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_tile_fetch: failed to retrieve file: %s", curl_easy_strerror(res));
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_tile_fetch: failed to retrieve file: %s", curl_easy_strerror(res));
ctx->cache.x = -1;
ctx->cache.y = -1;
ctx->cache.z = -1;
@@ -124,7 +125,7 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha
res = curl_easy_getinfo(ctx->ctx, CURLINFO_RESPONSE_CODE, &httpCode);
if (res != CURLE_OK) {
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_tile_fetch: failed to retrieve HTTP code: %s", curl_easy_strerror(res));
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_tile_fetch: failed to retrieve HTTP code: %s", curl_easy_strerror(res));
ctx->cache.x = -1;
ctx->cache.y = -1;
ctx->cache.z = -1;
@@ -142,7 +143,7 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha
ctx->cache.st_stat.expired = 0;
res = curl_easy_getinfo(ctx->ctx, CURLINFO_FILETIME, &(ctx->cache.st_stat.mtime));
ctx->cache.st_stat.atime = 0;
- log_message(STORE_LOGLVL_DEBUG, "ro_http_proxy_tile_read: Read file of size %i", chunk.size);
+ g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_read: Read file of size %i", chunk.size);
break;
}
@@ -172,14 +173,14 @@ static int ro_http_proxy_tile_read(struct storage_backend * store, const char *x
if (ro_http_proxy_tile_retrieve(store, xmlconfig, options, x, y, z) > 0) {
if (ctx->cache.st_stat.size > sz) {
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_tile_read: size was too big, overrun %i %i", sz, ctx->cache.st_stat.size);
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_tile_read: size was too big, overrun %i %i", sz, ctx->cache.st_stat.size);
return -1;
}
memcpy(buf, ctx->cache.tile, ctx->cache.st_stat.size);
return ctx->cache.st_stat.size;
} else {
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_tile_read: Fetching didn't work");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_tile_read: Fetching didn't work");
return -1;
}
}
@@ -210,21 +211,21 @@ static char * ro_http_proxy_tile_storage_id(struct storage_backend * store, cons
static int ro_http_proxy_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz)
{
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_metatile_write: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_write: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
static int ro_http_proxy_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z)
{
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
static int ro_http_proxy_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z)
{
- log_message(STORE_LOGLVL_ERR, "ro_http_proxy_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
+ g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented");
return -1;
}
@@ -255,17 +256,17 @@ struct storage_backend * init_storage_ro_http_proxy(const char * connection_stri
{
#ifndef HAVE_LIBCURL
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_http_proxy: Support for curl and therefore the http proxy storage has not been compiled into this program");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_http_proxy: Support for curl and therefore the http proxy storage has not been compiled into this program");
return NULL;
#else
struct storage_backend * store = malloc(sizeof(struct storage_backend));
struct ro_http_proxy_ctx * ctx = malloc(sizeof(struct ro_http_proxy_ctx));
CURLcode res;
- log_message(STORE_LOGLVL_DEBUG, "init_storage_ro_http_proxy: initialising proxy storage backend for %s", connection_string);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_http_proxy: initialising proxy storage backend for %s", connection_string);
if (!store || !ctx) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_http_proxy: failed to allocate memory for context");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_http_proxy: failed to allocate memory for context");
if (store) {
free(store);
@@ -288,7 +289,7 @@ struct storage_backend * init_storage_ro_http_proxy(const char * connection_stri
pthread_mutex_lock(&qLock);
if (!done_global_init) {
- log_message(STORE_LOGLVL_DEBUG, "init_storage_ro_http_proxy: Global init of curl", connection_string);
+ g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_http_proxy: Global init of curl", connection_string);
res = curl_global_init(CURL_GLOBAL_DEFAULT);
done_global_init = 1;
} else {
@@ -298,7 +299,7 @@ struct storage_backend * init_storage_ro_http_proxy(const char * connection_stri
pthread_mutex_unlock(&qLock);
if (res != CURLE_OK) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_http_proxy: failed to initialise global curl: %s", curl_easy_strerror(res));
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_http_proxy: failed to initialise global curl: %s", curl_easy_strerror(res));
free(ctx);
free(store);
return NULL;
@@ -307,7 +308,7 @@ struct storage_backend * init_storage_ro_http_proxy(const char * connection_stri
ctx->ctx = curl_easy_init();
if (!ctx->ctx) {
- log_message(STORE_LOGLVL_ERR, "init_storage_ro_http_proxy: failed to initialise curl");
+ g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_http_proxy: failed to initialise curl");
free(ctx);
free(store);
return NULL;
diff --git a/src/sys_utils.c b/src/sys_utils.c
index 769daca6..47e1f5bb 100644
--- a/src/sys_utils.c
+++ b/src/sys_utils.c
@@ -23,12 +23,12 @@ double get_load_avg(void)
double avg = 1000.0;
if (!loadavg) {
- fprintf(stderr, "failed to read /proc/loadavg");
+ g_logger(G_LOG_LEVEL_ERROR, "failed to read /proc/loadavg");
return 1000.0;
}
if (fscanf(loadavg, "%lf", &avg) != 1) {
- fprintf(stderr, "failed to parse /proc/loadavg");
+ g_logger(G_LOG_LEVEL_ERROR, "failed to parse /proc/loadavg");
fclose(loadavg);
return 1000.0;
}