Skip to content

Instantly share code, notes, and snippets.

@speedlog
Last active February 20, 2022 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speedlog/1efb9996d3b9813407b3814b3a462744 to your computer and use it in GitHub Desktop.
Save speedlog/1efb9996d3b9813407b3814b3a462744 to your computer and use it in GitHub Desktop.
Playbook for setting logging level in springboot application through actuator.
- hosts: "{{ nodes }}"
gather_facts: no
vars:
- category: ROOT # pass here ROOT or package or classname with package
- level: INFO # pass here logging level or null
tasks:
- name: "Change logging level to '{{ level }}' for '{{ category }}'"
when: level != "null"
uri:
url: "http://localhost:8080/actuator/loggers/{{ category }}"
method: POST
status_code: 204
body: "{\"configuredLevel\": \"{{ level }}\" }"
body_format: json
headers:
Content-Type: "application/json"
- name: "Remove configured logging for '{{ category }}'"
when: level == "null"
uri:
url: "http://localhost:8080/actuator/loggers/{{ category }}"
method: POST
status_code: 204
body: "{\"configuredLevel\": null }"
body_format: json
headers:
Content-Type: "application/json"
@speedlog
Copy link
Author

speedlog commented Feb 15, 2022

You can run playbook with variables:

  • nodes - IP addresses or server group from your inventory
  • category - ROOT or package or classname with package
  • level - logging level for example INFO or null

Run example

ansible-playbook change-logging-level.yaml \
--extra-vars "nodes=localhost category=pl.speedlog.example.logging_level.AnotherScheduler level=TRACE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment