Logging

🕓 10 minutes

What you’ll learn#

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

  • Logging helps you to:
    • follow the system actions and information about user,
    • reveal application problems and where they occur.

Prerequisites#

Overview#

Loki tool#

CodeNow is using the Loki tool for both logs and metrics, which is a horizontally-scallable log aggregation system.

Logs#

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

log_step_1

  1. You can investigate your application logs by entering the specific query into the query field and click on the "Run Query" button.
  • Some basic queries are:

    • 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.

  • You can find out more by looking at the "Loki Cheat Sheet", where you can find instructions on how to write queries for the Loki tool.

    log_step_2

    log_step_2

  1. The appeared graph shows you the request statistics in time. Below it you will find application logs.
  • Also you can change, if you'd like to see the time, unique labels, wrap lines or set the dedup.
log_step_2

  1. You can set the time range for your application, to see corresponding logs.
log_step_3

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

  1. To see the history of your requested queries, click on the "Query history" button.
    • Inside, you will find a "Setting" section, where you can change the history time span and other options.
log_step_5

  1. If you want to add another query and run both of them at the same time, you can click on the "Add query" button.
    • If you want to remove one of the queries, simply click on the button with the minus sign on it.
log_step_6

log_step_6

  1. You can split your screen into two by clicking on the "split" sign.
log_step_9

  1. "Log labels" section contains predefined queries that you can use for your application.
    • You can search through the different categories such as container, node, release, stream etc.
log_step_8

Metrics#

  1. Metric queries extend the log queries and calculate the sample values based on the content of the logs from a log query.
  • Metric queries can be used to calculate things such as the rate of error messages, or the top N log sources with the most amount of logs over the last 3 hours.
metrics

  1. You can investigate your application metrics by entering the specific query into the query field.
  • You will see a graph that represents the statistics of the requests in time. Below it, you will find the application metrics.
log_step_2

  • You can look at the "LogQL Cheat Sheet", where you find instructions on how to write queries for extracting metrics.
    • TIP: Instead of a job , you can place the name of your namespace(namespace="_your_namespace_").
logql_cheat_sheet

What’s next?#

See our other manuals: