Logging

🕓 10 minutes

What you’ll learn#

How to use logs of your application for monitoring, debugging, and better understanding of the process behind the code.

Logging helps you to:

  • follow the system actions and information about user,
  • and reveal application problems together with the place where they occur.

Prerequisites#

Overview#

Loki tool#

CodeNow is using the Loki tool for logs, which is a horizontally scalable log aggregation system.

  • Loki comes with its own language for queries called LogQL.
  • LogQL uses labels and operators for filtering.

Steps#

  1. Find the "Logging&Tracing" section in the sidebar menu and go to the "Logging" option.
log_1

log_2

  1. You have different options to enter a query:
  • You can use "Log browser" button to automatically generate a query:
    • Select some labels and then select values for each of these labels.
    • Tool will automatically generate the query, which you can see as "Resulting selector" at the bottom of log browser.
    • Press "Show logs" button.
log_3

  • You can write your own queries from basic queries and then click on the "Run Query" button.:
    • Logs for your namespace: {namespace="_name_of_the_namespace_"}
    • Logs for the specific application: {app="_name_of_the_application_", namespace="_name_of_the_namespace_"}
    • NOTE: You can't use traceID for application logs.
log_4

  • To understand how to write more complex queries, please refer to LogQL's online documentation.

  • To understand how to write queries for the Loki tool, please refer to "Loki Cheat Sheet".

log_5

  1. The appeared graph shows you the request statistics in time. Below it you will find application logs.
  • You can also set the appearance of the logs: time, unique labels, wrap lines or dedup. You can additionally flip the results' order.
log_6

  1. You can expand the log to see more details
  • You can click on "Jaeger" button to see the corresponding trace
log_7

log_8

  1. You can set the time range for your application and see the corresponding logs.
log_9

  1. For live monitoring of your application, click on the "Live" button.
    • For pausing or stopping the live monitoring, simply click on the "Live" button again.
log_10

  1. If you want to add another query and run both the original query and the new query at the same time, you can click on the "Add query" button.
    • You can simply disable or remove a query by clicking on buttons in the right side of the query
log_11

log_12

  1. You can split your screen in two by clicking on the "split" sign.
log_13

  1. Here we described the basics of using Logging in Grafana. For more details visit the corresponding section of Grafana's online documentation.

What’s next?#

See our other manuals: