We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Logging does not respect the "%(lineno)s" and "%(filename)s".
### System Info

```Shell
Copy-and-paste the text below in your GitHub issue

- `Accelerate` version: 0.24.1
- Platform: Linux-6.2.0-35-generic-x86_64-with-glibc2.35
- Python version: 3.11.5
- Numpy version: 1.26.1
- PyTorch version (GPU?): 2.1.0+cu121 (True)
- PyTorch XPU available: False
- PyTorch NPU available: False
- System RAM: 125.48 GB
- GPU type: NVIDIA GeForce RTX 3090
- `Accelerate` default config:
        - compute_environment: LOCAL_MACHINE
        - distributed_type: NO
        - mixed_precision: bf16
        - use_cpu: False
        - debug: False
        - num_processes: 1
        - machine_rank: 0
        - num_machines: 1
        - gpu_ids: all
        - rdzv_backend: static
        - same_network: True
        - main_training_function: main
        - downcast_bf16: no
        - tpu_use_cluster: False
        - tpu_use_sudo: False
        - tpu_env: []
```


### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] One of the scripts in the examples/ folder of Accelerate or an officially supported `no_trainer` script in the `examples` folder of the `transformers` repo (such as `run_no_trainer_glue.py`)
- [X] My own task or dataset (give details below)

### Reproduction

When using `accelerate.logging.get_logger` to log, all of the logs says it came from `logging.py` at line 60.

Interestingly, it respects the current module's name correctly.

```python
import logging

from accelerate.logging import get_logger
from rich.logging import RichHandler

logger = get_logger(__name__)

if __name__ == "__main__":
    logging.basicConfig(
        format="%(name)s: %(lineno)s - %(message)s",
        datefmt="%m/%d %H:%M:%S",
        level=logging.INFO,
        handlers=[RichHandler(show_time=True, show_level=True, show_path=True)],
    )
    logger.info("Test")
```

The output looks something like this.

```
11/02 16:45:19 INFO     __main__: 60 - Test                                                logging.py:60
```

### Expected behavior

The line number and filename should respect where the `logger.info()` is called.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/accelerate/logging.py`
Content:
```
1 # Copyright 2022 The HuggingFace Team. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import functools
16 import logging
17 import os
18 
19 from .state import PartialState
20 
21 
22 class MultiProcessAdapter(logging.LoggerAdapter):
23     """
24     An adapter to assist with logging in multiprocess.
25 
26     `log` takes in an additional `main_process_only` kwarg, which dictates whether it should be called on all processes
27     or only the main executed one. Default is `main_process_only=True`.
28 
29     Does not require an `Accelerator` object to be created first.
30     """
31 
32     @staticmethod
33     def _should_log(main_process_only):
34         "Check if log should be performed"
35         state = PartialState()
36         return not main_process_only or (main_process_only and state.is_main_process)
37 
38     def log(self, level, msg, *args, **kwargs):
39         """
40         Delegates logger call after checking if we should log.
41 
42         Accepts a new kwarg of `main_process_only`, which will dictate whether it will be logged across all processes
43         or only the main executed one. Default is `True` if not passed
44 
45         Also accepts "in_order", which if `True` makes the processes log one by one, in order. This is much easier to
46         read, but comes at the cost of sometimes needing to wait for the other processes. Default is `False` to not
47         break with the previous behavior.
48 
49         `in_order` is ignored if `main_process_only` is passed.
50         """
51         if PartialState._shared_state == {}:
52             raise RuntimeError(
53                 "You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility."
54             )
55         main_process_only = kwargs.pop("main_process_only", True)
56         in_order = kwargs.pop("in_order", False)
57 
58         if self.isEnabledFor(level):
59             if self._should_log(main_process_only):
60                 msg, kwargs = self.process(msg, kwargs)
61                 self.logger.log(level, msg, *args, **kwargs)
62 
63             elif in_order:
64                 state = PartialState()
65                 for i in range(state.num_processes):
66                     if i == state.process_index:
67                         msg, kwargs = self.process(msg, kwargs)
68                         self.logger.log(level, msg, *args, **kwargs)
69                     state.wait_for_everyone()
70 
71     @functools.lru_cache(None)
72     def warning_once(self, *args, **kwargs):
73         """
74         This method is identical to `logger.warning()`, but will emit the warning with the same message only once
75 
76         Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the
77         cache. The assumption here is that all warning messages are unique across the code. If they aren't then need to
78         switch to another type of cache that includes the caller frame information in the hashing function.
79         """
80         self.warning(*args, **kwargs)
81 
82 
83 def get_logger(name: str, log_level: str = None):
84     """
85     Returns a `logging.Logger` for `name` that can handle multiprocessing.
86 
87     If a log should be called on all processes, pass `main_process_only=False` If a log should be called on all
88     processes and in order, also pass `in_order=True`
89 
90     Args:
91         name (`str`):
92             The name for the logger, such as `__file__`
93         log_level (`str`, *optional*):
94             The log level to use. If not passed, will default to the `LOG_LEVEL` environment variable, or `INFO` if not
95 
96     Example:
97 
98     ```python
99     >>> from accelerate.logging import get_logger
100     >>> from accelerate import Accelerator
101 
102     >>> logger = get_logger(__name__)
103 
104     >>> accelerator = Accelerator()
105     >>> logger.info("My log", main_process_only=False)
106     >>> logger.debug("My log", main_process_only=True)
107 
108     >>> logger = get_logger(__name__, log_level="DEBUG")
109     >>> logger.info("My log")
110     >>> logger.debug("My second log")
111 
112     >>> array = ["a", "b", "c", "d"]
113     >>> letter_at_rank = array[accelerator.process_index]
114     >>> logger.info(letter_at_rank, in_order=True)
115     ```
116     """
117     if log_level is None:
118         log_level = os.environ.get("ACCELERATE_LOG_LEVEL", None)
119     logger = logging.getLogger(name)
120     if log_level is not None:
121         logger.setLevel(log_level.upper())
122         logger.root.setLevel(log_level.upper())
123     return MultiProcessAdapter(logger, {})
124
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/accelerate/logging.py b/src/accelerate/logging.py
--- a/src/accelerate/logging.py
+++ b/src/accelerate/logging.py
@@ -54,6 +54,8 @@
             )
         main_process_only = kwargs.pop("main_process_only", True)
         in_order = kwargs.pop("in_order", False)
