Skip to content

Instantly share code, notes, and snippets.

@prezire
Last active November 4, 2022 14:30
Show Gist options
  • Save prezire/255f93d0ca4bb016f13ad6b18e33aa50 to your computer and use it in GitHub Desktop.
Save prezire/255f93d0ca4bb016f13ad6b18e33aa50 to your computer and use it in GitHub Desktop.
Proper use of logger.
<?php namespace App\Services\Enums;
final class LogType
{
const
//Total failures. Major systems are unavailable.
EMERGENCY_UNUSABLE_SYSTEMS = 'emergency',
//Usable hardwares with unusal outputs such as website down, unavailable DBs.
ALERT_CORRUPTED_SYSTEMS = 'alert',
//Apps, servers, sites, device errors, unavailable component,
//unexpected exception. Must be solved immediately.
CRITICAL_ERRORS = 'critical',
//Runtime errors. Must be resolved at a future time.
ERROR_NON_URGENT_ERRORS = 'error',
//Prelude to errors such as file system 85% full, deprecated APIs, CORS.
//Must be resolved at a future time.
WARNING_PRE_NON_URGENT_ERRORS = 'warning',
//Unusual but not exactly errors such as all update, delete of records or files.
NOTICE_UNUSUAL_NON_ERRORS = 'notice',
//Informational reporting. All log-ins/outs, create, read, index listing,
//analytics generation, file creations such as images and PDFs must have this.
INFO_REPORTING = 'info',
//Custom tracing.
DEBUG_DEV = 'debug';
}
//
/**
* @param string $type
* @param string $message Default is empty string to simulate a single, empty line.
* @param array $channels See config.logging.channels such as stack, single.
*/
function log
(
string $type = LogType::DEBUG_DEV,
string $message = '',
array $channels
)
{
empty($channels) ?
logger()->{$type}($message) :
\Log::stack($channels)->{$type}($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment