Skip to content
Firebase Logger is a simple firebase PHP logger package to monitor and save the users activities.
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
vendor
.gitignore
FirebaseLogger.php
LICENSE
README.md
composer.json
composer.lock
example.php
preview.gif
serviceAccountKey.json

README.md

Firebase Logger

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

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

You can’t perform that action at this time.