Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
irul
/
php-logger
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6c3bed97
authored
Aug 31, 2024
by
irul
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add maximum level of logging to write to logs
1 parent
d2114b77
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletions
Logger.php
Logger.php
View file @
6c3bed9
...
@@ -20,6 +20,14 @@ class Logger
...
@@ -20,6 +20,14 @@ class Logger
private
$log_handle
=
null
;
// Handle to the default log file.
private
$log_handle
=
null
;
// Handle to the default log file.
private
$_user_log_handle
=
null
;
// Handle to the developer specified log file.
private
$_user_log_handle
=
null
;
// Handle to the developer specified log file.
private
static
$log_level
=
null
;
// The maximum level of logging to write to logs
private
static
$log_level_integers
=
[
'debug'
=>
8
,
'info'
=>
7
,
'warn'
=>
5
,
'error'
=>
4
];
// Map logging levels to syslog specifications, there's room for the other levels
/**
/**
* This method checks if there is an instance available. If yes it returns its handle otherwise
* This method checks if there is an instance available. If yes it returns its handle otherwise
* create a new instance and return it's handle.
* create a new instance and return it's handle.
...
@@ -32,8 +40,9 @@ class Logger
...
@@ -32,8 +40,9 @@ class Logger
*
*
* @static
* @static
* */
* */
public
static
function
get_logger
(
$log_path
=
null
,
$log_file
=
null
)
public
static
function
get_logger
(
$log_path
=
null
,
$log_file
=
null
,
$log_level
=
'debug'
)
{
{
self
::
$log_level
=
(
$log_level
==
'warning'
)
?
'warn'
:
$log_level
;
if
(
is_null
(
$log_path
))
{
if
(
is_null
(
$log_path
))
{
if
(
!
(
isset
(
self
::
$logger
))
||
(
is_null
(
self
::
$logger
)))
{
if
(
!
(
isset
(
self
::
$logger
))
||
(
is_null
(
self
::
$logger
)))
{
self
::
$logger
=
new
self
();
self
::
$logger
=
new
self
();
...
@@ -160,6 +169,9 @@ class Logger
...
@@ -160,6 +169,9 @@ class Logger
* */
* */
public
function
do_write
(
$log_string
,
$log_source
,
$log_level
=
'debug'
)
public
function
do_write
(
$log_string
,
$log_source
,
$log_level
=
'debug'
)
{
{
if
(
self
::
$log_level_integers
[
$log_level
]
>
self
::
$log_level_integers
[
self
::
$log_level
]){
return
;
}
$log_string
=
sprintf
(
"%s [%s] %s -- %s"
,
date
(
DATESTRING_FULL
),
str_pad
(
strtoupper
(
$log_level
),
5
),
$log_string
,
$log_source
);
$log_string
=
sprintf
(
"%s [%s] %s -- %s"
,
date
(
DATESTRING_FULL
),
str_pad
(
strtoupper
(
$log_level
),
5
),
$log_string
,
$log_source
);
$log_string
=
$log_string
.
PHP_EOL
;
$log_string
=
$log_string
.
PHP_EOL
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment