7

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.

James
  • 5,942
  • 15
  • 48
  • 72
  • 1
    Are you sure you want to [log](http://stackoverflow.com/questions/3953217/does-php-have-built-in-debugging-logging-like-ruby-on-rails-logger-info-to-a-de/3953234#3953234 "Ways to log with PHP") that information? To me it sounds like you want to [profile](http://stackoverflow.com/questions/133686/what-is-the-best-way-to-profile-php-code "Q: Best way to profile PHP") and [stresstest](http://stackoverflow.com/questions/2558970/how-to-test-a-site-rigorously/2558996#2558996 "Q: How to test a site rigourously") it. – Gordon Oct 22 '10 at 07:40
  • We want to log, so we are able to see if certain users are calling a call too much (yes, we have rate limiting, but still good to know if people are trying to abuse). As well as seeing where the big usage really comes from, how many errors are occurring, that kinda fun stuff. – James Oct 22 '10 at 08:09
  • James, did you come up with a good solution? I'm interested in the same question. – kalenjordan Jul 30 '12 at 18:49

3 Answers3

5

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.

rbl00
  • 91
  • 1
  • 4
1

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.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
0

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.

oklas
  • 7,935
  • 2
  • 26
  • 42