> For the complete documentation index, see [llms.txt](https://ir0nstone.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ir0nstone.gitbook.io/notes/misc/pwntools/logging_and_context.md).

# Logging and Context

## Logging

Logging is a very useful feature of pwntools that lets you know where in your code you've gotten up to, and you can log in different ways for different types of data.

### log.info(text)

```
>>> log.info('Binary Base is at 0x400000')
[*] Binary Base is at 0x400000
```

### log.success(text)

```
>>> log.success('ASLR bypassed! Libc base is at 0xf7653000')
[+] ASLR bypassed! Libc base is at 0xf7653000
```

### log.error(text)

```
>>> log.success('The payload is too long')
[-] The payload is too long
```

## Context

`context` is a 'global' variable in pwntools that allows you to set certain values once and all future functions automatically use that data.

```python
context.arch = 'i386'
context.os = 'linux'
context.endian = 'little'
context.bits = 64
```

Now every time you generate shellcode or use the `p64()` and `u64()` functions it will be specifically designed to use the `context` variables, meaning it will *just work*. The power of pwntools.\ <br>

If you think that's a lot of setup, make it even simpler.

```python
context.binary = './vulnerable_binary'
```

This enables you to do a lot more things as well - for example, if you run

```python
p = process()
```

it will automatically use the `context` binary and you will not have to specify it again.


---

# 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://ir0nstone.gitbook.io/notes/misc/pwntools/logging_and_context.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.
