Logging for cloud native apps

Where are my logfiles? Before I answer this question let me explain the context. I work in the cloud development world and we have a methodology, which is called the 12 factor-app. One of the 12 factors is Logs and here is how this factor is defined.

A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behavior.

If you are not familiar with the 12 factor app, here you get more info about it.

But what does this mean for me as a developer? The answer is simple, I write all my logs to stdout. For example, I write my next cool web service in swift. Then you need a minimum of this 2 lines, for writing to stdout.


// Disable Buffering to write directly to stdout
setbuf(stdout, nil)
print(“this line will be printed to stdout.”)

That’s all, ok I have to be honest, you see 3 lines of code, but the comment is just for explanation, sorry. By the way setbuf is provided by the Standard C Library. If you need different log level’s like debug, error etc. then you might be more interested in library, which support you with this and also helps with the format of the log line. If we extend our swift app then the “HeliumLogger” will be a good option. This Logger also write’s only to stdout and this is everything we need.

Let’s talk about the different environments. If you develop on your local machine, then you can see the logs of your app in the terminal. But this is not the place where your app lives. If your app run’s on one of the cloud foundry (CF) provider, then you fetch the logs of your app with the cloud foundry cli “cf logs my-swift-app“. This is possible, because the routing of the logs in cloud foundry is managed by the runtime for you and one option for the output, could be the cloud foundry cli.


bash$ cf logs printer — recent | grep APP/PROC/WEB/0

2017–10–17T22:05:02.03+0200 [APP/PROC/WEB/0] OUT

Gentleman start the engine ….

2017–10–17T22:06:56.46+0200 [APP/PROC/WEB/0] OUT this line will be printed to stdout.”


But what is, if you need logs from the past? Honestly I don’t know, how other CF provider do handle this, but my experience with IBM Cloud Foundry is, that for this use case the logs are routed to an ELK stack and can easily access from the WebUi, which is awesome.

IBM Cloud Foundry Logs Web Ui
IBM Cloud Kibana Ui

Finally let me say, when ever a developer from outside of the cloud development world asking me where are my logs? I tell them exactly what I have writen here.

thanks for reading cheers

Norman