Deploy R Code - 5Analytics Enterprise AI Platform

Centralized logging with syslog and R

Whenever you have applications solving serious business problems, the challenge of logging - and in a larger environment centralized logging - comes up. In this tutorial we are looking at how the 5Analytics Enterprise AI Platform helps you create microservices in R that are logging to syslog.

Before we dive deeper into how to implement centralized logging, lets see what Wikipedia says about syslog:

In computing, syslog is a standard for message logging. It allows separation of the software that generates messages, the system that stores them, and the software that reports and analyzes them. Each message is labeled with a facility code, indicating the software type generating the message, and assigned a severity level.
Computer system designers may use syslog for system management and security auditing as well as general informational, analysis, and debugging messages. A wide variety of devices, such as printers, routers, and message receivers across many platforms use the syslog standard. This permits the consolidation of logging data from different types of systems in a central repository. Implementations of syslog exist for many operating systems.

So, how do we create a microservice in R that logs to syslog? If you want to know how to create microservices with R and 5Analytics, have a look at this tutorial. Let's define a syslog logger.

Syslog logging

Logging can be defined in the configuration file: etc/ada.xml. To enable syslog logging, you have to set the attribute type to syslog and file to the host/port of the syslog daemon. If you omit the port, the port is set to 514 by default.

       <logging level="INFO" type="syslog" file="tcp://host:1234">
                <name level="INFO">de.visionstec.mbase.cluster.threads</name>
        </logging>

Once this is set, every log-message is logged to syslog and the defined server. To create log messages in R you can use the FiveA package that comes with the 5Analytics Enterprise AI Platform.

Here is a small hello-world example:

# hello-world.R
library(FiveA)

fafun_hello-world <- function(x=1) {
	fa.log.info("Hello World")
}

Once we have uploaded the hello-world.R file into the platform, we can simply query the microservice ...

> curl 'http://localhost:5050/if/json/R/v1/fafun_hello-world?_token=test_token'
{
  "data": "Hello World"
}

.. and when we have a look at the syslog logfile /var/log/messages we can see our log-entry.

2018-08-13T10:26:07.211296+02:00 sebastian sudo: pam_unix(sudo:session): session opened for user root by sebastian(uid=0)
2018-08-13T10:26:07.212167+02:00 sebastian sudo: pam_systemd(sudo:session): Cannot create session: Already running in a session
2018-08-13T08:56:28+02:00 sebastian.5analytics.com logInfo(82) Thread-4 Hello World
... next call
2018-08-13T08:56:29+02:00 sebastian.5analytics.com logInfo(82) Thread-4 Hello World

That's it. Now you can have your R microservices logging directly to your centralized syslog.

get_appWould you like to try the demo with your own data or with your own code?
Register for our Community Edition!
get_appGet our Community Edition
or visit our Homepage!