khaledalam/firebase-logger

There is no license information available for the latest version (v1.0.1) of this package.

A simple firebase PHP logger package to monitor and save the users activities.

v1.0.1 2020-02-06 12:51 UTC

This package is auto-updated.

Last update: 2020-02-16 15:45:55 UTC


README

Firebase Logger is a simple firebase PHP logger package to monitor and save the users activities.

Installation

Use composer to install firebase-logger.

composer require khaledalam/firebase-logger

Preview

preview.gif

Usage

example.php

<?php
// PHP 7.1^
//error_reporting(0);

include_once './FirebaseLogger.php';

$serviceFile = __DIR__ . '/serviceAccountKey.json';
$databaseUri = 'https://{EDIT_THIS}.firebaseio.com';

$firebaseLogger = new FirebaseLogger([
    'service_account_key_json' => $serviceFile,
    'database_uri' => $databaseUri,
    'database_realtime_name' => 'Logger',
]);

if ($_POST['search'])
{
    echo "<h2>Log saved!</h2>";
    $data = [
        'action' => 'search action',
        'value' => $_POST['search'],
    ];
    $firebaseLogger->log($data);
}
?>

<center>
    <form action="./example.php" method="post">
        <input type="text" placeholder="search text" name="search">
        <input type="submit" value="search">
    </form>
</center>

Config

serviceAccountKey.json:

  • To get file: Go to firebase console -> settings -> Service Account -> Generate New private key That will download the required JSON file.
  • save serviceAccountKey.json file in safe and secret directory.

basic data:

  • structure: { device, date time(m-d-Y g:i:sA), ip }
  • to change basic data: $firebaseLogger->setBasic(['text_key' => 'text_val' ]);
  • to append basic data to orginal data: $firebaseLogger->addBasic(['new_key' => 'new_val' ]);
  • to avoid adding basic data to log: $firebaseLogger->log($data, false);

other

  • database_realtime_name => by default logs

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to test changes as appropriate.

Blog

https://khaledalam.net/firebase-logger

Packagist

https://packagist.org/packages/khaledalam/firebase-logger

License

MIT