Skip to content

Commit

Permalink
Drop support for Monolog 1
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 3, 2024
1 parent ed0e4a2 commit cac4ab0
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 357 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
monolog: [ '1.*', '2.*' ]
monolog: [ '2.*' ]
include:
- php: '7.4'
deps: lowest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

* Drop support for Monolog 1

## 3.10.0 (2023-11-06)

* Add configuration support for SamplingHandler
Expand Down
74 changes: 12 additions & 62 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,38 +223,22 @@
* - [timeout]: float
* - [connection_timeout]: float
*
* - raven / sentry:
* - sentry:
* - dsn: connection string
* - client_id: Raven client custom service id (optional)
* - hub_id: Sentry hub custom service id (optional)
* - [release]: release number of the application that will be attached to logs, defaults to null
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
* - [auto_log_stacks]: bool, defaults to false
* - [environment]: string, default to null (no env specified)
*
* - sentry:
* - hub_id: Sentry hub custom service id (optional)
* - [fill_extra_context]: bool, defaults to false
*
* - newrelic:
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
* - [app_name]: new relic app name, default null
*
* - hipchat:
* - token: hipchat api token
* - room: room id or name
* - [notify]: defaults to false
* - [nickname]: defaults to Monolog
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
* - [use_ssl]: bool, defaults to true
* - [message_format]: text or html, defaults to text
* - [host]: defaults to "api.hipchat.com"
* - [api_version]: defaults to "v1"
* - [timeout]: float
* - [connection_timeout]: float
*
* - slack:
* - token: slack api token
* - channel: channel name (with starting #)
Expand All @@ -279,13 +263,6 @@
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
*
* - slackbot:
* - team: slack team slug
* - token: slackbot token
* - channel: channel name (with starting #)
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
*
* - cube:
* - url: http/udp url to the cube server
* - [level]: level name or int value, defaults to DEBUG
Expand Down Expand Up @@ -538,23 +515,17 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('url')->end() // cube
->scalarNode('exchange')->end() // amqp
->scalarNode('exchange_name')->defaultValue('log')->end() // amqp
->scalarNode('room')->end() // hipchat
->scalarNode('message_format')->defaultValue('text')->end() // hipchat
->scalarNode('api_version')->defaultNull()->end() // hipchat
->scalarNode('channel')->defaultNull()->end() // slack & slackwebhook & slackbot & telegram
->scalarNode('channel')->defaultNull()->end() // slack & slackwebhook & telegram
->scalarNode('bot_name')->defaultValue('Monolog')->end() // slack & slackwebhook
->scalarNode('use_attachment')->defaultTrue()->end() // slack & slackwebhook
->scalarNode('use_short_attachment')->defaultFalse()->end() // slack & slackwebhook
->scalarNode('include_extra')->defaultFalse()->end() // slack & slackwebhook
->scalarNode('icon_emoji')->defaultNull()->end() // slack & slackwebhook
->scalarNode('webhook_url')->end() // slackwebhook
->scalarNode('team')->end() // slackbot
->scalarNode('notify')->defaultFalse()->end() // hipchat
->scalarNode('nickname')->defaultValue('Monolog')->end() // hipchat
->scalarNode('token')->end() // pushover & hipchat & loggly & logentries & flowdock & rollbar & slack & slackbot & insightops & telegram
->scalarNode('token')->end() // pushover & loggly & logentries & flowdock & rollbar & slack & insightops & telegram
->scalarNode('region')->end() // insightops
->scalarNode('source')->end() // flowdock
->booleanNode('use_ssl')->defaultTrue()->end() // logentries & hipchat & insightops
->booleanNode('use_ssl')->defaultTrue()->end() // logentries & insightops
->variableNode('user') // pushover
->validate()
->ifTrue(function ($v) {
Expand All @@ -564,7 +535,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->scalarNode('title')->defaultNull()->end() // pushover
->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat
->scalarNode('host')->defaultNull()->end() // syslogudp
->scalarNode('port')->defaultValue(514)->end() // syslogudp
->arrayNode('config')
->canBeUnset()
Expand All @@ -576,18 +547,17 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')->end()
->end()
->scalarNode('connection_string')->end() // socket_handler
->scalarNode('timeout')->end() // socket_handler, logentries, pushover, hipchat & slack
->scalarNode('timeout')->end() // socket_handler, logentries, pushover & slack
->scalarNode('time')->defaultValue(60)->end() // deduplication
->scalarNode('deduplication_level')->defaultValue(Logger::ERROR)->end() // deduplication
->scalarNode('store')->defaultNull()->end() // deduplication
->scalarNode('connection_timeout')->end() // socket_handler, logentries, pushover, hipchat & slack
->scalarNode('connection_timeout')->end() // socket_handler, logentries, pushover & slack
->booleanNode('persistent')->end() // socket_handler
->scalarNode('dsn')->end() // raven_handler, sentry_handler
->scalarNode('dsn')->end() // sentry_handler
->scalarNode('hub_id')->defaultNull()->end() // sentry_handler
->scalarNode('client_id')->defaultNull()->end() // raven_handler, sentry_handler
->scalarNode('auto_log_stacks')->defaultFalse()->end() // raven_handler
->scalarNode('release')->defaultNull()->end() // raven_handler, sentry_handler
->scalarNode('environment')->defaultNull()->end() // raven_handler, sentry_handler
->scalarNode('client_id')->defaultNull()->end() // sentry_handler
->scalarNode('release')->defaultNull()->end() // sentry_handler
->scalarNode('environment')->defaultNull()->end() // sentry_handler
->scalarNode('message_type')->defaultValue(0)->end() // error_log
->scalarNode('parse_mode')->defaultNull()->end() // telegram
->booleanNode('disable_webpage_preview')->defaultNull()->end() // telegram
Expand Down Expand Up @@ -713,10 +683,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->ifTrue(function ($v) { return 'pushover' === $v['type'] && (empty($v['token']) || empty($v['user'])); })
->thenInvalid('The token and user have to be specified to use a PushoverHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'raven' === $v['type'] && !\array_key_exists('dsn', $v) && null === $v['client_id']; })
->thenInvalid('The DSN has to be specified to use a RavenHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'sentry' === $v['type'] && !\array_key_exists('dsn', $v) && null === $v['hub_id'] && null === $v['client_id']; })
->thenInvalid('The DSN has to be specified to use Sentry\'s handler')
Expand All @@ -725,18 +691,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->ifTrue(function ($v) { return 'sentry' === $v['type'] && null !== $v['hub_id'] && null !== $v['client_id']; })
->thenInvalid('You can not use both a hub_id and a client_id in a Sentry handler')
->end()
->validate()
->ifTrue(function ($v) { return 'hipchat' === $v['type'] && (empty($v['token']) || empty($v['room'])); })
->thenInvalid('The token and room have to be specified to use a HipChatHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'hipchat' === $v['type'] && !\in_array($v['message_format'], ['text', 'html']); })
->thenInvalid('The message_format has to be "text" or "html" in a HipChatHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'hipchat' === $v['type'] && null !== $v['api_version'] && !\in_array($v['api_version'], ['v1', 'v2'], true); })
->thenInvalid('The api_version has to be "v1" or "v2" in a HipChatHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'slack' === $v['type'] && (empty($v['token']) || empty($v['channel'])); })
->thenInvalid('The token and channel have to be specified to use a SlackHandler')
Expand All @@ -745,10 +699,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->ifTrue(function ($v) { return 'slackwebhook' === $v['type'] && (empty($v['webhook_url'])); })
->thenInvalid('The webhook_url have to be specified to use a SlackWebhookHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'slackbot' === $v['type'] && (empty($v['team']) || empty($v['token']) || empty($v['channel'])); })
->thenInvalid('The team, token and channel have to be specified to use a SlackbotHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'cube' === $v['type'] && empty($v['url']); })
->thenInvalid('The url has to be specified to use a CubeHandler')
Expand Down
92 changes: 0 additions & 92 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler

$publisher = new Definition('Gelf\Publisher', []);
$publisher->addMethodCall('addTransport', [$transport]);
$publisher->setPublic(false);
} elseif (class_exists('Gelf\MessagePublisher')) {
$publisher = new Definition('Gelf\MessagePublisher', [
$handler['publisher']['hostname'],
$handler['publisher']['port'],
$handler['publisher']['chunk_size'],
]);

$publisher->setPublic(false);
} else {
throw new \RuntimeException('The gelf handler requires the graylog2/gelf-php package to be installed');
Expand Down Expand Up @@ -632,27 +624,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
}
break;

case 'hipchat':
$definition->setArguments([
$handler['token'],
$handler['room'],
$handler['nickname'],
$handler['notify'],
$handler['level'],
$handler['bubble'],
$handler['use_ssl'],
$handler['message_format'],
!empty($handler['host']) ? $handler['host'] : 'api.hipchat.com',
!empty($handler['api_version']) ? $handler['api_version'] : 'v1',
]);
if (isset($handler['timeout'])) {
$definition->addMethodCall('setTimeout', [$handler['timeout']]);
}
if (isset($handler['connection_timeout'])) {
$definition->addMethodCall('setConnectionTimeout', [$handler['connection_timeout']]);
}
break;

case 'slack':
$definition->setArguments([
$handler['token'],
Expand Down Expand Up @@ -687,16 +658,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
]);
break;

case 'slackbot':
$definition->setArguments([
$handler['team'],
$handler['token'],
urlencode($handler['channel']),
$handler['level'],
$handler['bubble'],
]);
break;

case 'cube':
$definition->setArguments([
$handler['url'],
Expand Down Expand Up @@ -773,31 +734,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
]);
break;

case 'raven':
if (null !== $handler['client_id']) {
$clientId = $handler['client_id'];
} else {
$client = new Definition('Raven_Client', [
$handler['dsn'],
[
'auto_log_stacks' => $handler['auto_log_stacks'],
'environment' => $handler['environment'],
],
]);
$client->setPublic(false);
$clientId = 'monolog.raven.client.'.sha1($handler['dsn']);
$container->setDefinition($clientId, $client);
}
$definition->setArguments([
new Reference($clientId),
$handler['level'],
$handler['bubble'],
]);
if (!empty($handler['release'])) {
$definition->addMethodCall('setRelease', [$handler['release']]);
}
break;

case 'loggly':
$definition->setArguments([
$handler['token'],
Expand Down Expand Up @@ -975,13 +911,10 @@ private function getHandlerClassByType($handlerType)
'symfony_mailer' => 'Symfony\Bridge\Monolog\Handler\MailerHandler',
'socket' => 'Monolog\Handler\SocketHandler',
'pushover' => 'Monolog\Handler\PushoverHandler',
'raven' => 'Monolog\Handler\RavenHandler',
'sentry' => 'Sentry\Monolog\Handler',
'newrelic' => 'Monolog\Handler\NewRelicHandler',
'hipchat' => 'Monolog\Handler\HipChatHandler',
'slack' => 'Monolog\Handler\SlackHandler',
'slackwebhook' => 'Monolog\Handler\SlackWebhookHandler',
'slackbot' => 'Monolog\Handler\SlackbotHandler',
'cube' => 'Monolog\Handler\CubeHandler',
'amqp' => 'Monolog\Handler\AmqpHandler',
'error_log' => 'Monolog\Handler\ErrorLogHandler',
Expand All @@ -991,55 +924,30 @@ private function getHandlerClassByType($handlerType)
'fingers_crossed' => 'Monolog\Handler\FingersCrossedHandler',
'filter' => 'Monolog\Handler\FilterHandler',
'mongo' => 'Monolog\Handler\MongoDBHandler',
'elasticsearch' => 'Monolog\Handler\ElasticSearchHandler',
'telegram' => 'Monolog\Handler\TelegramBotHandler',
'server_log' => 'Symfony\Bridge\Monolog\Handler\ServerLogHandler',
'redis' => 'Monolog\Handler\RedisHandler',
'predis' => 'Monolog\Handler\RedisHandler',
'insightops' => 'Monolog\Handler\InsightOpsHandler',
'sampling' => 'Monolog\Handler\SamplingHandler',
];

$v2HandlerTypesAdded = [
'elastica' => 'Monolog\Handler\ElasticaHandler',
'elasticsearch' => 'Monolog\Handler\ElasticaHandler',
'elastic_search' => 'Monolog\Handler\ElasticsearchHandler',
'fallbackgroup' => 'Monolog\Handler\FallbackGroupHandler',
'noop' => 'Monolog\Handler\NoopHandler',
];

$v2HandlerTypesRemoved = [
'hipchat',
'raven',
'slackbot',
];

$v3HandlerTypesRemoved = [
'swift_mailer',
];

if (Logger::API >= 2) {
$typeToClassMapping = array_merge($typeToClassMapping, $v2HandlerTypesAdded);
foreach ($v2HandlerTypesRemoved as $v2HandlerTypeRemoved) {
unset($typeToClassMapping[$v2HandlerTypeRemoved]);
}
}

if (Logger::API >= 3) {
foreach ($v3HandlerTypesRemoved as $v3HandlerTypeRemoved) {
unset($typeToClassMapping[$v3HandlerTypeRemoved]);
}
}

if (!isset($typeToClassMapping[$handlerType])) {
if (Logger::API === 1 && \array_key_exists($handlerType, $v2HandlerTypesAdded)) {
throw new \InvalidArgumentException(\sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType));
}

if (Logger::API >= 2 && \array_key_exists($handlerType, $v2HandlerTypesRemoved)) {
throw new \InvalidArgumentException(\sprintf('"%s" was removed in Monolog v2.', $handlerType));
}

if (Logger::API >= 3 && \array_key_exists($handlerType, $v3HandlerTypesRemoved)) {
throw new \InvalidArgumentException(\sprintf('"%s" was removed in Monolog v3.', $handlerType));
}
Expand Down
5 changes: 0 additions & 5 deletions Resources/config/schema/monolog-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
<xsd:attribute name="from-email" type="xsd:string" />
<xsd:attribute name="to-email" type="xsd:string" />
<xsd:attribute name="subject" type="xsd:string" />
<xsd:attribute name="notify" type="xsd:boolean" />
<xsd:attribute name="room" type="xsd:string" />
<xsd:attribute name="nickname" type="xsd:string" />
<xsd:attribute name="release" type="xsd:string" />
<xsd:attribute name="timeout" type="xsd:string" />
<xsd:attribute name="time" type="xsd:integer" />
Expand All @@ -86,11 +83,9 @@
<xsd:attribute name="document_type" type="xsd:string" />
<xsd:attribute name="document-type" type="xsd:string" />
<xsd:attribute name="ignore-error" type="xsd:string" />
<xsd:attribute name="api_version" type="xsd:string" />
<xsd:attribute name="include-stacktraces" type="xsd:string" />
<xsd:attribute name="content-type" type="xsd:string" />
<xsd:attribute name="webhook-url" type="xsd:string" />
<xsd:attribute name="slack-team" type="xsd:string" />
<xsd:attribute name="region" type="xsd:string" />
</xsd:complexType>

Expand Down
14 changes: 3 additions & 11 deletions Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;

use Monolog\Handler\NullHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass;
Expand Down Expand Up @@ -53,16 +52,9 @@ public function testFailureOnHandlerWithoutPushProcessor()
$container->getCompilerPassConfig()->setRemovingPasses([]);
$container->addCompilerPass(new AddProcessorsPass());

if (Logger::API < 2) {
$container->compile();
$service = $container->getDefinition('monolog.handler.test3');
$calls = $service->getMethodCalls();
$this->assertCount(1, $calls);
} else {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "test3" handler does not accept processors');
$container->compile();
}
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "test3" handler does not accept processors');
$container->compile();
}

protected function getContainer()
Expand Down
Loading

0 comments on commit cac4ab0

Please sign in to comment.