+        # set `stacklevel` to exclude ourself in `Logger.findCaller()` while respecting user's choice
+        kwargs.setdefault("stacklevel", 2)
 
         if self.isEnabledFor(level):
             if self._should_log(main_process_only):

{"golden_diff": "diff --git a/src/accelerate/logging.py b/src/accelerate/logging.py\n--- a/src/accelerate/logging.py\n+++ b/src/accelerate/logging.py\n@@ -54,6 +54,8 @@\n             )\n         main_process_only = kwargs.pop(\"main_process_only\", True)\n         in_order = kwargs.pop(\"in_order\", False)\n+        # set `stacklevel` to exclude ourself in `Logger.findCaller()` while respecting user's choice\n+        kwargs.setdefault(\"stacklevel\", 2)\n \n         if self.isEnabledFor(level):\n             if self._should_log(main_process_only):\n", "issue": "Logging does not respect the \"%(lineno)s\" and \"%(filename)s\".\n### System Info\n\n```Shell\nCopy-and-paste the text below in your GitHub issue\r\n\r\n- `Accelerate` version: 0.24.1\r\n- Platform: Linux-6.2.0-35-generic-x86_64-with-glibc2.35\r\n- Python version: 3.11.5\r\n- Numpy version: 1.26.1\r\n- PyTorch version (GPU?): 2.1.0+cu121 (True)\r\n- PyTorch XPU available: False\r\n- PyTorch NPU available: False\r\n- System RAM: 125.48 GB\r\n- GPU type: NVIDIA GeForce RTX 3090\r\n- `Accelerate` default config:\r\n        - compute_environment: LOCAL_MACHINE\r\n        - distributed_type: NO\r\n        - mixed_precision: bf16\r\n        - use_cpu: False\r\n        - debug: False\r\n        - num_processes: 1\r\n        - machine_rank: 0\r\n        - num_machines: 1\r\n        - gpu_ids: all\r\n        - rdzv_backend: static\r\n        - same_network: True\r\n        - main_training_function: main\r\n        - downcast_bf16: no\r\n        - tpu_use_cluster: False\r\n        - tpu_use_sudo: False\r\n        - tpu_env: []\n```\n\n\n### Information\n\n- [ ] The official example scripts\n- [X] My own modified scripts\n\n### Tasks\n\n- [ ] One of the scripts in the examples/ folder of Accelerate or an officially supported `no_trainer` script in the `examples` folder of the `transformers` repo (such as `run_no_trainer_glue.py`)\n- [X] My own task or dataset (give details below)\n\n### Reproduction\n\nWhen using `accelerate.logging.get_logger` to log, all of the logs says it came from `logging.py` at line 60.\r\n\r\nInterestingly, it respects the current module's name correctly.\r\n\r\n```python\r\nimport logging\r\n\r\nfrom accelerate.logging import get_logger\r\nfrom rich.logging import RichHandler\r\n\r\nlogger = get_logger(__name__)\r\n\r\nif __name__ == \"__main__\":\r\n    logging.basicConfig(\r\n        format=\"%(name)s: %(lineno)s - %(message)s\",\r\n        datefmt=\"%m/%d %H:%M:%S\",\r\n        level=logging.INFO,\r\n        handlers=[RichHandler(show_time=True, show_level=True, show_path=True)],\r\n    )\r\n    logger.info(\"Test\")\r\n```\r\n\r\nThe output looks something like this.\r\n\r\n```\r\n11/02 16:45:19 INFO     __main__: 60 - Test                                                logging.py:60\r\n```\n\n### Expected behavior\n\nThe line number and filename should respect where the `logger.info()` is called.\n", "before_files": [{"content": "# Copyright 2022 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport functools\nimport logging\nimport os\n\nfrom .state import PartialState\n\n\nclass MultiProcessAdapter(logging.LoggerAdapter):\n    \"\"\"\n    An adapter to assist with logging in multiprocess.\n\n    `log` takes in an additional `main_process_only` kwarg, which dictates whether it should be called on all processes\n    or only the main executed one. Default is `main_process_only=True`.\n\n    Does not require an `Accelerator` object to be created first.\n    \"\"\"\n\n    @staticmethod\n    def _should_log(main_process_only):\n        \"Check if log should be performed\"\n        state = PartialState()\n        return not main_process_only or (main_process_only and state.is_main_process)\n\n    def log(self, level, msg, *args, **kwargs):\n        \"\"\"\n        Delegates logger call after checking if we should log.\n\n        Accepts a new kwarg of `main_process_only`, which will dictate whether it will be logged across all processes\n        or only the main executed one. Default is `True` if not passed\n\n        Also accepts \"in_order\", which if `True` makes the processes log one by one, in order. This is much easier to\n        read, but comes at the cost of sometimes needing to wait for the other processes. Default is `False` to not\n        break with the previous behavior.\n\n        `in_order` is ignored if `main_process_only` is passed.\n        \"\"\"\n        if PartialState._shared_state == {}:\n            raise RuntimeError(\n                \"You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility.\"\n            )\n        main_process_only = kwargs.pop(\"main_process_only\", True)\n        in_order = kwargs.pop(\"in_order\", False)\n\n        if self.isEnabledFor(level):\n            if self._should_log(main_process_only):\n                msg, kwargs = self.process(msg, kwargs)\n                self.logger.log(level, msg, *args, **kwargs)\n\n            elif in_order:\n                state = PartialState()\n                for i in range(state.num_processes):\n                    if i == state.process_index:\n                        msg, kwargs = self.process(msg, kwargs)\n                        self.logger.log(level, msg, *args, **kwargs)\n                    state.wait_for_everyone()\n\n    @functools.lru_cache(None)\n    def warning_once(self, *args, **kwargs):\n        \"\"\"\n        This method is identical to `logger.warning()`, but will emit the warning with the same message only once\n\n        Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the\n        cache. The assumption here is that all warning messages are unique across the code. If they aren't then need to\n        switch to another type of cache that includes the caller frame information in the hashing function.\n        \"\"\"\n        self.warning(*args, **kwargs)\n\n\ndef get_logger(name: str, log_level: str = None):\n    \"\"\"\n    Returns a `logging.Logger` for `name` that can handle multiprocessing.\n\n    If a log should be called on all processes, pass `main_process_only=False` If a log should be called on all\n    processes and in order, also pass `in_order=True`\n\n    Args:\n        name (`str`):\n            The name for the logger, such as `__file__`\n        log_level (`str`, *optional*):\n            The log level to use. If not passed, will default to the `LOG_LEVEL` environment variable, or `INFO` if not\n\n    Example:\n\n    ```python\n    >>> from accelerate.logging import get_logger\n    >>> from accelerate import Accelerator\n\n    >>> logger = get_logger(__name__)\n\n    >>> accelerator = Accelerator()\n    >>> logger.info(\"My log\", main_process_only=False)\n    >>> logger.debug(\"My log\", main_process_only=True)\n\n    >>> logger = get_logger(__name__, log_level=\"DEBUG\")\n    >>> logger.info(\"My log\")\n    >>> logger.debug(\"My second log\")\n\n    >>> array = [\"a\", \"b\", \"c\", \"d\"]\n    >>> letter_at_rank = array[accelerator.process_index]\n    >>> logger.info(letter_at_rank, in_order=True)\n    ```\n    \"\"\"\n    if log_level is None:\n        log_level = os.environ.get(\"ACCELERATE_LOG_LEVEL\", None)\n    logger = logging.getLogger(name)\n    if log_level is not None:\n        logger.setLevel(log_level.upper())\n        logger.root.setLevel(log_level.upper())\n    return MultiProcessAdapter(logger, {})\n", "path": "src/accelerate/logging.py"}], "after_files": [{"content": "# Copyright 2022 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport functools\nimport logging\nimport os\n\nfrom .state import PartialState\n\n\nclass MultiProcessAdapter(logging.LoggerAdapter):\n    \"\"\"\n    An adapter to assist with logging in multiprocess.\n\n    `log` takes in an additional `main_process_only` kwarg, which dictates whether it should be called on all processes\n    or only the main executed one. Default is `main_process_only=True`.\n\n    Does not require an `Accelerator` object to be created first.\n    \"\"\"\n\n    @staticmethod\n    def _should_log(main_process_only):\n        \"Check if log should be performed\"\n        state = PartialState()\n        return not main_process_only or (main_process_only and state.is_main_process)\n\n    def log(self, level, msg, *args, **kwargs):\n        \"\"\"\n        Delegates logger call after checking if we should log.\n\n        Accepts a new kwarg of `main_process_only`, which will dictate whether it will be logged across all processes\n        or only the main executed one. Default is `True` if not passed\n\n        Also accepts \"in_order\", which if `True` makes the processes log one by one, in order. This is much easier to\n        read, but comes at the cost of sometimes needing to wait for the other processes. Default is `False` to not\n        break with the previous behavior.\n\n        `in_order` is ignored if `main_process_only` is passed.\n        \"\"\"\n        if PartialState._shared_state == {}:\n            raise RuntimeError(\n                \"You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility.\"\n            )\n        main_process_only = kwargs.pop(\"main_process_only\", True)\n        in_order = kwargs.pop(\"in_order\", False)\n        # set `stacklevel` to exclude ourself in `Logger.findCaller()` while respecting user's choice\n        kwargs.setdefault(\"stacklevel\", 2)\n\n        if self.isEnabledFor(level):\n            if self._should_log(main_process_only):\n                msg, kwargs = self.process(msg, kwargs)\n                self.logger.log(level, msg, *args, **kwargs)\n\n            elif in_order:\n                state = PartialState()\n                for i in range(state.num_processes):\n                    if i == state.process_index:\n                        msg, kwargs = self.process(msg, kwargs)\n                        self.logger.log(level, msg, *args, **kwargs)\n                    state.wait_for_everyone()\n\n    @functools.lru_cache(None)\n    def warning_once(self, *args, **kwargs):\n        \"\"\"\n        This method is identical to `logger.warning()`, but will emit the warning with the same message only once\n\n        Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the\n        cache. The assumption here is that all warning messages are unique across the code. If they aren't then need to\n        switch to another type of cache that includes the caller frame information in the hashing function.\n        \"\"\"\n        self.warning(*args, **kwargs)\n\n\ndef get_logger(name: str, log_level: str = None):\n    \"\"\"\n    Returns a `logging.Logger` for `name` that can handle multiprocessing.\n\n    If a log should be called on all processes, pass `main_process_only=False` If a log should be called on all\n    processes and in order, also pass `in_order=True`\n\n    Args:\n        name (`str`):\n            The name for the logger, such as `__file__`\n        log_level (`str`, *optional*):\n            The log level to use. If not passed, will default to the `LOG_LEVEL` environment variable, or `INFO` if not\n\n    Example:\n\n    ```python\n    >>> from accelerate.logging import get_logger\n    >>> from accelerate import Accelerator\n\n    >>> logger = get_logger(__name__)\n\n    >>> accelerator = Accelerator()\n    >>> logger.info(\"My log\", main_process_only=False)\n    >>> logger.debug(\"My log\", main_process_only=True)\n\n    >>> logger = get_logger(__name__, log_level=\"DEBUG\")\n    >>> logger.info(\"My log\")\n    >>> logger.debug(\"My second log\")\n\n    >>> array = [\"a\", \"b\", \"c\", \"d\"]\n    >>> letter_at_rank = array[accelerator.process_index]\n    >>> logger.info(letter_at_rank, in_order=True)\n    ```\n    \"\"\"\n    if log_level is None:\n        log_level = os.environ.get(\"ACCELERATE_LOG_LEVEL\", None)\n    logger = logging.getLogger(name)\n    if log_level is not None:\n        logger.setLevel(log_level.upper())\n        logger.root.setLevel(log_level.upper())\n    return MultiProcessAdapter(logger, {})\n", "path": "src/accelerate/logging.py"}]}