# spawn ve tail ile loglari izleme ve pretty etmek

Aşağıdaki kod parçacığı, belirli bir dosya yolundaki logları izlemek için bir fonksiyon oluşturur. Bu kod, `spawn` komutunu kullanır.

`spawn` bir child process oluşturur ve bu process, verilen komutu çalıştırır. Bu kodda, `spawn` logları izlemek ve bunları düzgün bir şekilde formatlamak için kullanılıyor. Hata durumunda, hata mesajını konsola yazdırır.

`stdio: "inherit"` seçeneği, child process'in standart giriş, çıkış ve hata akışlarını parent process ile paylaşmasını sağlar. Bu sayede, child process'te oluşan hatalar doğrudan parent process'teki konsola yazdırılır.

`shell: true` seçeneği ise, komutun bir shell içinde çalıştırılmasını sağlar. Bu, komut satırında birden fazla komutun (`tail` ve `pino-pretty` gibi) birleştirilmesini ve boru (`|`) operatörü gibi shell özelliklerinin kullanılmasını sağlar. Bu seçeneğin dikkatlice kullanılması gereklidir, çünkü kullanıcıdan alınan girdilerle oluşturulan komutların shell üzerinde çalıştırılması, potansiyel bir güvenlik riski oluşturabilir.

```javascript
function tailLogs({ filepath, level, region }) {
	const tailCommand = `tail -f ${filepath}`
	const prettyCommand = `node_modules/.bin/pino-pretty -I level,name,time -L ${level}`
	const command = !region
		? `${tailCommand} | ${prettyCommand}`
		: `ssh ${region} '${tailCommand}' | ${prettyCommand}`

	console.log(`Running: ${command}`)
	spawn(command, { stdio: "inherit", shell: true }).on("error", error => {
		console.error(`Error: ${error.message}`)
	})
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/arsiv/programming/spawn-ve-tail-ile-loglari-izleme-ve-pretty-etmek.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
