Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
olapy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
olapy
Commits
7186416d
Commit
7186416d
authored
May 03, 2017
by
mouadh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix logs
parent
91f0169d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
81 deletions
+11
-81
olapy/core/services/logger.py
olapy/core/services/logger.py
+0
-69
olapy/core/services/xmla.py
olapy/core/services/xmla.py
+3
-3
olapy/web/logger.py
olapy/web/logger.py
+8
-9
No files found.
olapy/core/services/logger.py
deleted
100644 → 0
View file @
91f0169d
from
__future__
import
absolute_import
,
division
,
print_function
import
logging
import
os
from
logging.handlers
import
RotatingFileHandler
class
Logs
:
"""
write server logs, it can be:
- mdx queries
- DataFrame results
- xmla requests and responses
:file_name: file name in which you want to write the logs
"""
def
__init__
(
self
,
file_name
):
self
.
file_name
=
file_name
+
".log"
self
.
root_path
=
self
.
_create_log_file
()
def
_create_log_file
(
self
):
path
=
os
.
path
.
abspath
(
__file__
)
path
=
path
.
lstrip
(
os
.
sep
)
root
=
path
[:
path
.
index
(
os
.
sep
)]
# TODO Fix this prob with c: (
# http://stackoverflow.com/questions/2422798/python-os-path-join-on-windows)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
))
root
=
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
)
return
root
def
write_log
(
self
,
msg
):
"""
Write logs messages to file
:param msg: message to write
"""
# Creation of the logger object that will serve us to write in the logs
logger
=
logging
.
getLogger
()
# We set the logger level to DEBUG, so it writes everything
logger
.
setLevel
(
logging
.
DEBUG
)
# Creation of a formatter that will add time, level
# Of each message when writing a message in the log
formatter
=
logging
.
Formatter
(
'%(asctime)s :: %(levelname)s :: %(message)s'
)
# Creation of a handler which will redirect message of the log to
# file in append mode, with 1 backup and max size of 1MB
file_handler
=
RotatingFileHandler
(
os
.
path
.
join
(
self
.
root_path
,
self
.
file_name
),
'a'
,
1000000
,
1
)
# We put the level on DEBUG, we tell him that he must use the formatter
# Created earlier and add this handler to the logger
file_handler
.
setLevel
(
logging
.
DEBUG
)
file_handler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
file_handler
)
# Creation of a second handler that will redirect each log
# On the console
# Steam_handler = logging.StreamHandler ()
# Steam_handler.setLevel (logging.DEBUG)
# Logger.addHandler (steam_handler)
# It's time to spam your code with logs everywhere:
logger
.
info
(
msg
)
# logger.warning('Testing %s', 'foo')
olapy/core/services/xmla.py
View file @
7186416d
...
...
@@ -236,11 +236,11 @@ def start_server(write_on_file=False):
# TODO FIX it with os
if
write_on_file
:
home_directory
=
expanduser
(
"~"
)
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'logs'
))
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
))
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
os
.
path
.
join
(
home_directory
,
'logs'
,
'xmla.log'
))
filename
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
,
'xmla.log'
))
else
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
getLogger
(
'spyne.protocol.xml'
).
setLevel
(
logging
.
DEBUG
)
...
...
olapy/web/logger.py
View file @
7186416d
...
...
@@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function
import
logging
import
os
from
logging.handlers
import
RotatingFileHandler
from
os.path
import
expanduser
class
Logs
:
...
...
@@ -12,15 +13,13 @@ class Logs:
self
.
root_path
=
self
.
_create_log_file
()
def
_create_log_file
(
self
):
path
=
os
.
path
.
abspath
(
__file__
)
path
=
path
.
lstrip
(
os
.
sep
)
root
=
path
[:
path
.
index
(
os
.
sep
)]
# TODO Fix this prob with c: (
# http://stackoverflow.com/questions/2422798/python-os-path-join-on-windows)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
)):
os
.
makedirs
(
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
))
root
=
os
.
path
.
join
(
root
+
'
\
\
'
,
'logs'
)
return
root
home_directory
=
expanduser
(
"~"
)
location
=
os
.
path
.
join
(
home_directory
,
'olapy-data'
,
'logs'
)
if
not
os
.
path
.
exists
(
location
):
os
.
makedirs
(
location
)
return
location
def
write_log
(
self
,
msg
):
# Creation of the logger object that will serve us to write in the logs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment