Skip to content

Commit

Permalink
Change lib name and add pip
Browse files Browse the repository at this point in the history
- Change lib name from Pylog to easylogging because Pylog already taken.
- Add lib to pip so you can install lib from pip
  • Loading branch information
AI35 authored Aug 19, 2018
1 parent 8dba9dc commit 9f16320
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 23 deletions.
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
# Pylog
# easylogging
###### Simple and Easy Logger lib for python

[![Pylog](https://img.shields.io/badge/build-passing-brightgreen.svg)]()
[![easylogging](https://img.shields.io/badge/build-passing-brightgreen.svg)]()
[![version](https://img.shields.io/badge/version-1.2.0-green.svg)]()
[![status](https://img.shields.io/badge/status-stable-brightgreen.svg)]()
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/677f082650b54782b947b429dd1c35ce)](https://www.codacy.com/project/alosh.othman55/Pylog/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AI35/Pylog&utm_campaign=Badge_Grade_Dashboard)
[![python](https://img.shields.io/badge/python-3-blue.svg)](http://www.python.org/download/)
[![windows](https://img.shields.io/badge/windows-tested-brightgreen.svg)]()
[![linux](https://img.shields.io/badge/linux-tested-brightgreen.svg)]()
[![license](https://img.shields.io/badge/license-GNU-blue.svg)](https://github.com/AI35/Python-Service/blob/master/LICENSE)
[![license](https://img.shields.io/badge/license-GNU-blue.svg)](https://github.com/AI35/easylogging/blob/master/LICENSE)

## REQUIREMENTS
- Python-3 --> http://www.python.org/download/

## Notes
- Now This lib is **Stable**.
- I am created this lib because i want use easy logging lib.
- ~~**Important(To Work --logfile)** : You need to put Pylog.py in same folder with your main file.~~
- ~~**Known Bug** : You need to place pylog.py next to the file that uses this lib.~~
- ~~**Important(To Work --logfile)** : You need to put easylogging.py in same folder with your main file.~~
- ~~**Known Bug** : You need to place easylogging.py next to the file that uses this lib.~~

## Installation

- Clone this repo:

```
$ git clone https://github.com/AI35/Pylog
$ git clone https://github.com/AI35/easylogging
```
- Using pip:

```
$ pip install easylogging
```

## Usage
- First you need import lib for your file and Set name :
```
import Pylog
import easylogging
Pylog.logname(__file__)
easylogging.logname(__file__)
```
- Use the functions you need:
- Pylog.critical(msg)
- Pylog.error(msg, exc_info) **default: exc_info=False**
- Pylog.warning(msg) **or** Pylog.warn(msg)
- Pylog.info(msg)
- Pylog.debug(msg)
- easylogging.critical(msg)
- easylogging.error(msg, exc_info) **default: exc_info=False**
- easylogging.warning(msg) **or** easylogging.warn(msg)
- easylogging.info(msg)
- easylogging.debug(msg)
- You can start logging from Cmd or PowerShell :
```
$ Python yourfile.py --logging --logfile
Expand All @@ -61,9 +66,9 @@
file_level=0
```
- **in Version 1.1.0** : Now you can show and hide error info from **logging.conf** :
###### - Show Error info (Pylog.error(msg, exc_info))
###### - Show Error info (easylogging.error(msg, exc_info))
###### - True or False or None
###### - * (None) means that exc_info takes the value entered from the user, example: Pylog.error(msg, exc_info=True)
###### - * (None) means that exc_info takes the value entered from the user, example: easylogging.error(msg, exc_info=True)
```
exc_info=None
```
Expand All @@ -73,11 +78,11 @@
- **in Version 1.1.3** : Fix input msg:
###### - You can know input (int or any value) , example:
```
Pylog.error(msg) ; msg = 10
easylogging.error(msg) ; msg = 10
```
- **in Version 1.2.0** : Important Fixes:
###### - You don't need to place pylog.py next to the file that uses this lib.
###### - file level in logging.conf work on --logfile **without use --logging** (if use --logging file write all level)
###### - You **don't** need to place easylog.py next to the file that uses this lib.
###### - File level in logging.conf work on --logfile **without use --logging** (if use --logging file write all level)
###### - V 1.2.0 is stable version and ready to use.
- Level table :

Expand All @@ -96,14 +101,14 @@

## LICENSE
```
Copyright 2018 LinePY - AI35, Inc.
Copyright 2018 LinePY - ALI B OTHMAN(AI35), Inc.
Pylog
easylogging
Licensed under the GNU License , you may not use this
file except in compliance with the License.
You may obtain a copy of the License at :
https://github.com/AI35/Pylog/blob/master/LICENSE
https://github.com/AI35/easylog/blob/master/LICENSE
```
###### ALI .B .OTH - ORG : LinePY
###### ALI .B .OTH - ORG : LinePY
108 changes: 108 additions & 0 deletions easylogging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Created By : Ali B Othman
# V 1.2.0
# Simple log lib for python

import logging
from time import gmtime, strftime
import sys, os
import logging.config
from configparser import ConfigParser

def logname(dname = __file__):
logname.dname = dname
d = dname.split("\\")
dn = d[:-1]
logname.name = d[-1]
run()

def warning(msg):
run.logger.warning(logname.name+' : '+ str(msg))
def debug(msg):
run.logger.debug(logname.name+' : '+ str(msg))
def info(msg):
run.logger.info(logname.name+' : '+ str(msg))
def critical(msg):
run.logger.critical(logname.name+' : '+ str(msg))
def error(msg, exc_info = False):
if exc == 'True':
run.logger.error(logname.name+' : '+ str(msg), exc_info = True)
elif exc == 'False':
run.logger.error(logname.name+' : '+ str(msg), exc_info = False)
else:
run.logger.error(logname.name+' : '+ str(msg), exc_info = exc_info)



config = ConfigParser()

if not os.path.exists('logging.conf'):
f = open("logging.conf","w+")
f.write('''[logging_option]
;Change number to enable *log level (0, 10, 20, 30, 40, 50)* without --logging or --logfile
;(This option will enable console log without --logging)
level=50
;.......................................
;Change number to set *log level (0, 10, 20, 30, 40, 50)* with --logfile (Level for log file)
;This option work on --logfile without use --logging (if use --logging file write all level)
file_level=0
;.......................................
;Show Error info (easylogging.error(msg, exc_info))
;True or False or None
; * (None) means that exc_info takes the value entered from the user, example: easylogging.error(msg, exc_info=True)
exc_info=None''')
f.close()

config.read('logging.conf')
prop = config.get('logging_option', 'file_level')
prop = int(prop)

level = config.get('logging_option', 'level')
level=int(level)

exc = config.get('logging_option', 'exc_info')
formated = '%(asctime)s - %(levelname)s - %(message)s'

logging.basicConfig(level = logging.DEBUG, format=formated)

def run():
Dir = os.path.join(os.path.dirname(os.path.abspath(logname.dname)), 'logs')
logFile = 'Log %s.log' % (strftime("%Y-%m-%d %Hh-%Mm-%Ss", gmtime()))
Dirfilelog = os.path.join(Dir, logFile)


logger = logging.getLogger(__name__)
run.logger = logger
logging.disable(level)
if level < 50:
logger.propagate = True
else:
logger.propagate = False

try:
if '--logfile' in sys.argv:
if not os.path.exists('logs'):
os.makedirs('logs')
handler = logging.FileHandler(Dirfilelog)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(formated)
handler.setFormatter(formatter)
logger.addHandler(handler)
logging.disable(prop)

except Exception:
pass

try:
if '--logging' in sys.argv:
logging.disable(0)
logger.propagate = True
except Exception:
pass
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Test V 1.2.0
# Simple Test File

from Pylog import *
from easylogging import *

########## very important ############
logname(__file__)
Expand Down

0 comments on commit 9f16320

Please sign in to comment.