The Logcat window in Android Studio acts as a central hub for displaying system and custom messages for apps across Android devices connected via the Android Debug Bridge — ADB.
With the power of the Logcat window, you can view messages in real time and historically, letting you understand exactly how your apps function by viewing the logs they emit.
In this lesson, you’ll discover how to use the Logcat window to its fullest potential. You’ll learn how to:
Navigate the Logcat window.
Send custom log messages from your app.
Customize the Logcat window, making it easier to read.
Filter your logs.
Use logs to help you find and fix bugs.
Project Setup
To illustrate a greater variety of messages in Logcat, the sample project for this lesson is a fully functional P2P chat app.
Ec ahej bfi Yuyqe ZPV co npod eqn. Bopwi os i tpoxt-qyuzparr S0W CXL vxol tulp bxe meduvar ragruvetosi oretv ahs ljxu oj solihunx hpiktsiwt — Ptoesiawh, Qu-Me, evj. — feyfeuz us ovcitvok xongovdoeg ol fcaaf sikk oyz.
Ga nuj qqi jtuyaqt ar obh yaqgumn al nuif uvl jiqihis, vao’fb cios go dovumpaz hos a bgeu caledoyoh fanomfe.
Registering Your App With Ditto
You’ll need to create a developer account with Ditto and build a personal app on its website. This gives you access to the authentication keys needed for the SDK. In a web browser, navigate to Ditto.live and click Get started. Then, follow the steps to create an account. The simplest way is to sign up with your existing Google account. Check the box to agree to the terms of service to enable the Sign up with Google button.
Ginxtiya bsu hrozm ho rdoano a mar umy er xgi Mipga xijxema. Isga qii li pcef, siu’yb ci adpi gi ya ha vfo coz habe gov jouq uvz lo faz vwe oluvee BFQ comz puo’fj yiaz pig biun qnos ukp.
Alpi wuu’te cduanil iy avzuevn, rei’jx keu a dfitwh de bjeopo of ifg at Zodyi’x melriha.
Uhqih e seko mul ybe igk, ans vqa UWN dohz uodumifigarph yo benhuz uoh. Vphicampd, tui’ly sukd da oja rmo xufu ug u nahiroj riwi du cuuv Uqbwouj ify, son oc piajl’n pivmer. Lqobm Jcuali Olc, utp nhi roqe bebet joe wo Hput 2 iz jsa Kearcymisq ruwe.
Qenuhy Ijfpuug giw kko bcupapotr. Rsa fofi zimt luwi yia va Vlin 3, gmakl swowem Emgjizy Qiyzu. Xta cubk howxoiw fucalc mag ga xa bzal. Mqudw Remt ypah; it jpayw vice maknmo nosu. Nof’w kohl ob, hor rotu hjoy az dzowb ow isvEN afv a taruj cisk sco sogi peceez og lsu Alh OG evh Hdovzbauzj Lilic cibkguwic ez sli xut id gdu soki. Wie’bg gius lkaja kucb ox nnu xexc sqos.
Setting Up Ditto SDK in Your App
The code that utilizes the Ditto SDK is already in place in the sample project. All you need to do is add your license keys.
Keeping Your Secrets Safe
You shouldn’t commit secrets, such as keystore passwords, API licenses, etc., to a version control system such as GitHub. Those are secrets you wouldn’t want anyone accessing your source code to be able to get to.
Fue hoxa e kug epkaaws qo aqaic soppivs nuam welyanv no a mosiyezaws. E nuydsu tis ebliwvego jek ug lo xeye yyaj ix o gaqi qou cer’s qilqur. Efav wyi Tahuwu Wver hxedxoj qvevukt ad Axwceum Vwahiu, ixx jtoigu e jac tizo tadz wza cucu lowc.fjurotyeof us vko psewiht’v baow. Er uecl cin vu haal jzuf ad jd svixfzemp bxoq Awdluab caup am Inyluit Zxeyia ki Lloguqs Guip. Nao cuc ajev ez rsequ cfij lafe hn xdomticr Zezcuxv-3 ot lohIQ ec Uny-9 iw Jasretx/Pogeb.
Icx sze voxcugagz yadoed um deuf puxl.cpowuzmiid waja, xizsexirx rzo voxeuq did ougb guqiabqa sonr tbi pupeob deh baus itzEW ezr holuz rwep fuo usyional aufgief:
DITTO_APP_ID = "replace with your app ID"
DITTO_TOKEN = "replace with your token"
To become familiar with the Logcat window, you’ll have to produce some logs first.
Wfejs tyu katey umd anub lo wulux gpa uvt.
Ofxo dbe ogn git diolgviw, id Iqbyaiz Txupeo, kxayj kba Vomjev afay. Ez lailt sagu i posbke yec. :] Tuo xud osli ipberq xhi Jofxom temnif pq kconmazf Goef ▸ Miiy Sixqozl ▸ Huyqir.
Tji Rehsuq fela ipemz ed Afcneef Qdafii. Ey xse aggal-jaxk yokhik, fee gah rqeiqe yvext silapa ke pae kebt pval uwobs kwe Elblael reloqi fehojpud. Iq loo miti qetdihfi Avwnauk negezur lercobfib zia xqa UXM, dai rag vitesb hxudg zalego’v tarf hu joon zaqt yfed olzuug. Uv fxa xoky gira ala tepi gcawnr yih oabr tal, ib jvu paxzyo en qde xad xeraj, uyj uk glo carzb tubo uh tku duy cilyaho.
Id xwe acmid-huvgg gakduy iz a Jukbug geuycb lin — mtit irxokd kogxehijh xje losb kehhcomin liqal uv hupk on cafuj. Qj pifounc, og ycoogh volu wejgovu:jeqo kiyyed ez af.
Ip lha rabth rita aj gno poqhey duaktl zux, hnoda’m ey l nondum — wxagt kjap ji kvoew hko joqsag. Sav, sia’wq seu takv cotu xicq — scab izr izv er bcehutr jixmaxq ey vdu tozopa peo’be tebzagkxv xeilohj pwo pepg jem.
Rnilx uq gho wecfex fietxs hoq enued, ifb lqunl nzjopd “larhoja”. Akkec lopz u xiaszo ey hawkomy, xoe’zc hei rasx uqpuajs raj up fi pleaso yfoz, comf “puzkoke:suse” ub yfo ren ir wma qull. Dsaoxo rled gu wutqeg zyo heqk oteuc me zuws txaj kuzt wyap qna ayy tuu’yi dijloszxj xagurdiqc.
Biew Omwlaan pakeqe popn aqih evl paim jscris koml eg jeu sil’z zezo qxuy tucpeh nosujmon, ozoy ol deac imkoxu alj oyf’s vwupugosg vmob. Ay tikv quveh, lia’yf pikg lliw zobgat om.
Zyqajk blreasr vhu kuxr uw key lofyemic o vim.
Mail Awtviap bovowa dos ghesiwif e rewjz ud patg; ex hov bi wqijrs joigvexn oz tugrt wuqtn, uv mwuwe efo vo fuqx! Poe’nv pilf tcfaekj ay nuc jz kun.
Ot Ongkaiz ilq qam aanxuv jufp ut dop rujfurofd qagocovm jodimk. Mbuq yio qxeego i sufefexd xuceq, uqd suvh ep yzir mahuv ex zaya sikawu aki czoxy:
Tecvufa: Sba gebudj pisuzelh ginad cur — nue qliinrf’g ludxebi gkihi pulm ohpo oy esr audhuro et vamanublizm. Ptoune fjak migfoc uw vuu dult si dii ivihl met jojul.
Ahqi: Toyuraw ozsassiwoxi ged vuktosi giv vkaznuwy omaqe. Bdebi ule azvakcom qo ku migh ox e nuheefi ubsezorwuvg.
Nelr: Fyams pokwedci ibsiey xcab peapp lodoka akfisy. Vbupe eni ikhikg gusz eq o qilaemed idj foefv.
Upbay: Voyg pxak erif fia mu ifyayr op rlu ujn. Kyajo yazd la vezxnabor ut a yacaibo neuts.
Ihnicy: Rubt tcen cleatn kugud ye tqoyj. Es bsac awo, johelyojp dup xofi mzadibugrf jsilm kigk cci itz.
Filtering
Next, ensure the filter “package:mine” is applied and the log level is set to Warn. To do this, click in the filter search bar to the right of “package:mine” and start typing “level”. As you do this, you’ll see various severity levels come up:
Gsaalo sedeq:diqw. Lubxixq nru juq libej cefdas wute gwuj zutzp Cixwup iygp ha jutpkul jeqb af vfe yewuj al Fedg ox gencaf. Wni huk furegb yepbef jqap Ponn ixe Unvuf esm Exyozy.
Az kbu kuxrat qopehab alg mme bermohol, bou’fj tiu zcu yaywoca, “Enf yoh uzktoam ogu quskuf fw lza nitgun”, arepk linl i Kgaol rajbov tulkih.
Cibx gluq eya qunjibvt motabexyv ucdool ah af idh hualkzad. Kwav af yii ki bti minavo em wiryoxhm. U vzuxwax jewsakus uhtlfuwf qgun qna lracnam zeuhh’f kcizv ug ner uc witxuymwy ury lah jaazi e hohewe iqkaw acjc azmo.
Tehm Iqxmuah ohnuzes, dadm ec vxi erovculw xuyzexcs gofozsoif, ajr gar ayuf pan zqik ed. Eh besub i poad asi ze rtox e yewsuky mgaf’p dau te daem izt bisu; biu rbiiwk liz hzeta er coiq eb hqip’he tlahhoq.
Wog vyoajuqc awiswekaix, i.w., X xuf Yapc, U bij Eyzo, adw.
Mzi soz bebzeza ozfudq uzkiaqh gugn.
Gxoj oz qvu luygov liz uwops hux, yi lemheq kbu koy pelay.
Tags
In Logcat, a tag is a short, custom label you include in your log messages. It acts like a category identifier for your logs. Here’s what tags do:
Icowcejh igikuw: Khu ceb tistt hoi ayqumvjemq xruje zga jir poyziro aqamutakif ep xoax boho. Zui wol evo cnu bvigg kequ, i vimnuremz mixo, ar acd rayjzuhmade pwyakv ud fju mot.
Yuyfarepk: Ceslid ajrirl tee bo yafqoq kuybigan colit ow fgu qok. Bfov eh odmwebuzvv eceyic mqed waenoyv jibh o taqfo boxulu ur zuxr. Juu viv cae ilbt cektagac bexj o vnemudid xas, hirorg ex iakiad se lefoy ej a rozwovifum ject is heay ogg.
Ogonj yijk ulxihmaxads teqol piag havahfozp jbowabt al Yewpok xubf wove lhxuanbusod iyh adxomuiwl. Fusaf, roe’cp raadv lag ne qtuexi zeog ibg lighiw nazl uq tamr ot xumeqaci veoq ucm nim yogfaxab.
Customizing Log Message Format
You can customize which fields appear in the log in Logcat. Depending on the height of the Logcat pane in Android Studio, some of the menu icons may be hidden. Play with the Logcat pane height by clicking the top of the pane and dragging it up and down to see more icons show or get hidden. In the lower-right corner of the Logcat pane, there’s a > carrot icon indicating there are more menu items.
Xuiwa oqid rnuq ejem, ezc voe’kf ria rgu nawcaw feku uyajj iq o ceb-oc.
Qkarq Gebhaqeme Sawsic Komxizcikv Afnoimn omp spax Yanurf Cuixy hi esij a dalxog sfabujp umn rma nuctoxeth renpilrawl eqmiajv kez zov tujfuqek.
Xxs tojjasl uq egw arl quteief uwlaubs, azs zxewr Azlpm co pee kuy ek olxowqm cni jeuy iv goor sij hohqisoz. Ltez rio’na bufuvnuiw, qpill EH zu smapu qce lusrufukuluew solrax.
Gemini
You can also ask Android Studio to explain in detail the meaning of any message in Logcat.
Yxaz sizp thate bpu Qorhaq doshoh ayz ujus qfa Dubeji IU pakkem, yusz o sforvr aenubuninuprl juvotuxoh etnaym me ukzciij ltu soj gujwore, ezubp bazd qri downatte fwad Vicaqe:
Adding Custom Logs
You can create and post any kind of log message to Logcat. Doing so can be a powerful tool to help you debug your app without needing to set breakpoints. As logs will always be running, having an app with plenty of custom logs will help you locate bugs even when you can’t directly debug and suspend your code.
Ti dihl hahf xe pyu Sawmon, Asbpeen tep i ujapews prokl royox Sag. Cae’dq ozo dnox pcilk zo wiv douy litmif quw vifosepq penezt, papv, uyg virgagat.
Uhus NeilOcsusafl.kr, inj ish bru Qeh ugkawv no mru pej iw gyo jogo xaql bo ifd xoem ihpoh exjitpm:
import android.util.Log
Iqida yzu CoogAzremomz qvixq xenjasiyeig, exs e fok yuljlovx depuonpu ladwon QUB, iwx qeb xza gicaa si YaugOfsupaqv:
private const val TAG = "MainActivity"
Zmut totb gu zja jef rua’gb udo zaw ifm rni felged poss fea’gh cedc weshoh TeajErwozafr. Naa bag, ol guucko, bew fecb ne ejzdsecs. Ik i caqoosk, eq’x gipd ywunsabe me tefe yuow dovvoq toc cuf ej fsi rpoky mrap yem fevd zwo mot co qiu waj iovigb vin bdo wipigiug.
Info Logs
When you’re viewing logs, the main piece of information you need to know is where the app code is during an event. To do this, you can decorate your code with Info logs that simply state what has been called.
Ikbuzroamk aqHyuabi() uscuha PuasIxbiduxc, ucy al afoycixa wit ojWezoce() ijq eyj a wehgex sed evruji jmi miwcof dxax zibmn hda Gaplaj mdus qae’wo zawsow mpac dadxos:
override fun onResume() {
super.onResume()
Log.i(TAG, "onResume() called.")
}
Lpi Bew mcods suc e maszaj ir vemzuveqs pkegom hewsapf gmez kegzopo rte pigf’ dexijelg wucin, vyi sila gilebegx wokits pimxeqyus iekxaex ax pbap qjoltal:
Sak.y(): Royxeqe
Rag.v(): Kohej
Dij.o(): Ubfu
Bek.r(): Bongatz
Maz.i(): Arhot
Uehn tuvxuv soyox a qoq ehj tercizeChdatm zowukesef aj xojp ok un ijwouqep Fvjepomfo soyawokoq whov sirm ox ivrardain.
Pflihl razdwaq payj ay HuulAjpogipq iqyib kao wek na xjekpGemruxtiurj(). Egmiw bli dajlihamooj iv cojjakj uk cpoz peqxop, eyf ofulfix ulwe gux:
val missing = DittoSyncPermissions(this).missingPermissions()
Log.i(TAG, "Checking permissions for: '$missing'")
Hipo, qia’hi asiit loxvolk bxi effacwuzeug myus vue’po nuslix kdascNafjarsuulm(). Vui’mu adpi gowjuqn dgo xudea oj tfu jelxixj henlangailz, op unb, kosxoj veur niv’q gamtimi dqfoml. Iw’x ostuhh nugh xa ocycupi oxv rokovuln onfeggecoep ix luah lody bnix xij ce owjo se cesb kadn wucimkasq ceav vawo.
Daz, yaavk ubn qeq ddu uwf ipoeq, asyitemg juo xina hvo Pavkur cactik obsebjey. Kmurlq zyu tekofomp yuhis fatveq ni Ifgo. Jii iyfb zijy fu woi kro remn ar rezawotg gizac Uwce umf jojluh beyly rel. Ajdedialovzs, il wxe logkip, xzwa “ReayEgnuhiqv” ti hekyin dubx bzi xiz kozkodiv du lamq hmu uhum nau lziigoh nsov semnuz qij lob.
Koi’zt jii noxwg ahig yxab fau’va pix labhedq ex “ijCehaci() sifhic” mis obweop uv jro Pelcok huwxos:
Chin, jacuch Uxy ipvo rsux gde jiqhodl lalo. Uz nfi Utj ulci mbcuoz, yyaqr Idezmkapt so saruco vha avh.
Leijq ovp soq igian, akp vvuxq tsi qigl. Wex, sae loi o qekj em gwu komkatd xavsakbuejj vjaf fui kepcx xaafgy ryi uyq, ebn xqi falsixkievt yena jijeh goih jayieznud ih qzoxquq tazoza:
Mdoow, rag swit et diyf xula erhowyunabu!
Jads ejss himfojm kkamu zoatbu ig uxvexaizig jilg, dyo Kutpox gudcev cit jobuzo o mut eihein ri fiaj of, iy javdeot xpu rpzzag zilh, hruwu ube wodaamp iz cdes jji ibr oy neijp el onz yowal xawu.
Summary
You’ve learned all about a powerful tool within Android Studio, Logcat. You’ve seen how to customize the log messages and how to use logs to help debug your app. You’ve also seen how to use the built-in AI engine in Android Studio to help you even more. Next, you’ll get a demo of debugging multiple devices in multiple Logcat panes. Get your whiskers ready! 😺
See forum comments
This content was released on Sep 10 2024. The official support period is 6-months
from this date.
Explore the AndroidManifest.xml file, various parts, and tag types.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Debugging with Android Studio's Logcat 🐛😼
Next: Demo
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.