# Logging levels issue

**URL:** <https://discuss.ray.io/t/logging-levels-issue/1740>\
**Category:** Ray Tune\
**Created:** [April 15, 2021, 9:46am UTC](https://discuss.ray.io/t/logging-levels-issue/1740 "2021-04-15T09:46:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![viotemp1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/viotemp1/32/376_2.png) [@viotemp1](https://discuss.ray.io/u/viotemp1)\
**Post date:** [April 15, 2021, 9:46am UTC](https://discuss.ray.io/t/logging-levels-issue/1740/1 "2021-04-15T09:46:49Z")

</div>

Hello,

Please help me to get logging levels to work after importing ray.  
I need to see INFO and sometimes DEBUG. I set logging level in main, but it does not work after importing ray.  
It is about main module, not tune tasks (childs)  
Example:

logging.debug(“debug log message”)  
logging.info(“info log message”)  
logging.warning(“warning log message”)  
logging.error(“error log message”)  
logging.critical(“critical log message”)

Output:  
WARNING:root:warning log message  
ERROR:root:error log message  
CRITICAL:root:critical log message

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [April 15, 2021, 5:40pm UTC](https://discuss.ray.io/t/logging-levels-issue/1740/2 "2021-04-15T17:40:18Z")

</div>

cc @amogkam Can you address his question?

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [April 23, 2021, 6:15pm UTC](https://discuss.ray.io/t/logging-levels-issue/1740/3 "2021-04-23T18:15:33Z")

</div>

@viotemp1 I think you just need to set the `logging_level` arg in your `ray.init` to the appropriate value you want.

---

<div class="post-metadata">

**Author:** ![viotemp1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/viotemp1/32/376_2.png) [@viotemp1](https://discuss.ray.io/u/viotemp1)\
**Post date:** [April 23, 2021, 7:00pm UTC](https://discuss.ray.io/t/logging-levels-issue/1740/4 "2021-04-23T19:00:47Z")

</div>

Hello,

I always do that.  
ray\_log\_level = logging.INFO  
if not ray.is\_initialized():  
print(“ray init”)  
ray.init(  
log\_to\_driver=True, # False to print TF messages # True False  
configure\_logging=True,  
logging\_level=ray\_log\_level,  
include\_dashboard=False,  
num\_cpus=multiprocessing.cpu\_count(),  
num\_gpus=1,  
# resources={“my\_resource”: 1},  
)

What I wanted to point out is that before running ray.init my info messages are not shown.  
logging.debug(“debug log message”)  
logging.info(“info log message”)  
logging.warning(“warning log message”)  
logging.error(“error log message”)  
logging.critical(“critical log message”)

I’ll prepare a small notebook these days to be more clear.

---

<div class="post-metadata">

**Author:** ![viotemp1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/viotemp1/32/376_2.png) [@viotemp1](https://discuss.ray.io/u/viotemp1)\
**Post date:** [April 24, 2021, 9:56am UTC](https://discuss.ray.io/t/logging-levels-issue/1740/5 "2021-04-24T09:56:39Z")

</div>

Hello,

Checked again today removing one by one the imports and I found out that the issue is not directly from ray, but from hebo.  
Sample notebook: [test\_logging\_levels](https://colab.research.google.com/drive/1MVA9qWQSHPTUve-q4D9wqNy6QA3M0a4v?usp=sharing)  
I’ll check a bit on hebo to see what’s wrong.  
Regards,

---

<div class="post-metadata">

**Author:** ![viotemp1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/viotemp1/32/376_2.png) [@viotemp1](https://discuss.ray.io/u/viotemp1)\
**Post date:** [April 25, 2021, 11:05am UTC](https://discuss.ray.io/t/logging-levels-issue/1740/6 "2021-04-25T11:05:30Z")

</div>

Hello, the issue is indeed from HEBO (gpy\_wgp.py).  
I commented the following lines there and everything is fine now.

#import logging  
#logging.disable(logging.WARNING)  
#import warnings  
#warnings.filterwarnings(‘ignore’, category = RuntimeWarning)

Regards,

---

<div class="post-metadata">

**Author:** ![vakker00](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vakker00](https://discuss.ray.io/u/vakker00)\
**Post date:** [July 27, 2021, 9:11pm UTC](https://discuss.ray.io/t/logging-levels-issue/1740/7 "2021-07-27T21:11:00Z")

</div>

@amogkam I seem to have a similar issue. If I add a logger the same way how it’s done in the Ray repo, then setting the level doesn’t seem to work:

```python
# main script
import logging

import ray
from ray import tune

from test_env import SimpleCorridor

if __name__ == " __main__":
    # ray.init(logging_level=logging.DEBUG)
    ray.init(logging_level=logging.INFO)

    config = {
        "env": SimpleCorridor,
        "evaluation_interval": 1,
        "env_config": {
            "corridor_length": 5,
        },
        "evaluation_num_episodes": 10,
        "num_gpus": 0.5,
        "lr": tune.grid_search([1e-4, 1e-4]),
        "num_workers": 2,
        "num_envs_per_worker": 1,
        "framework": "torch",
    }

    stop = {"training_iteration": 10}

    results = tune.run('APPO', config=config, stop=stop, verbose=1)

```

```python
# test_env.py
import logging

import gym
import numpy as np
from gym.spaces import Box, Discrete

logger = logging.getLogger( __name__ )

class SimpleCorridor(gym.Env):
    def __init__ (self, config):
        logger.debug("debug log message")
        logger.info("info log message")
        logger.warning("warning log message")
        logger.error("error log message")
        logger.critical("critical log message")
        self.end_pos = config["corridor_length"]
        self.cur_pos = 0
        self.action_space = Discrete(2)
        self.observation_space = Box(
            0.0, self.end_pos, shape=(1, ), dtype=np.float32)

    def reset(self):
        self.cur_pos = 0
        return [self.cur_pos]

    def step(self, action):
        assert action in [0, 1], action
        if action == 0 and self.cur_pos > 0:
            self.cur_pos -= 1
        elif action == 1:
            self.cur_pos += 1
        done = self.cur_pos >= self.end_pos
        return [self.cur_pos], 1.0 if done else -0.1, done, {}

```

Output:

```auto
....
(pid=510610) warning log message                                                                                                                                                                                   
(pid=510610) error log message    
(pid=510610) critical log message                                                                                                                                                                                  
(pid=510606) warning log message                                                                         
(pid=510606) error log message                                                                                                                                                                                     
(pid=510606) critical log message
(pid=510603) warning log message                                                                                                                                                                                   
(pid=510603) error log message                                                                           
(pid=510603) critical log message                                                                                                                                                                                  
(pid=510612) warning log message                                                                         
(pid=510612) error log message                                                                                                                                                                                     
(pid=510612) critical log message         
....

```

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [July 27, 2021, 9:35pm UTC](https://discuss.ray.io/t/logging-levels-issue/1740/8 "2021-07-27T21:35:25Z")

</div>

Yeah this definitely looks like a bug @vakker00. I made an issue here [[Core] Logging INFO Messages are not showing · Issue #17374 · ray-project/ray · GitHub](https://github.com/ray-project/ray/issues/17374), and we’ll look into this.
