Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
vtigercrm
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Welcome to Vtiger Community. To gain access for account, please contact [ community @ vtiger.com ]
Show more breadcrumbs
Madhuk
vtigercrm
Commits
ff129750
Commit
ff129750
authored
1 year ago
by
Apparao G
Browse files
Options
Downloads
Patches
Plain Diff
Feature::Vtiger Logger enabled using MonoLog library
parent
06a914dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Vtiger/helpers/Logger.php
+34
-3
34 additions, 3 deletions
modules/Vtiger/helpers/Logger.php
with
34 additions
and
3 deletions
modules/Vtiger/helpers/Logger.php
+
34
−
3
View file @
ff129750
...
...
@@ -9,33 +9,51 @@
* All Rights Reserved.
* ********************************************************************************** */
// Include the Monolog library for logging functionality
require
'vendor/autoload.php'
;
// Import necessary classes from Monolog
use
Monolog\Logger
as
MonologLogger
;
use
Monolog\Handler\StreamHandler
;
// Define a custom Logger class
class
Logger
{
private
static
$logLevel
;
private
static
$filePath
;
private
static
$initialized
=
false
;
/**
* Constructor to initialize the logger
* @global type $PERFORMANCE_CONFIG
*/
public
function
__construct
()
{
// Check if the logger is not already initialized
if
(
!
self
::
$initialized
)
{
global
$PERFORMANCE_CONFIG
;
// Check if the performance config is set and debug logging is enabled
if
(
isset
(
$PERFORMANCE_CONFIG
)
&&
isset
(
$PERFORMANCE_CONFIG
[
'LOGLEVEl_DEBUG'
])
&&
$PERFORMANCE_CONFIG
[
'LOGLEVEl_DEBUG'
])
{
self
::
$logLevel
=
100
;
// Default log file path.;
// Set the default log level to 100 and the log file path
self
::
$logLevel
=
100
;
self
::
$filePath
=
"logs/vtigercrm.log"
;
self
::
$initialized
=
true
;
}
}
}
/**
* Static method to get a logger instance
*/
public
static
function
getLogger
(
string
$channel
,
$customFormatter
=
true
)
{
// Create a new logger instance
$log
=
new
self
();
// Check if log level is set (logger is initialized)
if
(
self
::
$logLevel
)
{
$log
=
new
MonologLogger
(
$channel
);
$handler
=
new
StreamHandler
(
self
::
$filePath
,
self
::
$logLevel
);
// Set a custom formatter if customFormatter is true
if
(
$customFormatter
)
{
$handler
->
setFormatter
(
new
VtigerCustomFormatter
());
}
...
...
@@ -44,25 +62,38 @@ class Logger {
return
$log
;
}
// Placeholder method for logging information
public
function
info
(
$message
)
{
// Logging info not implemented
}
// Placeholder method for logging debug messages
public
function
debug
(
$message
)
{
// Logging debug not implemented
}
}
// Define a custom log formatter
use
Monolog\Formatter\FormatterInterface
;
class
VtigerCustomFormatter
implements
FormatterInterface
{
/**
* Format a log record
* @param Monolog\LogRecord $record
* @return string
*/
public
function
format
(
Monolog
\LogRecord
$record
)
{
$record
=
$record
->
toArray
();
$formatted
=
'['
.
date
(
'Y-m-d H:i:s'
)
.
'] - '
.
$record
[
'level_name'
]
.
' - '
.
$record
[
'channel'
]
.
' - '
.
$record
[
'message'
]
.
PHP_EOL
;
return
$formatted
;
}
/**
* Format a batch of log records
* @param array $records
* @return type string
*/
public
function
formatBatch
(
array
$records
)
{
$formatted
=
''
;
foreach
(
$records
as
$record
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment