You are reading the article Lists Of Options In Tkinter Grid With Various Examples updated in December 2023 on the website Daihoichemgio.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Lists Of Options In Tkinter Grid With Various Examples
Introduction to Tkinter GridWeb development, programming languages, Software testing & others
Syntax:
widget.grid(options_of_grid) Lists of Options in Tkinter GridBelow mentioned are the different options provided:
column: This option is used to put the widget in a column that is leftmost column. The default column is 0.
columnspan: This option keeps track of how many columns it will take to occupy widgets, and by default, this is 1.
ipadx and ipady: These two options are used for how many pixels on the interface to pad the widgets in horizontal and vertical, respectively, but it will be used in padding inside the widgets border.
padx and pady: These two options are similar to the above options, but these are used to pad outside widget borders in horizontal and vertical padding the pixels.
row: This option is when the widget is to put in a row; by default, the first row is empty.
rowspan: This option will be used to tell how many rowwidgets are occupied, and the default value is 1.
sticky: This option is used when a cell cannot fit in the widget, which means when the cell is larger than the widget, then this option is used to know which sides and corners of the widgets the cell can stick to. By default, widgets are always centered in the cell. Sticky uses similar to compass directions to stick the cells to the widgets like North, south, east, west and all the combination of these four.
Examples of Tkinter GridIn this article, we will see the Python grid() method in Tkinter. This method is usually used to design and manage the widgets in the graphical interface. This is a geometry manager to manage the widgets in a table-like structure; usually, a 2-dimensional table is used to manage these widgets in the parent widget, which is in turn split into row and column.
As we saw, that grid is one of the modules or class of geometry manager that is available in Tkinter. There are geometry managers like “pack”, which is also very good and powerful, but it’s very difficult to understand, and another geometry manager is “place”, which gives us complete control of positioning or placing each element. The grid manager is best known for its flexibility, easy to understand, easy to use, and mix features, which makes the grid manager powerful than any other geometry manager.
Now let us see a few examples to understand the grid geometry manager with the following code below:
Example #1 import tkinter as tk courses = ['C','C++','Python','Java','Unix','DevOps'] r = ['course'] for c in courses: tk.Label(text=c, width=15).grid(column=0) tk.Label(text=r, relief=tk.RIDGE, width=15).grid(column=1) tk.mainloop()Output:
Explanation: In the above example, firstly, we need to import Tkinter and then we need to declare the parent cell as “tk”, in which we want the grid layout of the widgets in row and column-wise. So in the above code, we have taken a column as the courses and each row is kept for each course; to do this, we have taken a list of programming languages as a column, and these are labeled as courses for each language row-wise. Hence the grid manages to display it in a two-dimensional table. You can even modify the above code to look it more attractive by using ridges which means it looks like boxes are drawn for every row in relief as you can see in the output, and you can also give some background color by using “big”, and you can have the tabs in the sunken mode for relief.
Example #2 from tkinter import * root = Tk() btn_column = Button(root, text="This is column 2") btn_column.grid(column=2) btn_columnspan = Button(root, text="With columnspan of 4") btn_columnspan.grid(columnspan=4) btn_ipadx = Button(root, text="padding horizontally ipadx of 3") btn_ipadx.grid(ipadx=3) btn_ipady = Button(root, text="padding vertically ipady of 3") btn_ipady.grid(ipady=3) btn_padx = Button(root, text="padx 2") btn_padx.grid(padx=4) btn_pady = Button(root, text="pady of 2") btn_pady.grid(pady=2) btn_row = Button(root, text="This is row 2") btn_row.grid(row=2) btn_rowspan = Button(root, text="With Rowspan of 3") btn_rowspan.grid(rowspan=3) btn_sticky = Button(root, text="Sticking to north-east") btn_sticky.grid(sticky=NE) root.mainloop()Output:
Explanation: In the above program, we have imported Tkinket, and we have imported “*”, which means all the methods or functions in the Tkinter can be imported. Then we are declaring the parent cell as “root” as this is a master widget in which other widgets are placed, and we are calling the “Tk()” method from Tkinter, which is used for creating the main window. At the end of the program, we write “root. mainloop”, where mainloop() is a method from Tkinter again which is used to run your GUI application; when it is ready, it waits for the event to occur and then processes this event until the window is closed. In the above code, we have used a button widget to demonstrate all the grid() class options. So each option is displayed using this widget with their working, or we can say how the options layout of grid works.
ConclusionIn this article, we have seen how to develop the GUI in Python using Tkinter. This Tkinter, in turn, has different geometry managers to make the GUI layout look attractive ad we can use them according to our requirements. The geometry managers are grid() which is very powerful and most widely used, pack() is also used, but as it is a little hard to understand than a grid(), place() manager is used to control the layout. The above article explains about the grid() geometry manager along with the options used in it.
Recommended ArticlesThis is a guide to Tkinter Grid. Here we discuss the Introduction and lists of options in Tkinter Grid along with different examples and code implementation. You may also have a look at the following articles to learn more –
Tkinter Menu
Tkinter Widgets
Tkinter Messagebox
Tkinter Menubutton
You're reading Lists Of Options In Tkinter Grid With Various Examples
Working Of Count In Pyspark With Examples
Introduction to PySpark Count
PySpark Count is a PySpark function that is used to Count the number of elements present in the PySpark data model. This count function is used to return the number of elements in the data. It is an action operation in PySpark that counts the number of Rows in the PySpark data model. It is an important operational data model that is used for further data analysis, counting the number of elements to be used. The count function counts the data and returns the data to the driver in PySpark, making the type action in PySpark. This count function in PySpark is used to count the number of rows that are present in the data frame post/pre-data analysis.
Start Your Free Software Development Course
Syntax:
b.count()
b: The data frame created.
count(): The count operation that counts the data elements present in the data frame model.
Output:
Working of Count in PySpark
The count is an action operation in PySpark that is used to count the number of elements present in the PySpark data model. It is a distributed model in PySpark where actions are distributed, and all the data are brought back to the driver node. The data shuffling operation sometimes makes the count operation costlier for the data model.
When applied to the dataset, the count operation aggregates the data by one of the executors, while the count operation over RDD aggregates the data final result in the driver. This makes up 2 stages in the Data set and a single stage with the RDD. The data will be available by explicitly caching the data, and the data will not be in memory.
Examples of PySpark CountDifferent examples are mentioned below:
But, first, let’s start by creating a sample data frame in PySpark.
Code:
data1 = [{'Name':'Jhon','Sal':25000,'Add':'USA'},{'Name':'Joe','Sal':30000,'Add':'USA'},{'Name':'Tina','Sal':22000,'Add':'IND'},{'Name':'Jhon','Sal':15000,'Add':'USA'}]The data contains the Name, Salary, and Address that will be used as sample data for Data frame creation.
a = sc.parallelize(data1)The sc.parallelize will be used for the creation of RDD with the given Data.
b = spark.createDataFrame(a)Post creation, we will use the createDataFrame method for the creation of Data Frame.
b.show()Output:
Now let us try to count of a number of elements in the data frame by using the Dataframe.count () function. The counts create a DAG and bring the data back to the driver node for functioning.
b.count()This counts up the data elements present in the Data frame and returns the result back to the driver as a result.
Output:
Now let’s try to count the elements by creating a Spark RDD with elements in it. This will make an RDD and count the data elements present in that particular RDD data model.
The RDD we are taking can be of any existing data type, and the count function can work over it.
a = sc.parallelize(["Ar","Br","Cr","Dr"]) a.count()Now let’s try to do this by taking the data type as Integer. This again will make an RDD and count the elements present in that. Note that all the elements are counted using the count function, not only the distinct elements but even if there are duplicate values, those elements will be counted as part of the Count function in the PySpark Data model.
a = sc.parallelize([2,3,4,56,3,2,4,5,3,4,56,4,2]) a.count()Output:
Note: It is an action operation in PySpark. It returns the count of elements present in the PySpark data model. Second, an action operation brings back the data to the driver node, so shuffling of data happens. Finally, it initiates DAG execution in PySpark Data Frame.
Conclusion Recommended ArticlesThis is a guide to PySpark Count. Here we discuss the introduction, working of count in PySpark, and examples for better understanding. You may also have a look at the following articles to learn more –
PySpark Round
PySpark Column to List
PySpark Select Columns
PySpark Join
Different Function Of Linspace In Matlab With Examples
Introduction to Linspace MATLAB
MATLAB is a technical computing language. MATLAB gets its popularity from providing an easy environment for performing and integrating computing tasks, visualizing & programming.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Uses of MATLAB include (but not limited to)
Computation
Simulation
Modeling
Data analytics (Analysing and Visualizing data)
Prototyping
Application development
Engineering & Scientific graphics
Linspace Function in MATLABIn this article, we will understand a very useful function of MATLAB called ‘linspace’. This function will generate a vector of values linearly spaced between two endpoints. It will need two inputs for the endpoints and an optional input to specify the number of points to include in the two endpoints.
X = linspace(a1, a2)
Now let us understand this one by one
1. X=linspace(a1,a2)This function will return a row of a vector of 100(default) linearly spaced points between a1 and a2
a1 and a2 can be real or complex
a2 can be either larger or smaller than a1
If a2 is smaller than a1 then the vector contains descending values
Here is an example to understand this:
Example #1X = linspace(-1, 1)
It will generate a vector of 100 evenly spaced vectors for the interval [-1, 1]
Output:
Example #2X = linspace(2, 3)
It will generate a vector of 100 evenly spaced vectors for the interval [2,3]
Output:
Example #3X = linspace(2, 1)
Here a2 is smaller than a1, it will generate a vector of 100 evenly spaced vectors for the interval [2,1] in descending order
Output:
2. X=linspace(a1,a2,n)This function will return a row of a vector of “n” points as specified in input for linearly spaced points between a1 and a2. This function gives control of the number of points and will always include the endpoints specified in the input as well.
If n is 1, the function will return a2 as output
If n is zero or negative, the function will return 1by0 empty matrix
Here is an example to understand this:
Example #1X = linspace(-1, 1, 7 )
It will generate a vector of 7 evenly spaced vectors for the interval [-1, 1]
Output:
Example #2X = linspace(2,3,5)
It will generate a vector of 5 evenly spaced vectors for the interval [2,3]
Output:
Example #3X = linspace(2, 3, 1)
Here n = 1, so the function will return a2 input parameter
Output:
Example #4Here n = 0, so function will return 1X0 empty double row vector
Output:
Vector of evenly spaced Complex numbersX = linspace(2+2i, 3+3i)
Here a1 and a2 are complex numbers, it will generate a vector of complex numbers for 100 evenly spaced points for the interval [2+21, 3+3i]
Output:
X= linspace(1+1i, 5+5i, 4)
It will generate a vector of complex numbers with 4 evenly spaced point for the interval [1+1i, 5+5i]
Output:
The linspace function in MATLAB provides us with an array/matrix comprising the desired number of values starting from and ending at a declared value. The produced array will have exactly the desired number of terms which will be evenly spaced. The values will be in the range of start and end values passed. So, the linspace function will help us in creating an instantiated matrix or array.
Recommended ArticlesThis is a guide to Linspace MATLAB. Here we discuss the introduction, Linspace Function in MATLAB and Vector of evenly spaced Complex numbers with examples and outputs. You can also go through our other suggested articles to learn more–
Color Grid Design In Photoshop
I’ll be using Photoshop CS5 throughout the tutorial, but any recent version will work.
In this Photoshop Effects tutorial , we’ll learn how to create a colorized grid design ! We’ll use Photoshop’s guides and rulers to set up the initial spacing, then a couple of rarely used selection tools to convert the guides into an actual grid. We’ll learn how to easily select random squares in the grid and colorize them with adjustment layers and blend modes, and finally, how to color and adjust the appearance of the grid itself!
How To Create A Color Grid Design Step 1: Create A New Photoshop DocumentLet’s begin by creating a new document for the grid. Go up to the File menu in the Menu Bar along the top of the screen and choose New:
The New Document dialog box.
Step 2: Show RulersGo up to the View menu at the top of the screen and choose Rulers, or press Ctrl+R (Win) / Command+R (Mac) to quickly turn the rulers on with the keyboard shortcut:
Step 3: Change The Ruler Measurement Type To Percent Step 4: Drag Out Horizontal And Vertical Guides At 10 Percent IncrementsDo the same thing to add a guide at each 10% increment (20%, 30%, 40%, and so on), all the way up to the 90% mark. Your document should now appear divided into 10 equally-spaced vertical columns:
The guides divide the document into 10 vertical columns.
The guides divide the document into a grid of squares.
With the guides in place, press Ctrl+R (Win) / Command+R (Mac) on your keyboard to hide the rulers, since we no longer need them.
Step 5: Add A New Blank Layer And Name It “Grid”Name the new layer “Grid”.
The new blank layer appears in the Layers panel above the Background layer:
Photoshop adds the new layer and names it “Grid”.
Step 6: Create A Selection From The GuidesWe’ve divided our document up into a grid using Photoshop’s guides, but the guides are just for visual reference. They won’t be of any real use to us unless we somehow convert them into an actual pixel-based grid, and we can do that easily using a couple of Photoshop’s rarely used selection tools – The Single Row and Single Column Marquee Tools.
A grid of horizontal and vertical selection outlines.
Step 7: Fill The Selection With BlackGo up to the Edit menu at the top of the screen and choose Fill:
This fills the selections with black, although it may be hard to see with the guides and selection outlines in the way, so go up to the Select menu at the top of the screen and choose Deselect, which will remove the selection outlines:
With the selection outlines and guides removed, we can see our black grid on the Grid layer:
The black grid lines now appear.
Step 8: Open The Photo You Want To Use With The EffectOpen the photo you’ll be using with the grid effect. Here’s my image:
Open the photo.
If you’re using Photoshop CS3 or earlier, the photo will automatically open in its own floating document window. If you’re using Photoshop CS4 or CS5, depending on how you have things set up in Photoshop’s Preferences, the photo may open in a tabbed document. If that’s the case, to make the next step easier, go up to the Window menu at the top of the screen, choose Arrange, and then choose Float All in Windows (CS4 and CS5 only):
Step 9: Drag The Photo Into The Grid DocumentGrab the Move Tool from the top of the Tools panel.
With the Move Tool selected, hold Shift and drag the photo into the grid document.
Release your mouse button, then release your Shift key, and the photo will appear centered inside the grid’s document window. You can close out of the photo’s document at this point since we no longer need it:
Holding the Shift key is what centers the photo inside the document when you drag it.
Notice that the grid appears in front of the photo. That’s because, if we look in the Layers panel, we see that the photo has been placed on its own layer under the Grid layer, just as we wanted:
Photoshop placed the photo on a new layer directly above the layer that was active, which is why we first selected the Background layer.
Step 10: Resize The Photo If Needed With Free TransformIf you need to resize your photo inside the grid document, go up to the Edit menu at the top of the screen and choose Free Transform:
This places the Free Transform bounding box and handles around the image. If you can’t see the handles because the edges of your photo extend beyond the viewable area in the document window, go up to the View menu and choose Fit on Screen:
Drag any of the corner handles to resize the image with Free Transform.
If you zoomed the image out a moment ago using the Fit on Screen command and want to zoom back in now that you’re done resizing the image, go back up to the View menu and choose Actual Pixels (see our Zooming and Panning in Photoshop tutorial for more info on zooming in and out of documents):
Step 11: Select The Grid Layer Step 12: Select The Magic Wand ToolIn Photoshop CS3 and higher, the Magic Wand is hiding behind the Quick Selection Tool.
Step 13: Select The Outer Edge SquaresAll of the outer edge squares now have selection outlines around them.
My initially selected squares.
Step 14: Add A New Layer Below The Grid LayerThe new layer appears below, not above, the Grid layer.
Step 15: Fill The Selected Squares With WhiteSet the Use option to White.
Photoshop fills the selected squares with white. Deselect the squares by going up to the Select menu and choosing Deselect, or simply press Ctrl+D (Win) / Command+D (Mac) to deselect them with the keyboard shortcut:
A border of white squares appears around the image.
Step 16: Select The Grid Layer Step 17: Select Different Squares Step 18: Select The Photo LayerSelect the photo layer in the Layers panel.
Step 19: Colorize The Squares With A Hue/Saturation Adjustment LayerChoose Hue/Saturation from the list of adjustment layers that appears:
Choose Hue/Saturation from the list.
Step 20: Change The Blend Mode For The Adjustment Layer To ColorIf we look in the Layers panel, we see the adjustment layer sitting directly above the photo layer. Make sure it’s selected (highlighted in blue), then go up to the Blend Mode option at the top of the Layers panel and change its blend mode from Normal (the default mode) to Color. This makes sure we’re changing only the colors in the image, not the brightness values:
Change the blend mode of the Hue/Saturation adjustment layer to Color.
Here’s my document after colorizing some of the squares red:
A few red squares have been added to the effect.
Step 21: Select And Colorize More SquaresYou can also use a Hue/Saturation adjustment layer to completely desaturate some of the squares, leaving them black and white. To do that, select some squares, then add a Hue/Saturation adjustment layer as you normally would, but rather than choosing a color with the Hue slider, simply drag the Saturation slider all the way to the left, which will remove all the color (no need to select the Colorize option, either):
Remove all color from some squares by dragging the Saturation slider all the way to the left.
Here’s my effect so far after colorizing more squares with additional Hue/Saturation adjustment layers. In case you want to use the same colors I did, for blue I set Hue to 200, Saturation to 30. For Green, Hue was set to 120, Saturation 25. For Purple, Hue was 289, Saturation 35. And as I just mentioned, for the black and white squares, Saturation was set to -100 by dragging the slider all the way to the left:
The colorized grid effect so far.
Step 22: Try A Different Color Mode For Some Of The Adjustment LayersThe one problem I have with my result so far is that it doesn’t really look as bright and colorful as I was hoping for. One way to change that is to change the blend mode for some of the adjustment layers. If we look in the Layers panel, we can see all the adjustment layers I’ve used to colorize the squares. There’s five in total, including the one I used for the black and white effect:
Five adjustment layers were used for the effect.
Selecting the red Hue/Saturation adjustment layer, then changing its blend mode to Screen.
Changing a blend mode may require adjustments to the color’s saturation level.
Here’s my image after changing the blend mode for red to Screen and increasing its color saturation. Notice the red squares now look brighter:
Screen is a popular blend mode commonly used to quickly brighten images.
Different blend modes will give you different effects. Screen, Multiply and Overlay are good ones to try.
Step 23: Change The Color Of The Grid Lines To White Step 24: Fill The Grid Lines With WhiteWith the Lock Transparent Pixels option selected on the Grid layer, anything we do to the layer will affect only the pixels themselves. It will not have any affect on the transparent areas. This way, if we fill the layer with, say, white (as we’re about to do), only the grid lines will be filled with white. The transparent areas on the layer will remain transparent.
Photoshop fills the layer with white but only the grid lines are affected.
Step 25: Add A Stroke Layer StyleChoose Stroke from the list of layer styles that appears:
Select Stroke from the list.
Change the color of the stroke to white, then adjust its width with the Size slider.
The final result.
Learn The Various Methods Of Powershell Join
Introduction to PowerShell Join
The join cmdlet is used to join multiple strings into a single string. The order in which the multiple strings are retained during the concatenation operation is the same order in which they are passed to the cmdlet. Join cmdlet is also used to covert text that is present in pipeline objects into a single string value. This article will explain in detail about join cmdlet in PowerShell, its syntax and usage along with appropriate examples.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
The basic syntax of the join operator is as follows
Where string1, string2 and string3 represent the various strings that needs to be merged. The delimiter represents the character that should be present between the strings that are concatenated. If no value is specified, the “” is used by PowerShell.
The following are the other available syntax
For the Join-String cmdlet, the default separator that is used by PowerShell is $OFS if the user doesn’t specify any value. If a property name is specified, then that property’s value can be converted to a string and subsequently concatenated to a string. A script block can also be used in place of a property name. If that is done, then the script block’s result is converted to a string before concatenation. This cmdlet is the latest and was released as part of PowerShell version 6.2
When the comma has used a delimiter with the join operator, the join operator is given a higher priority. In that case, only the first string is considered, in order to avoid that the strings must be enclosed in parentheses.
Example:
Input:
Output:
onetwothreefourfive
Parameters:
DoubleQuote:
This parameter is used to encapsulate each pipeline objects string value inside double quotes. The datatype of this parameter is switch and its default value is false. This parameter doesn’t accept pipeline input and wildcard characters are also not accepted.
FormatString:
This denotes the format structure of the item. The datatype of this parameter is string. None is the default value of this parameter. This parameter doesn’t accept pipeline input and wildcard characters are also not accepted. This is an optional parameter.
InputObject:
This denotes the input texts that are to be joined. It can either be a variable or a command object. The datatype of this parameter is PSObject[]. This parameter’s default value is none. This parameter accepts pipeline input whereas wildcard characters are not allowed. This is an optional parameter.
OutputPrefix:
This denotes the text that will be inserted before the result. It can contain special characters such as newline or a tab. The datatype of this parameter is string. It can be referred using its alias, op. None is the default value of this parameter. This parameter doesn’t accept pipeline input and wildcard characters are also not accepted. This is an optional parameter.
OutputSuffix:
This denotes the text that will be inserted after the result. . It can contain special characters such as newline or a tab. The datatype of this parameter is string. It can be referred using its alias, os. None is the default value of this parameter. This parameter doesn’t accept pipeline input and wildcard characters are also not accepted. This is an optional parameter.
Property:
Separator:
This denotes the character that needs to be inserted between the text that are joined from the pipeline object. It is generally a comma(,) or a semicolon (; ). It is placed at the number one position. None is its default value. Both pipeline input and wild card characters aren’t accepted. This is a mandatory parameter.
SingleQuote:
This parameter is used to wrap the output string value from pipeline object inside single quote. Its datatype is switch. None is its default value. Both pipeline input and wild card characters aren’t accepted. This is an optional parameter.
UseCulture:
This uses the current culture’s separator as the value of the item delimiter. To find this information, Get-Culture).TextInfo.ListSeparator is used. The datatype of this parameter is switch. None is its default value. Both pipeline input and wild card characters aren’t accepted. This is an optional parameter.
Example:
$stringa,$stringb -join “`n”
Output:
Conclusion Recommended ArticlesThis is a guide to PowerShell join. Here we discuss how can PowerShell join achieved using various methods and also explained the various parameters. You may also look at the following article to learn more –
How Logging Work In Scala With Examples
Introduction to Scala Logging
Logging is used to maintain the logs of an application. It is very much required to monitor our application. Logging helps us to monitor the activity of our application in case if any error occurs we can check it from the logs and fix it. We can also get the information about what activity is going on into out application. we can have day to day task and full monitoring of applications. It also keeps track of the unusual errors or circumstances which can lead down fall of our application. Majorly it is very helpful for the developers to keep track of all the actions performed and the error occurs if any.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
In scala also we have three levels of logging which are debug, info and error. But we need to set this in our application configuration which level we want to use. This levels will be different according to different environment lets discuss them with syntax see below;
Debug level syntax; debug(our message) Info level syntax; info(our message) Error level syntax; error(our message)In this way we can define them our application and we have to enable the log level accordingly and also make entries into configuration to make them work.
How Logging Work in Scala?Scala logging is important and works like any other programming language. To keep track of our application we can use logging it can be used with different levels. To apply logging we can simply use scala logging for this. Scala provides us one logger class which is present inside this com.typesafe.scalalogging package also this class internally wraps the SLF4J logger. To use scala logging we have to pass or give a name to one of the method available in Logger object. We will see this by syntax see below;
We can pass the name in many different ways we can discuss them in details with one practice example for beginners for better understanding of logging concept;
1. In this we can pass the name directly to the Logger class.
vallogger_name = Logger("any_name")In this syntax, we just have to give the name for the logger and one logging name pass as parameter inside the Logger class.
2. In this case, we can wrap our class by the implicit tag parameter.
vallogger_name = Logger[Your_Class_Name]In this syntax, we are passing our class to the implicit tag parameter.
3. In this case, as we know this scala logging internally use SLF4J, so we can pass the name to the SLF4J logger instance also.
vallogger_name = Logger(LoggerFactory.getLogger("any_name"))4. In this, we pass inside the class.
vallogger_name = Logger(classOf[Your_Class_Name])Inside this package com.typesafe.scalalogging it provides us two traits which are Strict Logging and Lazy Logging and they are responsible to define the logger as Strict or Lazy.
Now we have one more this which is called Application logging: Application logging keeps track of our application at runtime and maintains all the logs. But sometime it may happen that we want all the logs of our application so we have to maintain the audit of logging and this can be achieved by storing our runtime application logs somewhere like database, into a disk, or search engine etc.
There are some things which all application wat to capture as a log;
As we talked about the log levels i.e. information, error, and warning.
The most important thing is the timestamp.
Some relevant messages make any sense after some time also.
The log levels define various things see below;
Error: Error is something which is serious and shows something wring with our application it is not behaving normal as expected. This can be anything like related to database connection; some services are not available or stopped due to some failure etc. So this is very important to fix and make our application again up and running.
Debug: Debug level is something like when we perform our diagnosis regarding the application. Like if we are making any request for data to the database so is it working properly and fetching all the data that is applicable regarding the request we have made.
Trace: This is a more detailed version of the debug level. When we want to know the very precious value than we go for Trace in scala logging.
Examples of Scala LoggingIn this example, we are using Print Writer and File to maintain our logs in scala. We will create a file into our system and going to maintain the logs there.
Example #1Code:
import java.io.{File, PrintWriter} object LoggingDemo extends App { val pw = new PrintWriter(new File("logging_demo.log")) pw.write("logging file has been created") pw.write("loggers working fine") pw.close() } Example #2In this example, we are using slf4j to log the activity of our program. We have using different methods available for logging like debug, error, and info.
Code:
import org.slf4j.LoggerFactory object Main extends App { valmy_logger = LoggerFactory.getLogger(getClass.getSimpleName) my_logger.info("Here we are using info method !!!! ") my_logger.debug("Here we are using debug method !!!! ") my_logger.error("Here we are using error method !!!! ") println("logges been created. !!!") }Output:
ConclusionWe use logging for monitoring purposes. Which helps us to behave our application as expected. We can also provide different logging levels as well. We can maintain any number of lines to log out application activity we can also store them somewhere into the file for the future purpose also these file representation makes it easier to understand.
Recommended ArticlesWe hope that this EDUCBA information on “Scala Logging” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
Update the detailed information about Lists Of Options In Tkinter Grid With Various Examples on the Daihoichemgio.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!