KeyError: "Attempt to overwrite 'filename' in LogRecord"
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start by reading the issue’s traceback and the CallsiteParameterAdder configuration shown in the body, especially how its filename field reaches Python’s logging call. Reproduce the failure with the provided Gunicorn and structlog setup, then check the relevant structlog tests for callsite parameters. Done means the setup no longer raises the LogRecord overwrite error and the existing tests still pass.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This is what I am using. Gunicorn + uvicorn app.
elog = structlog.get_logger("gunicorn.error", )
alog = structlog.get_logger("gunicorn.error", )
class GunicornLogger:
def __init__(self, cfg):
self.cfg = cfg
self.error_log = elog.bind()
self.access_log = alog.bind()
logging.getLogger().setLevel(logging.DEBUG) # bit hacky but only required to emit logs
def debug(self, msg, *args, **kwargs) -> None:
self.error_log.debug(msg, *args, **kwargs)
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 8, in <module>
sys.exit(run())
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
super().run()
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 105, in setup
self.log.debug('Current configuration:\n{0}'.format(
File "/app/src/myapp/logs.py", line 80, in debug
self.error_log.debug(msg, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/structlog/stdlib.py", line 180, in debug
return self._proxy_to_logger("debug", event, *args, **kw)
File "/usr/local/lib/python3.10/site-packages/structlog/stdlib.py", line 247, in _proxy_to_logger
return super()._proxy_to_logger(method_name, event=event, **event_kw)
File "/usr/local/lib/python3.10/site-packages/structlog/_base.py", line 206, in _proxy_to_logger
return getattr(self._logger, method_name)(*args, **kw)
File "/usr/local/lib/python3.10/logging/__init__.py", line 1465, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/usr/local/lib/python3.10/logging/__init__.py", line 1622, in _log
record = self.makeRecord(self.name, level, fn, lno, msg, args,
File "/usr/local/lib/python3.10/logging/__init__.py", line 1596, in makeRecord
raise KeyError("Attempt to overwrite %r in LogRecord" % key)
KeyError: "Attempt to overwrite 'filename' in LogRecord"
processors = [
structlog.contextvars.merge_contextvars,
# If log level is too low, abort pipeline and throw away log entry.
structlog.stdlib.filter_by_level,
# Add the name of the logger to event dict.
structlog.stdlib.add_logger_name,
# Add log level to event dict.
structlog.stdlib.add_log_level,
# Perform %-style formatting.
structlog.stdlib.PositionalArgumentsFormatter(),
# Add a timestamp in ISO 8601 format.
structlog.processors.TimeStamper(fmt="iso"),
# If the "stack_info" key in the event dict is true, remove it and
# render the current stack trace in the "stack" key.
structlog.processors.StackInfoRenderer(),
# add exception frame as dict
# structlog.processors.dict_tracebacks,
# If the "exc_info" key in the event dict is either true or a
# sys.exc_info() tuple, remove "exc_info" and render the exception
# with traceback into the "exception" key.
structlog.processors.format_exc_info,
structlog.processors.ExceptionRenderer(),
# Add callsite parameters.
structlog.processors.CallsiteParameterAdder({
structlog.processors.CallsiteParameter.FILENAME,
structlog.processors.CallsiteParameter.FUNC_NAME,
structlog.processors.CallsiteParameter.LINENO,
}),
# structlog.processors.JSONRenderer(),
structlog.stdlib.render_to_log_kwargs,
]
structlog.configure(
processors=processors,
# `wrapper_class` is the bound logger that you get back from
# get_logger(). This one imitates the API of `logging.Logger`.
wrapper_class=structlog.stdlib.BoundLogger,
# `logger_factory` is used to create wrapped loggers that are used for
# OUTPUT. This one returns a `logging.Logger`. The final value (a JSON
# string) from the final processor (`JSONRenderer`) will be passed to
# the method of the same name as that you've called on the bound logger.
logger_factory=structlog.stdlib.LoggerFactory(),
# Effectively freeze configuration after creating the first bound
# logger.
cache_logger_on_first_use=True,
)
- Lenguaje dominante
- Python
- Estrellas
- 5k
- Forks
- 302
- Merge medio
- 17 min
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de hynek/structlog
-
bind_contextvars is not thread-safe?Posiblemente ocupada @nosmile99 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Transform examples in docs into included source filesPosiblemente ocupada @alexchen-sys la tomó hace 100 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
-
waiting for feedback
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
Todos los issues de hynek/structlog
Issues similares
-
Project submission:Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
slavakurilyak/awesome-ai-agents#845 ·
Los mantenedores suelen responder en 1 día
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodifficulty:2 enhancement good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
MakazhanAlpamys/Soup#2178 ·
Los mantenedores suelen responder en 1 día
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
scverse/rapids-singlecell#854 ·
Los mantenedores suelen responder en 1 día
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLPosiblemente ocupada @ninglinLiu la tomó hoy. Abiertoarea:frontend backend:slang bug direction:input
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=FalsePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 13 días