Code Monkey home page Code Monkey logo

logentries's Introduction

LogEntries

Build Status

A LogEntries specific logging class by Chris Schuld for logging information to LogEntries

About

LogEntries is an easy-to-use PHP PSR-3 compliant logging class used to log information to the LogEntries SaaS application.

Installation

Composer

From the Command Line:

composer require cbschuld/LogEntries:1.*

In your composer.json:

{
    "require": {
        "cbschuld/LogEntries": "1.*"
    }
}

Basic Usage

<?php

use cbschuld\LogEntries;

require "vendor/autoload.php";
$token = "2bfbea1e-10c3-4419-bdad-7e6435882e1f"; // your LogEntries token (sample from docs)

$log = LogEntries::getLogger($token,true,true); // create persistent SSL-based connection
$log->info("some information");
$log->notice(json_encode(["status"=>"ok","message"=>"send some json"]));

Advanced Usage

You can send all of the logging functions either a string (PSR-3), encoded JSON (PSR-3) or an array which will be encoded into JSON (not PSR-3 but available)

<?php

use cbschuld\LogEntries;

require "vendor/autoload.php";
$token = "2bfbea1e-10c3-4419-bdad-7e6435882e1f"; // your LogEntries token (sample from docs)
$jsonInfo = ["json"=>true,"example"=>"yes","works"=>true];

$log = LogEntries::getLogger($token,true,true); // create persistent SSL-based connection
$log->info(["status"=>"ok","example"=>"with json messages"]);
$log->notice($jsonInfo);

You can also create a non-static instantiation for dependency injection or multiple log token usage

<?php

use cbschuld\LogEntries;

require "vendor/autoload.php";
$token = "2bfbea1e-10c3-4419-bdad-7e6435882e1f"; // your LogEntries token (sample from docs)
$jsonInfo = ["json"=>true,"example"=>"yes","works"=>true];

$log = new LogEntries($token,true,true); // create persistent SSL-based connection
$log->info(["status"=>"ok","example"=>"with json messages"]);
$log->notice($jsonInfo);

$token2 = "2bfbea1e-10c3-4419-bdad-7e6435882e1f"; // your LogEntries token (sample from docs)
$log2 = new LogEntries($token2,true,true); // create persistent SSL-based connection
$log2->info(["status"=>"ok","example"=>"with json messages","from"=>"log2"]);
$log2->notice($jsonInfo);

Middleware (Writer)

Using a LogEntriesWriter you can append log writing middleware into the log. The middleware is called before the log is written to LogEntries. It allows for sensing for JSON or text. This allows you to append data from your architecture into your logs.

Here is a sample usage:

<?php

use cbschuld\LogEntries;
use cbschuld\LogEntriesWriter;

class WriterTest extends LogEntriesWriter {
    // always add the hostname
    public function log($message,$isJson=false) {
        if($isJson) {
            $json = json_decode($message,true);
            $json["hostname"] = gethostname();
            $message = json_encode($json);
        }
        else {
            $hostname = gethostname();
            $message .= " hostname={$hostname}";
        }
        return $message;
    }
}

$writer = new WriterTest();

$json = array(
    "datetime" => new \DateTime("now"),
    "status" => "ok",
);
$log = new LogEntries("MYTOKEN",true,true);
$log->addWriter($writer);
$log->info($json);

PSR-3 Compliant

LogEntries is PHP PSR-3 compliant. This means it implements the Psr\Log\LoggerInterface.

See Here for the interface definition.

License

The MIT License

Copyright (c) 2015 Chris Schuld [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

logentries's People

Contributors

cbschuld avatar

Watchers

Rudger avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.