Table of contents
1.
Introduction
2.
Logging Events in Salt
3.
Configurations Settings
3.1.
LOG_FILE
3.2.
LOG_LEVEL
3.3.
LOG_LEVEL_LOGFILE
3.4.
LOG_DATEFMT
3.5.
LOG_DATEFMT_LOGFILE
4.
Frequently Asked Questions
4.1.
How do I determine whether my Salt master is active?
4.2.
How can I check whether my salt system is functioning properly?
4.3.
What ports is SaltStack running on?
5.
Conclusion
Last Updated: Mar 27, 2024
Medium

Logging in Salt

Author Neha Chauhan
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Salt or SaltStack is an IT (Information Technology) infrastructure management tool. It can be used for managing hundreds of computers or servers. Using Salt or SaltStack, you can perform some hardware or software jobs on hundreds of computers remotely by using a Master Computer. You can perform the task for many computers simultaneously. 

Salt works on the Master-Slave model. You can send commands from the master to the slave and perform system configuration on the slave systems. The Slaves are called Minions in Salt. 

Logging is used to track the running software events. An event is described by a descriptive message, which can optionally contain variable data. 

logging in salt

In this article, we will discuss the ways of logging the data in Salt. 

Logging Events in Salt

Salt provides many functionalities to keep track of the events happening in the computer system while the Salt Minion is performing a job. Logging the events is important as it helps in identifying the problems and errors. 

You can log different events like errors, warnings, garbage values or critical errors. 

Salt uses Python’s logging library. A sequence of priority is given to each type of log event. Setting the log level to a specific level will log all the statements at that level or higher levels. 

There are the following log levels in Salt - 

Level Numeric Value Description
quite 1000 Nothing should be logged. 
critical  50 Only critical errors will be logged. 
error 40  All the errors will be logged. 
warning 30 All the warnings are logged. 
info 20  It consists of normal log information. 
profile 15 Profiling information on Salt performance.
debug  10 It consists of the information that can be used for debugging. 
trace 5 It contains detailed debugging information. 
garbage 1 It contains, even more, debugging information.
all All kinds of events will be logged. 

Configurations Settings

You can use the following parameters for logging various types of events.

LOG_FILE

This parameter is used for identifying where the log files should be stored. The files are passed through the file that can contain the local path name (like master or minion path name) as well as the external server path. 

Make the following configuration to store the data in Master 

log_file: /var/log/salt/master

 

Make the following configuration to store the data in Minion

log_file: /var/log/salt/minion

 

Make the following configuration to store the data in External network or server. 

log_file: udp://loghost:port

LOG_LEVEL

This parameter is used to identify which event is to be logged. Various log events are - all, garbage, trace, debug, profile, info, warning, error and critical. 

Make the following configurations if you want to log all the errors. 

log_level: error

 

Set the LOG_LEVEL to quite if you want to disable the logging. 

log_level: quite

LOG_LEVEL_LOGFILE

This parameter is used to identify which level of messages should be sent to the log file. Various levels are - all, garbage, trace, debug, profile, info, warning, error, critical and quit. 

Make the following configurations to log all the warning messages: 

log_level_logfile: warning

 

By default, this parameter is set to info level. 

LOG_DATEFMT

Use this parameter to set the format for the time format for the logged messages. 

Make the following configurations to set the time:

log_datefmt: '%H:%M:%S'

 

By Default the format is %H:%M:%S. 

LOG_DATEFMT_LOGFILE

Use this configuration to set the log messages' date and time format. 

Make the following configurations to set the date and time:

log_datefmt_logfile: '%Y-%m-%d %H:%M:%S'

 

By Default the format is %Y-%m-%d %H:%M:%S. 

Frequently Asked Questions

How do I determine whether my Salt master is active?

We can determine it by using Salt-Master Live Profiling. Salt-master will report the results' filename if executed in the foreground. The results are typically stored in c:temp on Windows systems and /tmp on Unix-based devices.

How can I check whether my salt system is functioning properly?

The core idea of Salt is that of a Master who commands one or more Minions. The Master is the Central Management System. Executed on managed systems, the Salt minion communicates with Salt Master via instructions and configurations. Linux is the default operating system for the Salt Master, although any other system can be a minion.

What ports is SaltStack running on?

The ports 4505 and 4506, used by the Salt master, need to be open in order to receive incoming connections.  With a persistent connection to the publisher port, all Salt minions wait for messages using port 4055.

Conclusion

Pat yourself on the back for finishing this article. In this article, we discussed the different ways of logging events in Salt. We started by discussing the various log levels and then discussed some parameters that can be used to configure the event logs. 

Do not stop learning! We recommend you read these articles -

🔥 Job Cache in Salt

🔥 Introduction to Salt

🔥 About Salt 

Head to the Guided Path on the Coding Ninjas Studio and upskill in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more courses.

If you want to Practice top Coding Problems, attempt mock tests, or read interview experiences, head to the Coding Ninjas Studio, our practice platform.

We wish you Good Luck!🎈 Please upvote our blog 🏆 and help other ninjas grow.

Live masterclass