Skip to content

Latest commit

 

History

History
397 lines (271 loc) · 10.9 KB

File metadata and controls

397 lines (271 loc) · 10.9 KB
title

Proxy Logger Component

data-transition-duration

2000

Under licence of LGPL-3. You can get the source from: https://github.com/stevleibelt/slides/tree/master/2013/131203_symfinyug_proxy_logger Based on the example: https://hovercraft.readthedocs.org/en/1.0/_sources/examples/hovercraft.txt - http://regebro.github.io/hovercraft Based on the docs: https://hovercraft.readthedocs.org/en/1.0/ http://docutils.sourceforge.net/docs/user/rst/cheatsheet.txt http://docutils.sourceforge.net/docs/user/rst/quickref.html http://en.wikipedia.org/wiki/ReStructuredText https://raw.github.com/regebro/hovercraft/master/docs/examples/positions.rst


Proxy Logger Component


What Is This Talk About?

  • distinction between logging, metrics and writing of history
  • present a concept of logging
  • present a logging component

Why At A Symfony UserGroup?

"symfony/event-dispatcher": "v2.3.5"    //since version 1.2.0 :-)

data-y

r1000

Distinction Between Logging, Metrics Or Writing Of History

We are web developers and web analytics is a mixture of all.

Web analytics is the measurement, collection, analysis and reporting of internet data for purposes of understanding and optimizing web usage.


What Is It All About?

  • analyse internal data
  • archive internal data
  • collect internal data
  • meter internal data
  • record internal data

Logging?

In computing, a logfile or simply log is a file that records events taking place in the execution of a system in order to provide an audit trail that can be used to understand the activity of the system and to diagnose problems. The act of keeping a logfile is called logging. ([0])

Metrics?

A software metric is a measure of some property of a piece of software or its specifications [...]
The goal is obtaining objective, reproducible and quantifiable measurements, which may have numerous valuable applications in schedule and budget planning, cost estimation, quality assurance testing, software debugging, software performance optimization, and optimal personnel task assignments. ([1])

Writing Of History?

  • recoding of events like:
  • preserve state of a bunch of data
    • create graph of data transformation
    • record when happen what on which set of data

And Graylog2 Is?

As an example.
Graylog2 is for data analysis ([2])

So graylog is pure web analytics (doing all at once if you ask me).


Summary

  • don't do web analytics
  • do logging
  • do metrics
  • do writing of history

And Also ...

  • figure out what your customer want
  • your customer should know what to measure
    • avoid measure everything
    • do not interpret data by adding wished cross connections
  • try to define common terms for your team and your customer
  • separate you data (by metric, logging and history)
  • create logger, history and metric handler (even if they are all simple file writer)

data-x

r1500

A Concept Of Logging


What Do I Mean With Logging?

  • not webserver logs but web application logs
  • record of workflow / processed data
  • dump of processed data if something went wrong
  • logging per instance (webserver)
  • deletion of log files or entries should be fearless
  • changing of log behaviour without fear
  • split logs into logical units (import/export/registration)

What I Struggled With

  • never found the right balance between logging enough to debug and do not glut the logfiles
  • set loglevel to warning and you are loosing notice, info or debug
  • set loglevel to info and your log file will be flooded with messages

What I Need

  • if something goes wrong, "i want it all" ([3])

How To Solve This Problem?

Log all process data but only when something goes wrong.


Meaning?

  • buffer log entries
  • clean or flush the buffer under well defined circumstances
  • deal with (a collection of) psr3 loggers
  • one log target (file/database column/whatever) per logical log unit (like import/purchase/migration)

data-y

r1000

A Logging Component


History Of Development

  • so i searched and found nothing good for php
  • started developing and released version 0.9.0 with FlushBufferTrigger
  • it was working but, it looks like a first draft ;-)
  • version 1.0.0 adds a lot of examples and the BypassBuffer
  • big refactoring leads to version 1.1.0
  • implementation of event driven design leads to version 1.2.0
  • story continues :-)
  • later on i stumbled over monolog and its FingersCrossedHandler (so i'm not alone with that concept of logging :-))
  • monolog looks like big logging component with a log of features

What It Is (1/2)


What It Is (2/2)


What It Is Not

  • it does not care how to store
  • it does not care where to store
  • is not the logger component, just a part of it

Common Terms (1/2)

  • RealLogger represents a psr-3 logger
  • LogRequest represents a log request (log level, message and context)
  • LogRequestBuffer represents a collection of log requests that are not pushed to the real loggers

Common Terms (2/2)

  • ProxyLogger represents a collection of real loggers
  • BufferLogger represents as a log request keeper that pass each log request to a buffer
  • BypassBufferInterface represents a buffer manipulation to bypass a certain log level to all added real loggers
  • FlushBufferTriggerInterface represents a buffer manipulation to trigger a buffer flush based on a log level

Showtime

Time for some example implementation!


Installation

Use composer and packagist.

require: "net_bazzline/component_proxy_logger": "dev-master"

How To Use It?

instead of

class MyLoggerFactory
{
    public function createMyProcessLogger()
    {
        return new Logger();
    }
}

use

class MyLoggerFactory
{
    public function createMyProcessLogger()
    {
        $realLogger = new Logger();

        //of course this should not be done on each create call
        $proxyLoggerFactory = new ProxyLoggerFactory();
        $proxyLogger = $proxyLoggerFactory->create($realLogger);

        return $proxyLogger;
    }
}

What Else?

If you have to deal with log4php loggers, use an adapter.

And the adapter works vica versa (super cool, use a psr3 logger in a log4php environment).


data-x

r0

data-y

r500

data-scale

0.1

Recap

  • do not log all
  • structure your log
  • explain your customer that they want metric or history
  • add bugs or remarks to the component
  • joind the development team

Questions?

  • who is using monolog?
    • what are your experience?
    • positives
    • negatives?
  • what loggers are you using?
  • do you use your log files to create metrics?

Your Opinion?

  • how do you like the main idea of the component?

Thanks!