@@ -138,75 +138,27 @@ apm.capture_message('hello, world!')
138138[[flask-logging]]
139139==== Shipping Logs to Elasticsearch
140140
141- Enable automatic log shipping by passing `logging=LEVEL` to the ElasticAPM
142- constructor. The agent will then ship all log messages with the given
143- log-level or higher, from Python's built-in `logging` module to
144- Elasticsearch. `LEVEL` must be one of the levels defined in the
145- https://docs.python.org/3/library/logging.html#logging-levels[`logging`]
146- module.
141+ This feature has been deprecated and will be removed in a future version.
147142
148- [source,python]
149- ----
150- import logging
143+ Please see our <<logs,Logging>> documentation for other supported ways to ship
144+ logs to Elasticsearch.
151145
152- from elasticapm.contrib.flask import ElasticAPM
153-
154- apm = ElasticAPM(app, logging=logging.ERROR)
155- ----
156-
157- To ship all log messages independent of log levels to Elastic APM, pass
158- `logging=True` to the constructor:
146+ Note that you can always send exceptions and messages to the APM Server with
147+ <<client-api-capture-exception,`capture_exception`>> and and
148+ <<client-api-capture-message,`capture_message`>>.
159149
160150[source,python]
161151----
162- from elasticapm.contrib.flask import ElasticAPM
163-
164- apm = ElasticAPM(app, logging=True)
165- ----
166-
167- NOTE: using `logging=True` can lead to high number of logs being sent to Elastic APM.
168- We recommend to always limit logging with Elastic APM to a high level (`WARNING` or `ERROR`).
169- For shipping of less urgent logs, we recommend to use {filebeat-ref}[filebeat].
170-
171- For fine-grained control, you can initialize a logging handler and add it,
172- just as you would with any other handler.
152+ from elasticapm import get_client
173153
174- For information on how to increase the log verbosity from the APM agent, see
175- <<agent-logging,troubleshooting agent logging>>.
176-
177- [source,python]
178- ----
179- from flask import Flask
180-
181- from elasticapm.contrib.flask import ElasticAPM
182- from elasticapm.handlers.logging import LoggingHandler
183-
184- app = Flask(__name__)
185-
186- apm = ElasticAPM(app)
187-
188- if __name__ == '__main__':
189- # Create a logging handler and attach it.
190- handler = LoggingHandler(client=apm.client)
191- handler.setLevel(logging.WARN)
192- app.logger.addHandler(handler)
193- ----
194-
195- You can also capture exceptions and send them explicitly:
196-
197- [source,python]
198- ----
199154@app.route('/')
200155def bar():
201156 try:
202157 1 / 0
203158 except ZeroDivisionError:
204- app.logger.error( 'I cannot math', exc_info=True )
159+ get_client().capture_exception( )
205160----
206161
207- NOTE: `exc_info=True` adds the exception info to the data that gets sent to the APM Server.
208- Without it, only the message is sent.
209-
210162[float]
211163[[flask-extra-data]]
212164===== Extra data
0 commit comments