James
James

Reputation: 6008

Logging API calls

I've written an API and currently am looking at what is the best way to provide logging for the system.

We want to be able to have an overview of the calls being made, if particular calls are being hit very often and such.

What is the best way to log and present all this information simply?

Simply wondering if there are any pre-built or commonly used solutions with APIs that encompass what I am looking for.

Upvotes: 7

Views: 14272

Answers (3)

oklas
oklas

Reputation: 8220

Consider approach log is a stream

Logs are a stream, and it behooves everyone to treat them as such. Your programs should log to stdout and/or stderr and omit any attempt to handle log paths, log rotation, or sending logs over the syslog protocol. Directing where the program’s log stream goes can be left up to the runtime container: a local terminal or IDE (in development environments), an Upstart / Systemd launch script (in traditional hosting environments), or a system like Logplex/Heroku (in a platform environment).

(I noticed it in this answer, which is originally from this article)

Good thing is marked in @Emil Vikström's answer, which is need to notice, is a format to simplify parsing and analyzing.

Upvotes: 0

rbl00
rbl00

Reputation: 91

There are several ways you could go about doing this. I would start with an abstracted logging solution first, something like Monolog [https://github.com/Seldaek/monolog]. This way you can test and play with what you want to log in a text file to start with then move to a more elegant solution.

Monolog has Handlers for a bunch of different ligging services/containers. For API usage logging I would take a look at the following:

GrayLog2, a really nice Open Source logging system.

Cube, also a great Open Source project for collecting timestamped events.

Loggly, A commercial Cloud-based logging platform. Monolog does not have a handler for Loggly right now but I wrote one that I'm currently using in production. My fork of the Monolog project has this handler in it, I plan on submitting a pull request soon : Download on Gitub here.

Sentry, a realtime event logging and aggregation platform that you can host yourself or use the paid hosted version. Like Loggly, no handler in Monolog for this but it is a really nice project with a nice API you can easily write some simple code to log to.

Upvotes: 5

Emil Vikström
Emil Vikström

Reputation: 91942

A simple solution would be to log all calls to a file, maybe in a format similar to Apache web server logs. Then you can parse the log with an existing log analytics tool,for example Webalizer.

Upvotes: 1

Related Questions