Skip to content
Snippets Groups Projects
Commit 376a701f authored by René Fritze's avatar René Fritze Committed by René Milk
Browse files

[py] add a minimal bind of Logging

parent dc7cd408
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,7 @@ public:
* \param logflags any OR'd combination of flags
* \param logfile filename for log, can contain paths, but creation will fail if dir is non-existant
**/
void create(int logflags = (LOG_FILE | LOG_CONSOLE | LOG_ERROR),
void create(int logflags = LogDefault,
const std::string logfile = "dune_xt_common_log",
const std::string datadir = "data",
const std::string _logdir = std::string("log"));
......
......@@ -38,6 +38,8 @@ enum LogFlags
LOG_FILE = 32,
LOG_NEXT = 64
};
static constexpr auto LogMax = LOG_INFO | LOG_ERROR | LOG_DEBUG | LOG_CONSOLE | LOG_FILE;
static constexpr auto LogDefault = LOG_INFO | LOG_ERROR | LOG_CONSOLE;
class CombinedBuffer;
......
......@@ -11,4 +11,5 @@ add_subdirectory(common)
dune_pybindxi_add_module(_common EXCLUDE_FROM_ALL bindings.cc)
dune_pybindxi_add_module(_empty EXCLUDE_FROM_ALL empty.cc)
dune_pybindxi_add_module(_logging EXCLUDE_FROM_ALL logging.cc)
from dune.xt._logging import *
// This file is part of the dune-xt-common project:
// https://github.com/dune-community/dune-xt-common
// Copyright 2009-2018 dune-xt-common developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2016 - 2017)
// Rene Milk (2018)
#include "config.h"
#include <string>
#include <vector>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/stl.h>
#include <python/dune/xt/common/bindings.hh>
#include <dune/pybindxi/pybind11.h>
PYBIND11_MODULE(_logging, m)
{
namespace py = pybind11;
using namespace pybind11::literals;
using namespace Dune::XT::Common;
Dune::XT::Common::bindings::addbind_exceptions(m);
Dune::XT::Common::bindings::add_initialization(m, "dune.xt.logging");
m.def("create",
[](int logflags, const std::string logfile, const std::string datadir, const std::string _logdir) {
Logger().create(logflags, logfile, datadir, _logdir);
},
"logflags"_a = LogDefault,
"logfile"_a = "dune_xt_common_log",
"datadir"_a = "data",
"_logdir"_a = std::string("log"));
m.def("info",
[](std::string msg, std::string end) {
Logger().info() << msg << end;
Logger().info().flush();
},
"msg"_a,
"end"_a = "\n");
m.def("debug",
[](std::string msg, std::string end) {
Logger().debug() << msg << end;
Logger().debug().flush();
},
"msg"_a,
"end"_a = "\n");
m.def("error",
[](std::string msg, std::string end) {
Logger().error() << msg << end;
Logger().error().flush();
},
"msg"_a,
"end"_a = "\n");
m.attr("log_max") = LogMax;
m.attr("log_default") = LogDefault;
}
......@@ -25,4 +25,12 @@ def test_empty():
assert ter.getName() == 'Berti'
assert pet.getName() == 'Bello'
assert ter.bark() == 'woof!'
\ No newline at end of file
assert ter.bark() == 'woof!'
def test_logging():
import dune.xt.common.logging as lg
lg.create(lg.log_max);
lg.info('log info test')
lg.error('log error test')
lg.debug('log debug test')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment