diff --git a/Makefile b/Makefile index 3e4f1b4..7ab6661 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include .config.mk # Define commands via docker DOCKER = docker -DOCKER_RUN := $(DOCKER) run --rm -i +DOCKER_RUN := $(DOCKER) run --rm -it WORKDIR :=/workdir DOCKER_COMMAND := $(DOCKER_RUN) -v $(PWD):$(WORKDIR):Z -w $(WORKDIR) \ -e XDG_CONFIG_HOME=$(WORKDIR) \ @@ -38,6 +38,9 @@ debug-%: ## Debug a variable by calling `make debug-VARIABLE` help: ## Show this help, includes list of all actions. @awk 'BEGIN {FS = ":.*?## "}; /^.+: .*?## / && !/awk/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ${MAKEFILE_LIST} +.PHONY:run +run: ## purge build time artifacts + $(DOCKER_COMMAND) bash .PHONY:clean clean: ## purge build time artifacts rm -rf dist/ build/ coverage/ pypoetry/ pip/ **/__pycache__/ .pytest_cache/ .cache .coverage diff --git a/logdna/logdna.py b/logdna/logdna.py index 2ad02fc..8ccfc19 100644 --- a/logdna/logdna.py +++ b/logdna/logdna.py @@ -4,6 +4,7 @@ import sys import threading import time +import traceback from concurrent.futures import ThreadPoolExecutor @@ -117,6 +118,7 @@ def buffer_log_sync(self, message): else: self.start_flusher() else: + print('could not acquire a lock') self.secondary.append(message) def clean_after_success(self): @@ -135,6 +137,8 @@ def flush(self): self.internalLogger.debug('Error in calling flush: %s', e) def flush_sync(self): + print('buf_size {}'.format(self.buf_size)) + print('\n'.join(traceback.format_stack())) if self.buf_size == 0: return if self.lock.acquire(blocking=False): @@ -189,6 +193,8 @@ def send_request(self, data): response.raise_for_status() status_code = response.status_code + print(status_code) + print(response.text) if status_code in [401, 403]: self.internalLogger.debug( 'Please provide a valid ingestion key.' + diff --git a/t.py b/t.py new file mode 100644 index 0000000..9967170 --- /dev/null +++ b/t.py @@ -0,0 +1,29 @@ +import logging +import os +from logdna import LogDNAHandler + +app = os.environ.get('APP', 'bloop') +# Set your key as an env variable +# then import here, its best not to +# hard code your key! +key = '50193c701e25003b9e40124015bf2c2d' + +log = logging.getLogger('logdna') +log.setLevel(logging.INFO) + +options = { + 'hostname': 'pytest', + 'ip': '10.0.1.1', + 'mac': 'C0:FF:EE:C0:FF:EE', + 'url': 'https://logs.use.dev.logdna.net/logs/ingest' +} + +# Defaults to False; when True meta objects are searchable +options['index_meta'] = True + +test = LogDNAHandler(key, options) + +log.addHandler(test) + +log.warning("Warning message", {'app': app}) +log.info("Info message", {'app': app})