mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
feat(game): setup logger
This commit is contained in:
parent
144cf771f0
commit
c40ec42ff1
1
.gitignore
vendored
1
.gitignore
vendored
@ -158,3 +158,4 @@ cython_debug/
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
debug
|
||||
|
||||
3
main.py
3
main.py
@ -1,8 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
from loguru import logger
|
||||
from py2048.game import Game
|
||||
|
||||
|
||||
@logger.catch
|
||||
def main() -> None:
|
||||
Game().run()
|
||||
|
||||
|
||||
@ -2,14 +2,19 @@ import random
|
||||
import sys
|
||||
|
||||
import pygame
|
||||
from loguru import logger
|
||||
|
||||
from .block import Block
|
||||
from .colors import COLORS
|
||||
from .config import Config
|
||||
from .logger import setup_logger
|
||||
|
||||
|
||||
class Game:
|
||||
def __init__(self) -> None:
|
||||
setup_logger()
|
||||
logger.info("Initializing game")
|
||||
|
||||
pygame.init()
|
||||
self.screen: pygame.Surface = pygame.display.set_mode((Config.WIDTH, Config.HEIGHT))
|
||||
pygame.display.set_caption("2048")
|
||||
|
||||
15
src/py2048/logger.py
Normal file
15
src/py2048/logger.py
Normal file
@ -0,0 +1,15 @@
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
BASE_PATH = Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
|
||||
def setup_logger() -> None:
|
||||
logger.add(
|
||||
BASE_PATH.joinpath(".logs", "game.log"),
|
||||
format="{time} | {level} | {message}",
|
||||
level="DEBUG" if BASE_PATH.joinpath("debug").exists() else "INFO",
|
||||
rotation="1 MB",
|
||||
compression="zip",
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user