Skip to content
This repository was archived by the owner on Dec 16, 2018. It is now read-only.

Commit 934ca0f

Browse files
author
Steve Thomas
committed
Merge branch 'release/1.1.0'
2 parents 4453e09 + f530967 commit 934ca0f

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

application/config/monolog.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313

1414
/* GENERAL OPTIONS */
15-
$config['handler'] = 'file'; // valid handlers are file
15+
$config['handlers'] = array('file', 'new_relic'); // valid handlers are file | new_relic
1616
$config['channel'] = ENVIRONMENT; // channel name which appears on each line of log
17-
$config['threshold'] = '1'; // 'ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'
17+
$config['threshold'] = '4'; // 'ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'
1818
$config['introspection_processor'] = TRUE; // add some meta data such as controller and line number to log messages
1919

2020
/* FILE HANDLER OPTIONS
@@ -23,5 +23,8 @@
2323
*/
2424
$config['file_logfile'] = APPPATH . 'logs/ci.log';
2525

26+
/* NEW RELIC OPTIONS */
27+
$config['new_relic_app_name'] = 'App Name';
28+
2629
// exclusion list for pesky messages which you may wish to temporarily suppress with strpos() match
2730
$config['exclusion_list'] = array();

application/libraries/Log.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* CodeIgniter Monolog integration
77
*
8-
* Version 1.0.1
8+
* Version 1.1.0
99
* (c) Steve Thomas <[email protected]>
1010
*
1111
* For the full copyright and license information, please view the LICENSE
@@ -15,6 +15,7 @@
1515
use Monolog\Logger;
1616
use Monolog\ErrorHandler;
1717
use Monolog\Handler\RotatingFileHandler;
18+
use Monolog\Handler\NewRelicHandler;
1819
use Monolog\Processor\IntrospectionProcessor;
1920

2021
/**
@@ -67,16 +68,23 @@ public function __construct()
6768
$this->log->pushProcessor(new IntrospectionProcessor());
6869
}
6970

70-
// decide which handler to use
71-
switch ($this->config['handler']) {
72-
case 'file':
73-
$handler = new RotatingFileHandler($this->config['file_logfile']);
74-
break;
75-
default:
76-
exit('log handler not supported: ' . $this->config['handler']);
77-
}
71+
// decide which handler(s) to use
72+
foreach ($this->config['handlers'] as $value) {
73+
switch ($value) {
74+
case 'file':
75+
$handler = new RotatingFileHandler($this->config['file_logfile']);
76+
break;
77+
78+
case 'new_relic':
79+
$handler = new NewRelicHandler(Logger::ERROR, true, $this->config['new_relic_app_name']);
80+
break;
7881

79-
$this->log->pushHandler($handler);
82+
default:
83+
exit('log handler not supported: ' . $this->config['handler']);
84+
}
85+
86+
$this->log->pushHandler($handler);
87+
}
8088

8189
$this->write_log('DEBUG', 'Monolog replacement logger initialized');
8290
}
@@ -89,8 +97,10 @@ public function __construct()
8997
* @param $msg
9098
* @return bool
9199
*/
92-
public function write_log($level = 'error', $msg)
93-
{
100+
public function write_log(
101+
$level = 'error',
102+
$msg
103+
) {
94104
$level = strtoupper($level);
95105

96106
// verify error level
@@ -106,7 +116,7 @@ public function write_log($level = 'error', $msg)
106116

107117
if ($pos !== false) {
108118
// just exit now - we don't want to log this error
109-
return TRUE;
119+
return true;
110120
}
111121
}
112122
}
@@ -125,6 +135,6 @@ public function write_log($level = 'error', $msg)
125135
break;
126136
}
127137
}
128-
return TRUE;
138+
return true;
129139
}
130140
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"monolog/monolog": "1.6.*"
3+
"monolog/monolog": "1.7.*"
44
}
55
}

0 commit comments

Comments
 (0)