I want to log messages to a local Redis server with Monolog in a Symfony 2 project. I'm using the SncRedisBundle for this purpose.
This should be straight forward following the documentation, but it seems that no messages are stored in Redis. If I use the the default Redis client configured and write something to the Redis server this works perfectly.
My configuration is the following:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
monolog:
type: predis
alias: monolog
dsn: redis://localhost/1
logging: false
options:
connection_persistent: true
monolog:
client: monolog
key: monolog
monolog:
handlers:
custom:
type: service
id: snc_redis.monolog.handler
level: debug
Does anybody know how I can fix this issue?
You have to watch out for the fact that monolog handlers are redefined in config_prod.yml and config_dev.yml, so if you define them in config.yml they will just be overwritten by the prod or dev config. I'm not sure where you did it but if you have the redis and monolog configs together it is a probable cause that you just configured monolog in the wrong file.
Related
I have two databases for my application so I put the entities in two separate folders to simplify things.
Entity/
Local/
User.php
Foo.php
Remote/
Bar.php
but I have an error 500 that I don't understand at the time of connection
[2020-09-03 17:10:58] request.CRITICAL:
Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class 'App\Entity\Local\User' was not found in the chain configured namespaces " at /www/myapp/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php line 23 {"exception":"[object] (Doctrine\\Persistence\\Mapping\\MappingException(code: 0): The class 'App\\Entity\\Local\\User' was not found in the chain configured namespaces at /www/myapp/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23)"} []
Here is my doctrine.yml configuration
doctrine:
dbal:
default_connection: local
connections:
local:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
remote:
url: '%env(resolve:DATABASE_URL_MS)%'
charset: 'UTF-8'
wrapper_class: App\Connections\ConnectionRemote
mapping_types:
timestamp: string
xml: string
schema_filter: $sales$
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: local
entity_managers:
local:
connection: local
mappings:
local:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Local'
prefix: 'App\Entity\Local'
alias: local
AnotherBundle: ~
remote:
connection: remote
mappings:
remote:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Remote'
prefix: 'App\Entity\Remote'
alias: remote
Even stranger, if I refresh my page, I am well connected and the error doesn't come back...
Even crazier, it works very well in dev mode
I think there's a bug in Doctrine, it's the fact that it works in dev and not in prod that put me on the track of the solution.
I had dumped the dev and prod conf to compare the two versions and what I noticed was that doctrine.orm.default_entity_manager was set to default even though it is set to custom in package/doctrine.yaml.
so for the value to be really taken into account you must also set doctrine.orm.default_entity_manager in prod/doctrine.yaml
doctrine:
orm:
default_entity_manager: local
I try to configure the cable.yml like this
development:
adapter: postgresql
test:
adapter: postgresql
production:
adapter: postgresql
url: ?
channel_prefix: ?
it's better if you can use a cache service like redis https://redis.io/ for better performance as you'll be roughly hitting the db with the notification system for each user with an always-open socket.
But you can configure your yml file as follow:
development:
adapter: postgresql
test:
adapter: postgresql
staging:
adapter: postgresql
production:
adapter: postgresql
url: production_db_url
channel_prefix:
see the documentation at this specific part where it mentions redis in production at least for the same reason I mentioned before :
https://edgeguides.rubyonrails.org/action_cable_overview.html#subscription-adapter
My Symfony4 app is working fine in dev environment but not in production, i can't login (using FosUserBundle). After enabling debug and profiler toolbar in production (beacause it doesn't write any log) i've found the error
The class 'App\Entity\FintelUtility\User\User' was not found in the
chain configured namespaces FOS\UserBundle\Model
The class was not found in the chain configured namespaces
I've cleared the cache and i've checked mapping info of doctrine
php bin/console doctrine:mapping:info --env=prod
Found 2 mapped entities:
[OK] FOS\UserBundle\Model\Group
[OK] FOS\UserBundle\Model\User
wwwfintel#fnt-srvweb01:~/s4fgel$ php bin/console doctrine:mapping:info --env=dev
Found 5 mapped entities:
[OK] App\Entity\FintelUtility\QuoteOfTheDay
[OK] App\Entity\FintelUtility\User\Group
[OK] App\Entity\FintelUtility\User\User
[OK] FOS\UserBundle\Model\Group
[OK] FOS\UserBundle\Model\User
I don't know how to map those three entities that are missing.
config/packages/doctrine.yaml
# Doctrine Configuration
doctrine:
dbal:
default_connection: mssql_fgel_utility
connections:
mssql_fgel_utility:
driver: ~
driver_class: "%fgelutil_database_driver_class%"
host: "%fgelutil_database_host%"
dbname: "%fgelutil_database_name%"
user: "%fgelutil_database_user%"
password: "%fgelutil_database_password%"
types:
datetime_key: 'App\Type\DateTimeKeyType'
orm:
default_entity_manager: mssql_fgel_utility
entity_managers:
#################################
# Update schema only with this em
#################################
mssql_fgel_utility:
connection: mssql_fgel_utility
mappings:
FintelUtility:
type: "annotation"
# The directory for entity (relative to bundle path)
dir: '%kernel.project_dir%/src/Entity/FintelUtility'
prefix: 'App\Entity\FintelUtility'
is_bundle: false
Ther's no config/packages/dev/doctrine.yaml but prod
config/packages/prod/doctrine.yaml
doctrine:
orm:
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
I've tried also php bin/console cache:warmup --env=prod --no-debug but it didn't help
Any idea?
EDIT
I've changed "mssql_fgel_utility" entity manager to "default" and it worked for prod but then it doesn't work for dev
orm:
default_entity_manager: mssql_fgel_utility
entity_managers:
#################################
# Update schema only with this em
#################################
# THIS WAS WRONG EVEN IF I DON'T KNOW WHY
# mssql_fgel_utility:
#################################
default: #changed to this
I've changed "mssql_fgel_utility" entity manager to "default" and it worked
orm:
default_entity_manager: default
entity_managers:
#################################
# Update schema only with this em
#################################
# THIS WAS WRONG EVEN IF I DON'T KNOW WHY
# mssql_fgel_utility:
#################################
default: #changed to this
You wrote:
I've cleared the cache and i've checked mapping info of doctrine
Is it the Symfony cache or Doctrine cache? if it's not the Doctrine cache, clear it and try the command php bin/console do:sc:va to check the mapping and check if the database is in sync with the mapping and make the php bin/console do:sc:up --force --env=prod in the case it's not in sync.
You have to change "mssql_fgel_utility" entity manager to "default" and delete "default_entity_manager: mssql_fgel_utility" and it will work for dev and prod.
I can't get the file spooling to work properly with Symfony 2 and Swiftmailer.
This is my config
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: '%kernel.root_dir%/spool'
port: %mailer_port%
encryption: %mailer_encryption%
sender_address: %mailer_sender_address%
When I send an email, a file is created in app/spool/default/
I then run
php app/console swiftmailer:spool:send
and get this response
[2015-12-29 18:54:40] Processing default mailer... 1 emails sent
So it looks like it has worked, but nothing is sent and /var/log/mail.log does not show any new emails.
When I had the config set to memory spooling, the emails were working without any issue, all I changed was config.yml
swiftmailer:
spool: { type: memory }
changed to
swiftmailer:
spool:
type: file
path: '%kernel.root_dir%/spool'
I'm using sendgrid and postfix to actually send out the emails, but I'm not sure that the emails are even getting to postfix, so that probably doesn't make any difference.
The problem ended up being the default environment. All I needed to do was specify an environment other than dev
php app/console swiftmailer:spool:send --env=prod
According the https://github.com/doctrine/DoctrineCacheBundle#cache-providers there are several parameters necessary to use redis instead of file_system as cache backend.
In the main configuration file of Sylius, there is only one area to put cache settings:
app/config/parameters.yml
sylius.cache:
type: redis (was file_system)
Where to put the rest?
connection_id - Redis connection service id
host - redis host
port - redis port
Thanks!
You can use this syntax:
sylius.cache:
type: redis
namespace: sylius
redis:
host: localhost
port: 6379
database: 10
Sylius then creates a doctrine cache provider with this configuration.