~ubuntu-branches/ubuntu/trusty/gnome-do/trusty

« back to all changes in this revision

Viewing changes to Do.Platform/src/Do.Platform/LogBase.cs

  • Committer: Package Import Robot
  • Author(s): Christopher James Halse Rogers
  • Date: 2012-03-26 11:12:21 UTC
  • mfrom: (0.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120326111221-1jk143fy37zxi3e4
Tags: 0.9-1
* New upstream version no longer uses deprecated internal glib headers.
  (Closes: #665537)
* [59fa37b9] Fix watch file
* [63486516] Imported Upstream version 0.9
* [8c636d84] Disable testsuite for now; requires running dbus and gconf daemons
* [e46de4b9] Remove inaccurate README.Source
* [4591d677] Add git-buildpackage configuration to default to pristine-tar

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
using System;
21
21
using System.Linq;
 
22
using System.Threading;
22
23
using System.Collections.Generic;
23
24
 
24
25
using Do.Universe;
47
48
                        }
48
49
                }
49
50
 
 
51
                static object write_lock = new object ();
 
52
                static bool writing = false;
50
53
                public static LogLevel DisplayLevel { get; set; }
51
54
 
52
 
                static bool Writing { get; set; }
53
 
                static ICollection<LogCall> PendingLogCalls { get; set; }
54
 
 
55
 
                static LogBase ()
56
 
                {
57
 
                        Writing = false;
58
 
                        PendingLogCalls = new LinkedList<LogCall> ();
59
 
                }
60
 
 
61
55
                public static void Write (LogLevel level, string msg, params object[] args)
62
56
                {
63
 
                        if (level < DisplayLevel) return;
64
 
                        
65
 
                        msg = string.Format (msg, args);
66
 
                        if (Writing) {
67
 
                                // In the process of logging, another log call has been made.
68
 
                                // We need to avoid the infinite regress this may cause.
69
 
                                PendingLogCalls.Add (new LogCall (level, msg));
70
 
                        } else {
71
 
                                Writing = true;
72
 
 
73
 
                                if (PendingLogCalls.Any ()) {
74
 
                                        // Flush delayed log calls.
75
 
                                        // First, swap PendingLogCalls with an empty collection so it
76
 
                                        // is not modified while we enumerate.
77
 
                                        IEnumerable<LogCall> calls = PendingLogCalls;
78
 
                                        PendingLogCalls = new LinkedList<LogCall> ();
79
 
        
80
 
                                        // Log all pending calls.
81
 
                                        foreach (LogCall call in calls)
82
 
                                                foreach (ILogService log in Services.Logs)
83
 
                                                        log.Log (call.Level, call.Message);
84
 
                                }
85
 
 
86
 
                                // Log message.
87
 
                                foreach (ILogService log in Services.Logs)
88
 
                    log.Log (level, msg);
89
 
                                
90
 
                                Writing = false;
 
57
                        if (level < DisplayLevel)
 
58
                                return;
 
59
 
 
60
                        lock (write_lock) {
 
61
                                msg = string.Format (msg, args);
 
62
 
 
63
                                if (writing) {
 
64
                                        throw new InvalidOperationException (String.Format ("Logger implementation attempted to call Log from its own Log method.\n" +
 
65
                                                "Message was:\n" +
 
66
                                                "***************************\n" +
 
67
                                                "{0}\n" +
 
68
                                                "***************************", msg));
 
69
                                }
 
70
                                writing = true;
 
71
 
 
72
                                try {
 
73
                                        // Log message.
 
74
                                        foreach (ILogService log in Services.Logs)
 
75
                                                log.Log (level, msg);
 
76
                                } finally {
 
77
                                        writing = false;
 
78
                                }
91
79
                        }
92
80
                }
93
81
        }