Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Logger.h@0:9e26d3c8b2b1, 2015-02-12 (annotated)
- Committer:
- nmlaastad
- Date:
- Thu Feb 12 13:49:58 2015 +0000
- Revision:
- 0:9e26d3c8b2b1
Ferdig greier (men stygt p? slutten)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nmlaastad | 0:9e26d3c8b2b1 | 1 | #pragma once |
| nmlaastad | 0:9e26d3c8b2b1 | 2 | |
| nmlaastad | 0:9e26d3c8b2b1 | 3 | #include "mbed.h" |
| nmlaastad | 0:9e26d3c8b2b1 | 4 | #include <string> |
| nmlaastad | 0:9e26d3c8b2b1 | 5 | #include <ctime> |
| nmlaastad | 0:9e26d3c8b2b1 | 6 | |
| nmlaastad | 0:9e26d3c8b2b1 | 7 | LocalFileSystem local("local"); |
| nmlaastad | 0:9e26d3c8b2b1 | 8 | |
| nmlaastad | 0:9e26d3c8b2b1 | 9 | class Logger |
| nmlaastad | 0:9e26d3c8b2b1 | 10 | { |
| nmlaastad | 0:9e26d3c8b2b1 | 11 | public: |
| nmlaastad | 0:9e26d3c8b2b1 | 12 | Logger() |
| nmlaastad | 0:9e26d3c8b2b1 | 13 | { |
| nmlaastad | 0:9e26d3c8b2b1 | 14 | oppstartstid = time(NULL); |
| nmlaastad | 0:9e26d3c8b2b1 | 15 | logFile = fopen("/local/Logg.txt", "a"); |
| nmlaastad | 0:9e26d3c8b2b1 | 16 | if (logFile == NULL) { // vis en error |
| nmlaastad | 0:9e26d3c8b2b1 | 17 | return; |
| nmlaastad | 0:9e26d3c8b2b1 | 18 | } |
| nmlaastad | 0:9e26d3c8b2b1 | 19 | fprintf(logFile, "\nStarting up system\n"); |
| nmlaastad | 0:9e26d3c8b2b1 | 20 | fflush(logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 21 | wait(0.1); |
| nmlaastad | 0:9e26d3c8b2b1 | 22 | fclose(logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 23 | } |
| nmlaastad | 0:9e26d3c8b2b1 | 24 | ~Logger() { |
| nmlaastad | 0:9e26d3c8b2b1 | 25 | if (logFile) |
| nmlaastad | 0:9e26d3c8b2b1 | 26 | fclose(logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 27 | } |
| nmlaastad | 0:9e26d3c8b2b1 | 28 | |
| nmlaastad | 0:9e26d3c8b2b1 | 29 | void Logg(const std::string &melding) |
| nmlaastad | 0:9e26d3c8b2b1 | 30 | { |
| nmlaastad | 0:9e26d3c8b2b1 | 31 | logFile = fopen("/local/Logg.txt", "a"); |
| nmlaastad | 0:9e26d3c8b2b1 | 32 | if (logFile == NULL) { // vis en error |
| nmlaastad | 0:9e26d3c8b2b1 | 33 | return; |
| nmlaastad | 0:9e26d3c8b2b1 | 34 | } |
| nmlaastad | 0:9e26d3c8b2b1 | 35 | int tid = time(NULL) - oppstartstid; |
| nmlaastad | 0:9e26d3c8b2b1 | 36 | fprintf(logFile, "Tid: %d\t\t", tid); |
| nmlaastad | 0:9e26d3c8b2b1 | 37 | fputs(melding.c_str(),logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 38 | fputs("\n", logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 39 | fflush(logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 40 | wait(0.1); |
| nmlaastad | 0:9e26d3c8b2b1 | 41 | fclose(logFile); |
| nmlaastad | 0:9e26d3c8b2b1 | 42 | return; |
| nmlaastad | 0:9e26d3c8b2b1 | 43 | } |
| nmlaastad | 0:9e26d3c8b2b1 | 44 | |
| nmlaastad | 0:9e26d3c8b2b1 | 45 | |
| nmlaastad | 0:9e26d3c8b2b1 | 46 | private: |
| nmlaastad | 0:9e26d3c8b2b1 | 47 | FILE * logFile; |
| nmlaastad | 0:9e26d3c8b2b1 | 48 | time_t oppstartstid; |
| nmlaastad | 0:9e26d3c8b2b1 | 49 | }; |
| nmlaastad | 0:9e26d3c8b2b1 | 50 |