> For the complete documentation index, see [llms.txt](https://docs.yemreak.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yemreak.com/arsiv/programming/spawn-ve-tail-ile-loglari-izleme-ve-pretty-etmek.md).

# spawn ve tail ile loglari izleme ve pretty etmek

programming, typescript, spawn ve tail ile loglari izleme ve pretty etmek, loglari izleme, pretty etmek, spawn, pino-pretty, tail

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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
