ytake / hack-logging

Send logs to files For HHVM/Hack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hack-logging

Build Status

Requirements

HHVM 4.95 and above.

Usage

$ composer require hack-logging/hack-logging

StdHandler

use namespace HackLogging;
use namespace HH\Lib\IO;

async function fvAsync(): Awaitable<void> {
  list($read, $write) = IO\pipe();

  $log = new HackLogging\Logger('hack-logging', vec[
    new HackLogging\Handler\StdHandler($write),
  ]);

  await $log->writeAsync(
    HackLogging\LogLevel::DEBUG,
    'hacklogging-test',
  );
}

FilesystemHandler

use namespace HackLogging;
use namespace HH\Lib\File;
use function bin2hey();
use function random_bytes;
use function sys_get_temp_dir;

async function fvAsync(): Awaitable<void> {
  $filename = sys_get_temp_dir() . '/' . bin2hex(random_bytes(16));
  $file = File\open_write_only($filename);
  $log = new HackLogging\Logger('hack-logging', vec[
    new HackLogging\Handler\FilesystemHandler($file),
  ]);
  await $log->writeAsync(
    HackLogging\LogLevel::DEBUG,
    'hacklogging-test',
    dict[
      'context' => vec['nice'],
    ],
  );
}

About

Send logs to files For HHVM/Hack

License:MIT License


Languages

Language:Hack 98.8%Language:Shell 1.2%