Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a logging library #202

Closed
pnorman opened this issue Oct 25, 2014 · 8 comments · Fixed by #1326
Closed

Use a logging library #202

pnorman opened this issue Oct 25, 2014 · 8 comments · Fixed by #1326

Comments

@pnorman
Copy link
Collaborator

pnorman commented Oct 25, 2014

Currently everything prints out with fprintf. This makes it hard to change the verbosity.

Any thoughts?

@zerebubuth, do you think MapQuest/logging would be suited here?

@alex85k
Copy link
Contributor

alex85k commented Oct 25, 2014

There is always Boost logging somewhere near but it seems to be huge and slow to build. Something smaller would be preferrable (non-professional opinion).

@pnorman
Copy link
Collaborator Author

pnorman commented Feb 27, 2015

boost::log was only introduced in 1.54. This is a big minus.

@zerebubuth, I can't remember the options we came up with at the hack weekend.

@zerebubuth
Copy link
Contributor

There's google's logging library too. I've never used it, though, so I
can't say whether it's any good.

The MQ logging library is probably no good for now, as it currently depends
on mapnik and that's too big of a dep to pull in (imho).
On 27 Feb 2015 20:12, "Paul Norman" notifications@github.com wrote:

boost::log was only introduced in 1.54. This is a big minus.

@zerebubuth https://github.com/zerebubuth, I can't remember the options
we came up with at the hack weekend.


Reply to this email directly or view it on GitHub
#202 (comment)
.

@pnorman
Copy link
Collaborator Author

pnorman commented Feb 27, 2015

I forgot our library depends on Mapnik. I agree, that rules it out.

log4cxx is another library mentioned, patterned after log4j. log4cxx is packaged on Ubuntu 12.04, 14.04 and FreeBSD

google-glog is Google's. It is packaged on Ubuntu 14.04 and FreeBSD, but not Ubuntu 12.04.

@alex85k
Copy link
Contributor

alex85k commented Oct 30, 2015

Maybe use something lighweight and header-only like https://github.com/gabime/spdlog , if you are going to use cppformat anyway #398
It would be great to replace boost completely, to my opinion. It is the biggest dependency, after all but used only in few places.

@alex85k
Copy link
Contributor

alex85k commented Oct 30, 2015

Another way is to use boost whenever possible, like https://github.com/alacarte-maps/alacarte (just switched from log4cpp to boost log) and https://github.com/Project-OSRM/osrm-backend (including logging, formatting, testing if needed). Performance and compilation time may suffer a little :)

@pnorman
Copy link
Collaborator Author

pnorman commented Nov 15, 2016

osmium::util::VerboseOutput might be of use here

@pnorman
Copy link
Collaborator Author

pnorman commented Mar 15, 2017

Per previous discussion, we need support for three levels of output - details (off by default), standard, and errors.

We might also have additional debugging output with some compile-time flags (e.g. all COPY lines to postgres)

joto added a commit to joto/osm2pgsql that referenced this issue Nov 17, 2020
This improves the logging output in several ways:

* New logging functions log_debug/info/warn/error(). Almost all
  output now uses one of these functions.
* Log messages start with timestamp.
* Log messages of level warn/error are printed in red when
  logging to console.
* New command line option: --log-level to set log level. Default
  is "info". The option -v, --verbose does the same as
  --log-level=debug.
* New option --log-progress=true/false/auto. The default is `auto`
  which enables progress logging on the console and disables it
  when stderr has been redirected to a file.
* Extra functions to log SQL commands/SQL COPY data. These can
  be activated by command line options --log-sql and --log-sql-data,
  respectively, instead of the compile time setting. Output is
  printed in blue when logging to console.

Most log messages are in level "info" at the moment, so they are shown
as before with the default settings. Many of these probably don't need
to be shown in normal operation and can be downgraded to "debug". I'll
leave this for a later commit.

There are several places in the code where the output is updated on the
screen while some longer process is running:

* The code displaying regular updates of a counter in the expire code
  has been removed. Writing out the expire data doesn't take that long,
  so it isn't important to have this. Instead a log message is now
  generated.
* The output of the objects being processed and the pending ways and
  relations output is now en/disabled by the `--log-progress` option.
  Otherwise it has not been touched. I'll leave cleaning that up
  for a later time.

Some error reporting code has also been changed. Usually errors should
be reported by throwing an exception that is then caught in the main()
function and written out. The exception should contain the whole
error message, sometimes additional logging lines are created before
throwing the error. There is probably some more cleanup needed here.

This introduces a new global object "the_logger". Otherwise we'd have to
add the logger as parameter to a lot of functions!

Fixes osm2pgsql-dev#202
Fixes osm2pgsql-dev#1246
Fixes osm2pgsql-dev#591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants